9 #include <boost/thread/mutex.hpp>
29 std::map<HardwareType, AbstractControllerHardwareConnector *>
35 std::map<HardwareType, std::unique_ptr<boost::mutex>> thread_mutexes_;
44 active_controllers_[hardware_type] =
nullptr;
45 thread_mutexes_[hardware_type] =
46 std::unique_ptr<boost::mutex>(
new boost::mutex);
58 template <
class ControllerHardwareConnectorT,
class GoalT>
60 ControllerHardwareConnectorT *controller_hardware_connector =
62 .
getObject<ControllerHardwareConnectorT>();
63 controller_hardware_connector->setGoal(goal);
65 controller_hardware_connector->getHardwareType();
66 if (active_controllers_[hardware_type] != controller_hardware_connector) {
67 boost::mutex::scoped_lock lock(*thread_mutexes_[hardware_type]);
68 active_controllers_[hardware_type] = controller_hardware_connector;
79 template <
class ControllerHardwareConnectorT,
class GoalT>
81 const ControllerHardwareConnectorT *controller_hardware_connector =
83 .
getObject<ControllerHardwareConnectorT>();
84 return controller_hardware_connector->getGoal();
94 template <
class ControllerHardwareConnectorT>
96 const ControllerHardwareConnectorT *controller_hardware_connector =
98 .
getObject<ControllerHardwareConnectorT>();
99 return controller_hardware_connector->getStatus();
111 auto active_controller = active_controllers_.find(hardware_type);
112 if (active_controller != active_controllers_.end() &&
113 active_controller->second !=
nullptr) {
114 return active_controller->second->getStatus();
127 boost::mutex::scoped_lock lock(*thread_mutexes_[hardware_type]);
128 active_controllers_[hardware_type] =
nullptr;
139 active_controllers_[hardware_type];
140 if (active_controller !=
nullptr) {
141 boost::mutex::scoped_lock lock(*thread_mutexes_[hardware_type]);
142 active_controller->
run();
virtual std::string getSystemStatus() const =0
Provide the current state of robot system.
TypeMap< AbstractControllerHardwareConnector > controller_hardware_connector_container_
Container to store and retrieve controller-hardware-connectors.
Definition: base_robot_system.h:23
void runActiveController(HardwareType hardware_type)
Run active controller stored for a given hardware type.
Definition: base_robot_system.h:136
GoalT getGoal() const
Get the goal from connector.
Definition: base_robot_system.h:80
void abortController(HardwareType hardware_type)
Remove active controller for given hardware type.
Definition: base_robot_system.h:126
Status of the controller.
Definition: controller_status.h:10
Iterable wrapper class for iterating over enums. Only works for enums that are contiguous.
Definition: iterable_enum.h:8
ObjectT * getObject()
return the object stored
Definition: type_map.h:37
void setGoal(GoalT goal)
sets goal to the connector and swaps the active connector with the specified connector type...
Definition: base_robot_system.h:59
Base for ControllerHardwareConnector class.
Definition: base_controller_hardware_connector.h:21
Provides functions to switch between active controllers and get goals.
Definition: base_robot_system.h:16
This status is used when no controller is engaged.
Definition: controller_status.h:19
ControllerStatus getStatus() const
Get the status of a controller.
Definition: base_robot_system.h:95
BaseRobotSystem()
Constructor to initialize active controllers and mutexes to NULL.
Definition: base_robot_system.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
ControllerStatus getActiveControllerStatus(HardwareType hardware_type) const
Get the status of the active controller.
Definition: base_robot_system.h:110