ASCO Aerial Autonomy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
base_controller_hardware_connector.h
Go to the documentation of this file.
1 #pragma once
5 #include <glog/logging.h>
6 
11 enum class HardwareType {
12  UAV,
13  Arm,
14  First = UAV, // This should always point to the first in the list
15  Last = Arm // This should always point to the last in the list
16 };
17 
22 public:
29  virtual void run() = 0;
30 
36  virtual ControllerStatus getStatus() const = 0;
37 
42 };
43 
52 template <class SensorDataType, class GoalType, class ControlType>
54 public:
71  HardwareType hardware_type)
73  controller_(controller) {}
74 
78  virtual void run() {
79  // Get latest sensor data
80  // run the controller
81  // send the data back to hardware manager
82  SensorDataType sensor_data;
83  ControlType control;
84  if (!extractSensorData(sensor_data)) {
86  "Cannot extract sensor data");
87  return;
88  }
89  if (!controller_.run(sensor_data, control)) {
90  status_ =
91  ControllerStatus(ControllerStatus::Critical, "Cannot run controller");
92  return;
93  }
94  sendHardwareCommands(control);
95  status_ = controller_.isConverged(sensor_data);
96  }
102  void setGoal(GoalType goal) {
104  controller_.setGoal(goal);
105  }
111  GoalType getGoal() const { return controller_.getGoal(); }
112 
119 
125  ControllerStatus getStatus() const { return status_; }
126 
127 protected:
135  virtual bool extractSensorData(SensorDataType &sensor_data) = 0;
136 
142  virtual void sendHardwareCommands(ControlType controls) = 0;
143 
144 protected:
153 
154 private:
162  Atomic<ControllerStatus> status_;
163 };
Base Controller class.
Definition: base_controller.h:18
void setGoal(GoalType goal)
Set the goal for controller.
Definition: base_controller_hardware_connector.h:102
virtual ControllerStatus getStatus() const =0
Provide the status of the controller.
Only aerial vehicle.
Status of the controller.
Definition: controller_status.h:10
virtual void run()
Extracts sensor data, run controller and send data back to hardware.
Definition: base_controller_hardware_connector.h:78
Base for ControllerHardwareConnector class.
Definition: base_controller_hardware_connector.h:21
HardwareType getHardwareType()
Return the type of hardware (HardwareType) used by the controller.
Definition: base_controller_hardware_connector.h:118
Performs a single step of extracting data, running controller and sending data back to hardware...
Definition: base_controller_hardware_connector.h:53
ControllerStatus getStatus() const
Provide the status of the controller.
Definition: base_controller_hardware_connector.h:125
GoalType getGoal() const
Get the goal for controller.
Definition: base_controller_hardware_connector.h:111
ControllerHardwareConnector(Controller< SensorDataType, GoalType, ControlType > &controller, HardwareType hardware_type)
ControlHardwareConnector runs the controller and sends the commands to hardware.
Definition: base_controller_hardware_connector.h:69
virtual bool extractSensorData(SensorDataType &sensor_data)=0
extract relevant data from hardware/estimators
HardwareType hardware_type_
Type of hardware controlled by the controller.
Definition: base_controller_hardware_connector.h:152
Controller active.
Definition: controller_status.h:16
virtual ~AbstractControllerHardwareConnector()
Destructor to get polymorphism.
Definition: base_controller_hardware_connector.h:41
virtual void run()=0
Abstract run function.
HardwareType
Type of hardware used by ControllerHardwareConnector. Enum ID must be contiguous. ...
Definition: base_controller_hardware_connector.h:11
Controller is critical and unable to continue.
Definition: controller_status.h:18
virtual void sendHardwareCommands(ControlType controls)=0
Send hardware commands for example UAV rpy.