radios_default_sensor.cpp
Go to the documentation of this file.
1 
8 #include <argos3/plugins/simulator/entities/radio_equipped_entity.h>
9 
10 namespace argos {
11 
12  /****************************************/
13  /****************************************/
14 
16  m_pcRadioEquippedEntity(nullptr),
17  m_pcControllableEntity(nullptr),
18  m_bShowRays(false) {}
19 
20  /****************************************/
21  /****************************************/
22 
24  try {
25  /* Get the radio equipped entity */
27  /* Resize the interface vector for each radio in the radio equipped entity */
29  /* For each radio, create an interface */
30  for(CRadioEquippedEntity::SInstance& s_instance :
32  /* Clear the existing data */
33  m_vecInterfaces.emplace_back(s_instance.Radio.GetId());
34  }
35  /* Get controllable entity */
36  m_pcControllableEntity = &(c_entity.GetComponent<CControllableEntity>("controller"));
37  }
38  catch(CARGoSException& ex) {
39  THROW_ARGOSEXCEPTION_NESTED("Can't set robot for the radios default sensor", ex);
40  }
41  }
42 
43  /****************************************/
44  /****************************************/
45 
47  try {
48  /* Parent class init */
49  CCI_RadiosSensor::Init(t_tree);
50  /* Show rays? */
51  GetNodeAttributeOrDefault(t_tree, "show_rays", m_bShowRays, m_bShowRays);
52  }
53  catch(CARGoSException& ex) {
54  THROW_ARGOSEXCEPTION_NESTED("Error initializing the radios default sensor", ex);
55  }
56  }
57 
58  /****************************************/
59  /****************************************/
60 
62  for(size_t i = 0; i < m_pcRadioEquippedEntity->GetInstances().size(); ++i) {
64  /* Clear data in the interface */
65  m_vecInterfaces[i].Data.clear();
66  /* Move data from the radio entity to the control interface */
67  for(const std::pair<CVector3, CByteArray>& c_data : cRadio.GetData()) {
68  m_vecInterfaces[i].Data.emplace_back(c_data.second);
69  if(m_bShowRays) {
70  CRay3 cRay(c_data.first, cRadio.GetPosition());
71  m_pcControllableEntity->GetCheckedRays().emplace_back(!c_data.second.Empty(), cRay);
72  }
73  }
74  /* Clear data in the radio entity */
75  cRadio.GetData().clear();
76  }
77  }
78 
79  /****************************************/
80  /****************************************/
81 
83  for(SInterface& s_interface : m_vecInterfaces) {
84  /* Clear the existing data */
85  s_interface.Data.clear();
86  }
87  }
88 
89  /****************************************/
90  /****************************************/
91 
93  "radios", "default",
94  "Michael Allwright [allsey87@gmail.com]",
95  "1.0",
96  "A generic radio sensor to receive messages from nearby radios.",
97  "This radio sensor implementation allows an arbitary number of messages\n"
98  "containing an arbitary number of bytes to be received from nearby robots. The\n"
99  "implementation is very basic and any concepts such as throughput, addressing,\n"
100  "or formatting of a message's contents is beyond the scope of this sensor's\n"
101  "implementation\n\n"
102  "REQUIRED XML CONFIGURATION\n\n"
103  " <controllers>\n"
104  " ...\n"
105  " <my_controller ...>\n"
106  " ...\n"
107  " <sensors>\n"
108  " ...\n"
109  " <radios implementation=\"default\" medium=\"radios\" />\n"
110  " ...\n"
111  " </sensors>\n"
112  " ...\n"
113  " </my_controller>\n"
114  " ...\n"
115  " </controllers>\n\n"
116  "The 'medium' attribute sets the id of the radio medium declared in the <media>\n"
117  "XML section.\n\n"
118  "OPTIONAL XML CONFIGURATION\n\n"
119  "None.\n",
120  "Usable"
121  );
122 
123 }
virtual void Reset()
Resets the sensor to the state it had just after Init().
An entity that contains a pointer to the user-defined controller.
std::vector< std::pair< bool, CRay3 > > & GetCheckedRays()
Returns the list of checked rays.
void GetNodeAttributeOrDefault(TConfigurationNode &t_node, const std::string &str_attribute, T &t_buffer, const T &t_default)
Returns the value of a node's attribute, or the passed default value.
virtual void Update()
Updates the state of the entity associated to this sensor.
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
SInstance::TVector & GetInstances()
Returns the radios.
#define THROW_ARGOSEXCEPTION_NESTED(message, nested)
This macro throws an ARGoS exception with the passed message and nesting the passed exception...
SInterface::TVector m_vecInterfaces
const CVector3 & GetPosition() const
Basic class for an entity that contains other entities.
CRadioEntity & GetRadio(UInt32 un_index)
Returns a radio by numeric index.
virtual void Init(TConfigurationNode &t_node)
Initializes the sensor from the XML configuration tree.
Definition: ci_sensor.h:54
A container of CRadioEntity.
The exception that wraps all errors in ARGoS.
CRadioEquippedEntity * m_pcRadioEquippedEntity
virtual void Init(TConfigurationNode &t_tree)
Initializes the sensor from the XML configuration tree.
virtual void SetRobot(CComposableEntity &c_entity)
Sets the entity associated to this sensor.
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
CControllableEntity * m_pcControllableEntity
const std::vector< std::pair< CVector3, CByteArray > > & GetData() const
Returns a constant reference to the received data.
Definition: radio_entity.h:57
CEntity & GetComponent(const std::string &str_component)
Returns the component with the passed string label.
REGISTER_SENSOR(CEyeBotLightRotZOnlySensor,"eyebot_light","rot_z_only","Carlo Pinciroli [ilpincy@gmail.com]","1.0","The eye-bot light sensor (optimized for 2D).","This sensor accesses a set of light sensors. The sensors all return a value\n""between 0 and 1, where 0 means nothing within range and 1 means the perceived\n""light saturates the sensor. Values between 0 and 1 depend on the distance of\n""the perceived light. Each reading R is calculated with R=(I/x)^2, where x is the\n""distance between a sensor and the light, and I is the reference intensity of the\n""perceived light. The reference intensity corresponds to the minimum distance at\n""which the light saturates a sensor. The reference intensity depends on the\n""individual light, and it is set with the \"intensity\" attribute of the light\n""entity. In case multiple lights are present in the environment, each sensor\n""reading is calculated as the sum of the individual readings due to each light.\n""In other words, light wave interference is not taken into account. In\n""controllers, you must include the ci_light_sensor.h header.\n\n""REQUIRED XML CONFIGURATION\n\n"" <controllers>\n"" ...\n"" <my_controller ...>\n"" ...\n"" <sensors>\n"" ...\n"" <eyebot_light implementation=\"rot_z_only\" />\n"" ...\n"" </sensors>\n"" ...\n"" </my_controller>\n"" ...\n"" </controllers>\n\n""OPTIONAL XML CONFIGURATION\n\n""It is possible to draw the rays shot by the light sensor in the OpenGL\n""visualization. This can be useful for sensor debugging but also to understand\n""what's wrong in your controller. In OpenGL, the rays are drawn in cyan when\n""they are not obstructed and in purple when they are. In case a ray is\n""obstructed, a black dot is drawn where the intersection occurred.\n""To turn this functionality on, add the attribute \"show_rays\" as in this\n""example:\n\n"" <controllers>\n"" ...\n"" <my_controller ...>\n"" ...\n"" <sensors>\n"" ...\n"" <eyebot_light implementation=\"rot_z_only\"\n"" show_rays=\"true\" />\n"" ...\n"" </sensors>\n"" ...\n"" </my_controller>\n"" ...\n"" </controllers>\n\n""It is possible to add uniform noise to the sensors, thus matching the\n""characteristics of a real robot better. This can be done with the attribute\n""\"noise_level\", whose allowed range is in [-1,1] and is added to the calculated\n""reading. The final sensor reading is always normalized in the [0-1] range.\n\n"" <controllers>\n"" ...\n"" <my_controller ...>\n"" ...\n"" <sensors>\n"" ...\n"" <eyebot_light implementation=\"rot_z_only\"\n"" noise_level=\"0.1\" />\n"" ...\n"" </sensors>\n"" ...\n"" </my_controller>\n"" ...\n"" </controllers>\n\n""OPTIONAL XML CONFIGURATION\n\n""None.\n","Usable")