7 #ifndef CCI_CONTROLLER_H
8 #define CCI_CONTROLLER_H
14 #include <argos3/core/utility/configuration/base_configurable_resource.h>
15 #include <argos3/core/utility/datatypes/datatypes.h>
16 #include <argos3/core/control_interface/ci_sensor.h>
17 #include <argos3/core/control_interface/ci_actuator.h>
18 #include <argos3/core/utility/plugins/factory.h>
78 inline const std::string&
GetId()
const {
88 inline void SetId(
const std::string& str_id) {
105 template<
typename ACTUATOR_IMPL>
106 ACTUATOR_IMPL*
GetActuator(
const std::string& str_actuator_type) {
107 CCI_Actuator::TMap::const_iterator it =
m_mapActuators.find(str_actuator_type);
109 ACTUATOR_IMPL* pcActuator =
dynamic_cast<ACTUATOR_IMPL*
>(it->second);
110 if(pcActuator != NULL) {
114 char* pchDemangledType = abi::__cxa_demangle(
typeid(ACTUATOR_IMPL).name(), NULL, NULL, NULL);
115 THROW_ARGOSEXCEPTION(
"Actuator type " << str_actuator_type <<
" cannot be cast to type " << pchDemangledType);
119 THROW_ARGOSEXCEPTION(
"Unknown actuator type " << str_actuator_type <<
" requested in controller. Did you add it to the XML file?");
136 template<
typename SENSOR_IMPL>
137 SENSOR_IMPL*
GetSensor(
const std::string& str_sensor_type) {
138 CCI_Sensor::TMap::const_iterator it =
m_mapSensors.find(str_sensor_type);
140 SENSOR_IMPL* pcSensor =
dynamic_cast<SENSOR_IMPL*
>(it->second);
141 if(pcSensor != NULL) {
145 char* pchDemangledType = abi::__cxa_demangle(
typeid(SENSOR_IMPL).name(), NULL, NULL, NULL);
146 THROW_ARGOSEXCEPTION(
"Sensor type " << str_sensor_type <<
" cannot be cast to type " << pchDemangledType);
150 THROW_ARGOSEXCEPTION(
"Unknown sensor type " << str_sensor_type <<
" requested in controller. Did you add it to the XML file?");
160 bool HasActuator(
const std::string& str_actuator_type)
const;
168 bool HasSensor(
const std::string& str_sensor_type)
const;
205 inline void AddSensor(
const std::string& str_sensor_type,
230 #ifdef ARGOS_DYNAMIC_LIBRARY_LOADING
232 #define REGISTER_CONTROLLER(CLASSNAME, LABEL) \
233 REGISTER_SYMBOL(CCI_Controller, \
248 #define REGISTER_CONTROLLER(CLASSNAME, LABEL) \
250 argos::CCI_Controller* ControllerMaker(const std::string& str_label) { \
251 if(str_label != LABEL) { \
252 THROW_ARGOSEXCEPTION("Controller label \"" << \
254 "\" does not match the registered one: \"" << \
257 return new CLASSNAME; \
argos::CCI_Controller * ControllerMaker(const std::string &str_label)
Registers a new controller inside ARGoS.
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
The namespace containing all the ARGoS related code.
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
The basic interface for all actuators.
std::map< std::string, CCI_Actuator *, std::less< std::string > > TMap
The basic interface for a robot controller.
virtual void Init(TConfigurationNode &t_node)
Initializes the controller.
CCI_Sensor::TMap & GetAllSensors()
Returns a map of the associated sensors.
void AddSensor(const std::string &str_sensor_type, CCI_Sensor *pc_sensor)
Adds an sensor to this controller.
bool HasSensor(const std::string &str_sensor_type) const
Returns true if an sensor with the passed type is associated to this controller.
CCI_Actuator::TMap & GetAllActuators()
Returns a map of the associated actuators.
ACTUATOR_IMPL * GetActuator(const std::string &str_actuator_type)
Returns a pointer to the an actuator, given its type.
virtual void ControlStep()
Executes a control step.
void SetId(const std::string &str_id)
Sets the id of the robot associated to this controller.
virtual void Destroy()
The default implementation of this method does nothing.
void AddActuator(const std::string &str_actuator_type, CCI_Actuator *pc_actuator)
Adds an actuator to this controller.
virtual void Reset()
Resets the state of the controller to what it was right after Init() was executed.
SENSOR_IMPL * GetSensor(const std::string &str_sensor_type)
Returns a pointer to the an sensor, given its type.
CCI_Sensor::TMap m_mapSensors
A map containing all the sensors associated to this controller.
virtual ~CCI_Controller()
Class destructor.
const std::string & GetId() const
Returns the id of the robot associated to this controller.
bool HasActuator(const std::string &str_actuator_type) const
Returns true if an actuator with the passed type is associated to this controller.
CCI_Actuator::TMap m_mapActuators
A map containing all the actuators associated to this controller.
std::string m_strId
The id of the robot associated to this controller
The basic interface for all sensors.
std::map< std::string, CCI_Sensor *, std::less< std::string > > TMap
This class is the base of all XML-configurable ARGoS interface.