radios_default_actuator.cpp
Go to the documentation of this file.
1 
8 #include <argos3/plugins/simulator/media/radio_medium.h>
9 #include <argos3/plugins/simulator/entities/radio_equipped_entity.h>
10 
11 namespace argos {
12 
13  /****************************************/
14  /****************************************/
15 
16  class CTxOperation : public CPositionalIndex<CRadioEntity>::COperation {
17 
18  public:
19 
20  CTxOperation(const CRadioEntity& c_tx_radio,
21  const std::vector<CByteArray>& c_tx_data) :
22  m_cTxRadio(c_tx_radio),
23  m_cTxData(c_tx_data) {}
24 
25  virtual bool operator()(CRadioEntity& c_rx_radio) {
26  if(&c_rx_radio != &m_cTxRadio) {
27  const CVector3& cRxRadioPosition = c_rx_radio.GetPosition();
28  const CVector3& cTxRadioPosition = m_cTxRadio.GetPosition();
29  Real fDistance = (cRxRadioPosition - cTxRadioPosition).Length();
30  if(fDistance < m_cTxRadio.GetRange()) {
31  for(const CByteArray& c_data : m_cTxData) {
32  c_rx_radio.ReceiveData(cTxRadioPosition, c_data);
33  }
34  }
35  }
36  return true;
37  }
38 
39  private:
40 
41  const CRadioEntity& m_cTxRadio;
42  const std::vector<CByteArray>& m_cTxData;
43 
44  };
45 
46 
47  /****************************************/
48  /****************************************/
49 
51  m_pcRadioEquippedEntity(nullptr) {
52  }
53 
54  /****************************************/
55  /****************************************/
56 
58  try {
59  /* Get and enable omndirectional radio equipped entity */
61  /* Create a configuration settings for each radio in the container */
63  /* Populate the descriptors */
65  m_vecInterfaces.emplace_back(s_instance.Radio.GetId());
66  }
67  }
68  catch(CARGoSException& ex) {
69  THROW_ARGOSEXCEPTION_NESTED("Can't set robot for the radios default actuator", ex);
70  }
71  }
72 
73  /****************************************/
74  /****************************************/
75 
77  try {
78  /* Parent class init */
80  }
81  catch(CARGoSException& ex) {
82  THROW_ARGOSEXCEPTION_NESTED("Error initializing the radios default actuator", ex);
83  }
84  }
85 
86 
87  /****************************************/
88  /****************************************/
89 
91  for(size_t i = 0; i < m_vecInterfaces.size(); ++i) {
93  /* Create operation instance */
94  CTxOperation cTxOperation(cRadio, m_vecInterfaces[i].Data);
95  /* Calculate the range of the transmitting radio */
96  CVector3 cTxRange(1.0f,1.0f,1.0f);
97  cTxRange *= (cRadio.GetRange() * 0.5f);
98  /* Get positional index */
99  CPositionalIndex<CRadioEntity>* pcRadioIndex =
100  &(cRadio.GetMedium().GetIndex());
101  /* Transmit the data to receiving radios in the space */
102  pcRadioIndex->ForEntitiesInBoxRange(cRadio.GetPosition(), cTxRange, cTxOperation);
103  /* Flush data from the control interface */
104  m_vecInterfaces[i].Data.clear();
105  }
106  }
107 
108  /****************************************/
109  /****************************************/
110 
112  for(SInterface& s_interface : m_vecInterfaces) {
113  /* Clear any data in the interface */
114  s_interface.Data.clear();
115  }
116  }
117 
118  /****************************************/
119  /****************************************/
120 
122  "radios", "default",
123  "Michael Allwright [allsey87@gmail.com]",
124  "1.0",
125  "A generic radio actuator to send messages to nearby radios.",
126  "This radio actuator implementation allows an arbitary number of messages\n"
127  "containing an arbitary number of bytes to be sent to nearby radios. The\n"
128  "implementation of this actuator is very basic and any concepts such as\n"
129  "throughput, addressing, or formatting of a message's contents is beyond the\n"
130  "scope of this actuator's implementation.\n\n"
131  "REQUIRED XML CONFIGURATION\n\n"
132  " <controllers>\n"
133  " ...\n"
134  " <my_controller ...>\n"
135  " ...\n"
136  " <actuators>\n"
137  " ...\n"
138  " <radios implementation=\"default\" medium=\"radios\" />\n"
139  " ...\n"
140  " </actuators>\n"
141  " ...\n"
142  " </my_controller>\n"
143  " ...\n"
144  " </controllers>\n\n"
145  "The 'medium' attribute sets the id of the radio medium declared in the <media>\n"
146  "XML section.\n\n"
147  "OPTIONAL XML CONFIGURATION\n\n"
148  "None.\n",
149  "Usable"
150  );
151 
152  /****************************************/
153  /****************************************/
154 
155 }
A 3D vector class.
Definition: vector3.h:29
void ReceiveData(const CVector3 &c_tx_location, const CByteArray &c_tx_data)
Adds data received by the radio.
Definition: radio_entity.h:75
CPositionalIndex< CRadioEntity > & GetIndex()
Returns the radio positional index.
Definition: radio_medium.h:59
float Real
Collects all ARGoS code.
Definition: datatypes.h:39
SInterface::TVector m_vecInterfaces
virtual void ForEntitiesInBoxRange(const CVector3 &c_center, const CVector3 &c_half_size, COperation &c_operation)=0
Executes an operation on all entities within the specified box range.
Real GetRange() const
Returns the transmission range of the radio.
Definition: radio_entity.h:94
REGISTER_ACTUATOR(CFootBotDistanceScannerDefaultActuator,"footbot_distance_scanner","default","Carlo Pinciroli [ilpincy@gmail.com]","1.0","The foot-bot distance scanner actuator.","This actuator controls the foot-bot distance scanner. For a complete\n""description of its usage, refer to the ci_footbot_distance_scanner_actuator\n""file.\n\n""REQUIRED XML CONFIGURATION\n\n"" <controllers>\n"" ...\n"" <my_controller ...>\n"" ...\n"" <actuators>\n"" ...\n"" <footbot_distance_scanner implementation=\"default\" />\n"" ...\n"" </actuators>\n"" ...\n"" </my_controller>\n"" ...\n"" </controllers>\n\n""OPTIONAL XML CONFIGURATION\n\n""None for the time being.\n","Usable")
A data structure that contains positional entities.
virtual void Update()
Updates the state of the entity associated to this actuator.
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...
CRadioMedium & GetMedium() const
Returns the medium associated to this radio.
virtual void SetRobot(CComposableEntity &c_entity)
Sets the entity associated to this actuator.
const CVector3 & GetPosition() const
virtual void Init(TConfigurationNode &t_node)
Initializes the actuator from the XML configuration tree.
Definition: ci_actuator.h:54
CRadioEquippedEntity * m_pcRadioEquippedEntity
Basic class for an entity that contains other entities.
CRadioEntity & GetRadio(UInt32 un_index)
Returns a radio by numeric index.
A container of CRadioEntity.
The exception that wraps all errors in ARGoS.
Byte array utility class.
Definition: byte_array.h:28
CTxOperation(const CRadioEntity &c_tx_radio, const std::vector< CByteArray > &c_tx_data)
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
virtual bool operator()(CRadioEntity &c_rx_radio)
virtual void Reset()
Resets the actuator to the state it had just after Init().
virtual void Init(TConfigurationNode &t_tree)
Initializes the actuator from the XML configuration tree.
CEntity & GetComponent(const std::string &str_component)
Returns the component with the passed string label.