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