2 #include <argos3/core/utility/rate.h>
3 #include <argos3/core/utility/logging/argos_log.h>
4 #include <argos3/core/control_interface/ci_controller.h>
19 m_pcController(NULL) {
28 const std::string& str_controller_id) {
48 std::string strControllerId, strControllerTag;
52 for(itControllers = itControllers.begin(&tControllers);
53 itControllers != itControllers.end() && strControllerTag ==
"";
56 if(strControllerId == str_controller_id) {
57 strControllerTag = itControllers->Value();
62 if(strControllerTag ==
"") {
68 LOG <<
"[INFO] Robot initialization start" << std::endl;
70 LOG <<
"[INFO] Robot initialization done" << std::endl;
74 LOG <<
"[INFO] Controller type '" << strControllerTag <<
"', id '" << str_controller_id <<
"' initialization start" << std::endl;
75 #ifdef ARGOS_DYNAMIC_LIBRARY_LOADING
81 char pchHostname[256];
82 pchHostname[255] =
'\0';
83 ::gethostname(pchHostname, 255);
85 LOG <<
"[INFO] Controller id set to '" << pchHostname <<
"'" << std::endl;
89 for(itAct = itAct.begin(&tActuators);
97 pcCIAct->
Init(*itAct);
103 for(itSens = itSens.begin(&tSensors);
104 itSens != itSens.end();
108 if(pcCISens == NULL) {
111 pcCISens->
Init(*itSens);
116 LOG <<
"[INFO] Controller type '" << strControllerTag <<
"', id '" << str_controller_id <<
"' initialization done" << std::endl;
141 LOG <<
"[INFO] Control loop running" << std::endl;
143 ::timeval tPast, tNow, tDiff;
145 ::gettimeofday(&tPast, NULL);
148 ::gettimeofday(&tNow, NULL);
149 timersub(&tNow, &tPast, &tDiff);
150 fElapsed =
static_cast<Real>(tDiff.tv_sec * 1000000 + tDiff.tv_usec) / 1e6;
165 LOG <<
"[INFO] Stopping controller" << std::endl;
170 LOG <<
"[INFO] All done" << std::endl;
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.
float Real
Collects all ARGoS code.
The namespace containing all the ARGoS related code.
ticpp::Iterator< ticpp::Element > TConfigurationNodeIterator
The iterator for the ARGoS configuration XML node.
TConfigurationNode & GetNode(TConfigurationNode &t_node, const std::string &str_tag)
Given a tree root node, returns the first of its child nodes with the wanted name.
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
CARGoSLog LOG(std::cout, SLogColor(ARGOS_LOG_ATTRIBUTE_BRIGHT, ARGOS_LOG_COLOR_GREEN))
void GetNodeAttribute(TConfigurationNode &t_node, const std::string &str_attribute, T &t_buffer)
Returns the value of a node's attribute.
The basic interface for all actuators.
virtual void Init(TConfigurationNode &t_node)
Initializes the actuator from the XML configuration tree.
virtual void Init(TConfigurationNode &t_node)
Initializes the controller.
void AddSensor(const std::string &str_sensor_type, CCI_Sensor *pc_sensor)
Adds an sensor to this controller.
virtual void ControlStep()
Executes a control step.
void SetId(const std::string &str_id)
Sets the id of the robot associated to this controller.
void AddActuator(const std::string &str_actuator_type, CCI_Actuator *pc_actuator)
Adds an actuator to this controller.
The basic interface for all sensors.
virtual void Init(TConfigurationNode &t_node)
Initializes the sensor from the XML configuration tree.
virtual void Init(const std::string &str_conf_fname, const std::string &str_controller_id)
Initializes the robot and the controller.
virtual void Control()
Execute the robot controller.
virtual ~CRealRobot()
Class destructor.
virtual void Destroy()=0
Put your robot cleanup code here.
CCI_Controller * m_pcController
ticpp::Document m_tConfiguration
TConfigurationNode * m_ptControllerConfRoot
virtual void Act(Real f_elapsed_time)=0
Send data to the actuators.
CRealRobot()
Class constructor.
TConfigurationNode m_tConfRoot
virtual void Execute()
Performs the main loop.
virtual CCI_Actuator * MakeActuator(const std::string &str_name)=0
Creates an actuator given its name.
virtual void Sense(Real f_elapsed_time)=0
Collect data from the sensors.
static void Cleanup(int)
Cleanup function called when the controller is stopped.
virtual CCI_Sensor * MakeSensor(const std::string &str_name)=0
Creates a sensor given its name.
virtual void InitRobot()=0
Put your robot initialization code here.
static CRealRobot * m_pcInstance
static TYPE * New(const std::string &str_label)
Creates a new object of type TYPE
void Sleep()
Sleeps for the appropriate time to complete the period.