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  /* sensor is enabled by default */
43  Enable();
44  }
45 
46  /****************************************/
47  /****************************************/
48 
50  try {
51  /* Parent class init */
52  CCI_RadiosSensor::Init(t_tree);
53  /* Show rays? */
54  GetNodeAttributeOrDefault(t_tree, "show_rays", m_bShowRays, m_bShowRays);
55  }
56  catch(CARGoSException& ex) {
57  THROW_ARGOSEXCEPTION_NESTED("Error initializing the radios default sensor", ex);
58  }
59  }
60 
61  /****************************************/
62  /****************************************/
63 
65  /* sensor is disabled--nothing to do */
66  if (IsDisabled()) {
67  return;
68  }
69  for(size_t i = 0; i < m_pcRadioEquippedEntity->GetInstances().size(); ++i) {
71  /* Clear data in the interface */
72  m_vecInterfaces[i].Data.clear();
73  /* Move data from the radio entity to the control interface */
74  for(const std::pair<CVector3, CByteArray>& c_data : cRadio.GetData()) {
75  m_vecInterfaces[i].Data.emplace_back(c_data.second);
76  if(m_bShowRays) {
77  CRay3 cRay(c_data.first, cRadio.GetPosition());
78  m_pcControllableEntity->GetCheckedRays().emplace_back(!c_data.second.Empty(), cRay);
79  }
80  }
81  /* Clear data in the radio entity */
82  cRadio.GetData().clear();
83  }
84  }
85 
86  /****************************************/
87  /****************************************/
88 
90  for(SInterface& s_interface : m_vecInterfaces) {
91  /* Clear the existing data */
92  s_interface.Data.clear();
93  }
94  }
95 
96  /****************************************/
97  /****************************************/
98 
100  "radios", "default",
101  "Michael Allwright [allsey87@gmail.com]",
102  "1.0",
103 
104  "A generic radio sensor to receive messages from nearby radios.",
105  "This radio sensor implementation allows an arbitary number of messages\n"
106  "containing an arbitary number of bytes to be received from nearby robots. The\n"
107  "implementation is very basic and any concepts such as throughput, addressing,\n"
108  "or formatting of a message's contents is beyond the scope of this sensor's\n"
109  "implementation\n\n"
110 
111  "This sensor is enabled by default.\n\n"
112 
113  "REQUIRED XML CONFIGURATION\n\n"
114 
115  " <controllers>\n"
116  " ...\n"
117  " <my_controller ...>\n"
118  " ...\n"
119  " <sensors>\n"
120  " ...\n"
121  " <radios implementation=\"default\" medium=\"radios\" />\n"
122  " ...\n"
123  " </sensors>\n"
124  " ...\n"
125  " </my_controller>\n"
126  " ...\n"
127  " </controllers>\n\n"
128 
129  "The 'medium' attribute sets the id of the radio medium declared in the <media>\n"
130  "XML section.\n\n"
131 
132  "OPTIONAL XML CONFIGURATION\n\n"
133 
134  "None.\n",
135 
136  "Usable"
137  );
138 
139 }
#define THROW_ARGOSEXCEPTION_NESTED(message, nested)
This macro throws an ARGoS exception with the passed message and nesting the passed exception.
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
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.
REGISTER_SENSOR(CEPuckProximityDefaultSensor, "epuck_proximity", "default", "Danesh Tarapore [daneshtarapore@gmail.com]", "1.0", "The E-Puck proximity sensor.", "This sensor accesses the epuck proximity sensor. For a complete description\n" "of its usage, refer to the ci_epuck_proximity_sensor.h interface. For the XML\n" "configuration, refer to the default proximity sensor.\n", "Usable")
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
virtual void Enable()
Enables updating of sensor information in the event loop.
Definition: ci_sensor.h:78
virtual void Init(TConfigurationNode &t_node)
Initializes the sensor from the XML configuration tree.
Definition: ci_sensor.h:54
bool IsDisabled() const
Definition: ci_sensor.h:86
Basic class for an entity that contains other entities.
CEntity & GetComponent(const std::string &str_component)
Returns the component with the passed string label.
An entity that contains a pointer to the user-defined controller.
std::vector< std::pair< bool, CRay3 > > & GetCheckedRays()
Returns the list of checked rays.
const CVector3 & GetPosition() const
The exception that wraps all errors in ARGoS.
SInterface::TVector m_vecInterfaces
virtual void Update()
Updates the state of the entity associated to this sensor, if the sensor is currently enabled.
CControllableEntity * m_pcControllableEntity
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.
virtual void Reset()
Resets the sensor to the state it had just after Init().
const std::vector< std::pair< CVector3, CByteArray > > & GetData() const
Returns a constant reference to the received data.
Definition: radio_entity.h:57
A container of CRadioEntity.
SInstance::TVector & GetInstances()
Returns the radios.
CRadioEntity & GetRadio(UInt32 un_index)
Returns a radio by numeric index.