Warning: include(php/utility.php): Failed to open stream: No such file or directory in /home/argos/argos3/doc/api/embedded/a00778_source.php on line 2

Warning: include(): Failed opening 'php/utility.php' for inclusion (include_path='.:/usr/lib64/php') in /home/argos/argos3/doc/api/embedded/a00778_source.php on line 2
The ARGoS Website

radio_equipped_entity.cpp
Go to the documentation of this file.
1 
8 #include <argos3/core/simulator/simulator.h>
9 #include <argos3/core/simulator/space/space.h>
10 #include <argos3/plugins/simulator/media/radio_medium.h>
11 
12 namespace argos {
13 
14  /****************************************/
15  /****************************************/
16 
18  SAnchor& s_anchor,
19  const CVector3& c_offset) :
20  Radio(c_radio),
21  Anchor(s_anchor),
22  Offset(c_offset) {}
23 
24  /****************************************/
25  /****************************************/
26 
28  CComposableEntity(pc_parent) {
29  Disable();
30  }
31 
32  /****************************************/
33  /****************************************/
34 
36  const std::string& str_id) :
37  CComposableEntity(pc_parent, str_id) {
38  Disable();
39  }
40 
41  /****************************************/
42  /****************************************/
43 
45  try {
46  /* Init parent */
48  /* Go through the radop entries */
49  TConfigurationNodeIterator itRadio("radio");
50  for(itRadio = itRadio.begin(&t_tree);
51  itRadio != itRadio.end();
52  ++itRadio) {
53  /* Initialise the radio using the XML */
54  CRadioEntity* pcRadio = new CRadioEntity(this);
55  pcRadio->Init(*itRadio);
56  CVector3 cOffset;
57  GetNodeAttribute(*itRadio, "position", cOffset);
58  /* Parse and look up the anchor */
59  std::string strAnchorId;
60  GetNodeAttribute(*itRadio, "anchor", strAnchorId);
61  /*
62  * NOTE: here we get a reference to the embodied entity
63  * This line works under the assumption that:
64  * 1. the RadioEquippedEntity has a parent;
65  * 2. the parent has a child whose id is "body"
66  * 3. the "body" is an embodied entity
67  * If any of the above is false, this line will bomb out.
68  */
70  /* Add the radio to this container */
71  m_vecInstances.emplace_back(*pcRadio, cBody.GetAnchor(strAnchorId), cOffset);
72  AddComponent(*pcRadio);
73  }
75  }
76  catch(CARGoSException& ex) {
77  THROW_ARGOSEXCEPTION_NESTED("Failed to initialize radio equipped entity \"" <<
78  GetContext() + GetId() << "\".", ex);
79  }
80  }
81 
82  /****************************************/
83  /****************************************/
84 
86  /* Perform generic enable behavior */
88  /* Enable anchors */
89  for(SInstance& s_instance : m_vecInstances) {
90  s_instance.Anchor.Enable();
91  }
92  }
93 
94  /****************************************/
95  /****************************************/
96 
98  /* Perform generic disable behavior */
100  /* Disable anchors */
101  for(SInstance& s_instance : m_vecInstances) {
102  s_instance.Anchor.Disable();
103  }
104  }
105 
106  /****************************************/
107  /****************************************/
108 
110  ARGOS_ASSERT(un_index < m_vecInstances.size(),
111  "CRadioEquippedEntity::GetRadio(), id=\"" <<
112  GetContext() + GetId() <<
113  "\": index out of bounds: un_index = " <<
114  un_index <<
115  ", m_vecInstances.size() = " <<
116  m_vecInstances.size());
117  return m_vecInstances[un_index].Radio;
118  }
119 
120  /****************************************/
121  /****************************************/
122 
124  CVector3 cPosition;
125  for(SInstance& s_instance : m_vecInstances) {
126  if(s_instance.Radio.IsEnabled()) {
127  cPosition = s_instance.Offset;
128  cPosition.Rotate(s_instance.Anchor.Orientation);
129  cPosition += s_instance.Anchor.Position;
130  s_instance.Radio.SetPosition(cPosition);
131  }
132  }
133  }
134 
135  /****************************************/
136  /****************************************/
137 
139  for(SInstance& s_instance : m_vecInstances) {
140  s_instance.Radio.SetMedium(c_medium);
141  }
142  }
143 
144  /****************************************/
145  /****************************************/
146 
148 
149  /****************************************/
150  /****************************************/
151 
152 }
A 3D vector class.
Definition: vector3.h:29
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
SInstance::TVector m_vecInstances
List of the radios managed by this entity.
void Enable()
Enables the entity.
Definition: entity.h:265
CVector3 & Rotate(const CQuaternion &c_quaternion)
Rotates this vector by the given quaternion.
Definition: vector3.cpp:25
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
This entity is a link to a body in the physics engine.
#define THROW_ARGOSEXCEPTION_NESTED(message, nested)
This macro throws an ARGoS exception with the passed message and nesting the passed exception...
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
#define ARGOS_ASSERT(condition, message)
When code is compiled in debug, this macro throws an ARGoS exception with the passed message if the s...
unsigned int UInt32
32-bit unsigned integer.
Definition: datatypes.h:97
Basic class for an entity that contains other entities.
CRadioEntity & GetRadio(UInt32 un_index)
Returns a radio by numeric index.
An anchor related to the body of an entity.
Definition: physics_model.h:38
void AddComponent(CEntity &c_component)
Adds a component to this composable entity.
void SetMedium(CRadioMedium &c_medium)
Sets the medium associated to this entity.
ticpp::Iterator< ticpp::Element > TConfigurationNodeIterator
The iterator for the ARGoS configuration XML node.
void GetNodeAttribute(TConfigurationNode &t_node, const std::string &str_attribute, T &t_buffer)
Returns the value of a node's attribute.
A container of CRadioEntity.
The exception that wraps all errors in ARGoS.
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
Definition: entity.cpp:40
virtual void UpdateComponents()
Calls the Update() method on all the components.
void Disable()
Disables the entity.
Definition: entity.h:275
CRadioEquippedEntity(CComposableEntity *pc_parent)
Class constructor.
const SAnchor & GetAnchor(const std::string &str_id) const
Returns the wanted anchor as a const reference.
const std::string & GetId() const
Returns the id of this entity.
Definition: entity.h:157
CComposableEntity & GetParent()
Returns this entity's parent.
Definition: entity.cpp:91
REGISTER_STANDARD_SPACE_OPERATIONS_ON_COMPOSABLE(CComposableEntity)
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
std::string GetContext() const
Returns the context of this entity.
Definition: entity.cpp:79
SInstance(CRadioEntity &c_radio, SAnchor &s_anchor, const CVector3 &c_offset)
CEntity & GetComponent(const std::string &str_component)
Returns the component with the passed string label.