Warning: include(php/utility.php): Failed to open stream: No such file or directory in /home/argos/argos3/doc/api/embedded/a00784_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/a00784_source.php on line 2
The ARGoS Website

tag_equipped_entity.cpp
Go to the documentation of this file.
1 
7 #include "tag_equipped_entity.h"
8 #include <argos3/core/simulator/simulator.h>
9 #include <argos3/core/simulator/space/space.h>
10 #include <argos3/plugins/simulator/media/tag_medium.h>
11 
12 namespace argos {
13 
14  /****************************************/
15  /****************************************/
16 
18  SAnchor& s_anchor,
19  const CVector3& c_position_offset,
20  const CQuaternion& c_orientation_offset) :
21  Tag(c_tag),
22  Anchor(s_anchor),
23  PositionOffset(c_position_offset),
24  OrientationOffset(c_orientation_offset) {}
25 
26  /****************************************/
27  /****************************************/
28 
30  CComposableEntity(pc_parent) {
31  Disable();
32  }
33 
34  /****************************************/
35  /****************************************/
36 
38  const std::string& str_id) :
39  CComposableEntity(pc_parent, str_id) {
40  Disable();
41  }
42 
43  /****************************************/
44  /****************************************/
45 
47  try {
48  /* Init parent */
50  /* Go through the tag entries */
51  TConfigurationNodeIterator itTag("tag");
52  for(itTag = itTag.begin(&t_tree);
53  itTag != itTag.end();
54  ++itTag) {
55  /* Initialise the Tag using the XML */
56  CTagEntity* pcTag = new CTagEntity(this);
57  pcTag->Init(*itTag);
58  CVector3 cPositionOffset;
59  GetNodeAttribute(*itTag, "position", cPositionOffset);
60  CQuaternion cOrientationOffset;
61  GetNodeAttribute(*itTag, "orientation", cOrientationOffset);
62  /* Parse and look up the anchor */
63  std::string strAnchorId;
64  GetNodeAttribute(*itTag, "anchor", strAnchorId);
65  /*
66  * NOTE: here we get a reference to the embodied entity
67  * This line works under the assumption that:
68  * 1. the TagEquippedEntity has a parent;
69  * 2. the parent has a child whose id is "body"
70  * 3. the "body" is an embodied entity
71  * If any of the above is false, this line will bomb out.
72  */
74  /* Add the tag to this container */
75  m_vecInstances.emplace_back(*pcTag,
76  cBody.GetAnchor(strAnchorId),
77  cPositionOffset,
78  cOrientationOffset);
79  AddComponent(*pcTag);
80  }
82  }
83  catch(CARGoSException& ex) {
84  THROW_ARGOSEXCEPTION_NESTED("Failed to initialize tag equipped entity \"" <<
85  GetContext() + GetId() << "\".", ex);
86  }
87  }
88 
89  /****************************************/
90  /****************************************/
91 
93  /* Perform generic enable behavior */
95  /* Enable anchors */
96  for(SInstance& s_instance : m_vecInstances) {
97  s_instance.Anchor.Enable();
98  }
99  }
100 
101  /****************************************/
102  /****************************************/
103 
105  /* Perform generic disable behavior */
107  /* Disable anchors */
108  for(SInstance& s_instance : m_vecInstances) {
109  s_instance.Anchor.Disable();
110  }
111  }
112 
113  /****************************************/
114  /****************************************/
115 
117  ARGOS_ASSERT(un_index < m_vecInstances.size(),
118  "CTagEquippedEntity::GetTag(), id=\"" <<
119  GetContext() << GetId() <<
120  "\": index out of bounds: un_index = " <<
121  un_index <<
122  ", m_vecInstances.size() = " <<
123  m_vecInstances.size());
124  return m_vecInstances[un_index].Tag;
125  }
126 
127  /****************************************/
128  /****************************************/
129 
131  const std::string& str_payload) {
132  ARGOS_ASSERT(un_index < m_vecInstances.size(),
133  "CTagEquippedEntity::SetTagPayload(), id=\"" <<
134  GetContext() << GetId() <<
135  "\": index out of bounds: un_index = " <<
136  un_index <<
137  ", m_vecInstances.size() = " <<
138  m_vecInstances.size());
139  m_vecInstances[un_index].Tag.SetPayload(str_payload);
140  }
141 
142  /****************************************/
143  /****************************************/
144 
145  void CTagEquippedEntity::SetTagPayloads(const std::string& str_payload) {
146  for(SInstance& s_instance : m_vecInstances) {
147  s_instance.Tag.SetPayload(str_payload);
148  }
149  }
150 
151  /****************************************/
152  /****************************************/
153 
154  void CTagEquippedEntity::SetTagPayloads(const std::vector<std::string>& vec_payloads) {
155  if(vec_payloads.size() == m_vecInstances.size()) {
156  for(UInt32 i = 0; i < vec_payloads.size(); ++i) {
157  m_vecInstances[i].Tag.SetPayload(vec_payloads[i]);
158  }
159  }
160  else {
162  "CTagEquippedEntity::SetTagPayloads(), id=\"" <<
163  GetContext() << GetId() <<
164  "\": number of tags (" <<
165  m_vecInstances.size() <<
166  ") does not equal the passed payload vector size (" <<
167  vec_payloads.size() <<
168  ")");
169  }
170  }
171 
172  /****************************************/
173  /****************************************/
174 
176  /* Tag position wrt global reference frame */
177  CVector3 cTagPosition;
178  CQuaternion cTagOrientation;
179  for(SInstance& s_instance : m_vecInstances) {
180  if(s_instance.Tag.IsEnabled()) {
181  cTagPosition = s_instance.PositionOffset;
182  cTagPosition.Rotate(s_instance.Anchor.Orientation);
183  cTagPosition += s_instance.Anchor.Position;
184  cTagOrientation = s_instance.Anchor.Orientation *
185  s_instance.OrientationOffset;
186  s_instance.Tag.MoveTo(cTagPosition, cTagOrientation);
187  }
188  }
189  }
190 
191  /****************************************/
192  /****************************************/
193 
195  for(SInstance& s_instance : m_vecInstances) {
196  s_instance.Tag.SetMedium(c_medium);
197  }
198  }
199 
200  /****************************************/
201  /****************************************/
202 
204 
205  /****************************************/
206  /****************************************/
207 
208 }
A 3D vector class.
Definition: vector3.h:29
void SetTagPayload(UInt32 un_index, const std::string &str_payload)
Sets the payload of a tag.
void Enable()
Enables the entity.
Definition: entity.h:265
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
void SetMedium(CTagMedium &c_medium)
Sets the medium associated to this entity.
CVector3 & Rotate(const CQuaternion &c_quaternion)
Rotates this vector by the given quaternion.
Definition: vector3.cpp:25
A container of CTagEntity.
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
Definition: tag_entity.cpp:47
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...
SInstance(CTagEntity &c_tag, SAnchor &s_anchor, const CVector3 &c_position_offset, const CQuaternion &c_orientation_offset)
#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.
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
An anchor related to the body of an entity.
Definition: physics_model.h:38
SInstance::TVector m_vecInstances
List of the tags managed by this entity.
void AddComponent(CEntity &c_component)
Adds a component to this composable 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.
The exception that wraps all errors in ARGoS.
CTagEntity & GetTag(UInt32 un_index)
Returns a tag by numeric index.
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
Definition: entity.cpp:40
void Disable()
Disables the entity.
Definition: entity.h:275
CTagEquippedEntity(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
virtual void UpdateComponents()
Calls the Update() method on all the components.
CEntity & GetComponent(const std::string &str_component)
Returns the component with the passed string label.
void SetTagPayloads(const std::string &str_payload)
Sets the payload of all the tags to the given payload.