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

space.cpp
Go to the documentation of this file.
1 
11 #include <argos3/core/utility/string_utilities.h>
12 #include <argos3/core/utility/math/range.h>
13 #include <argos3/core/utility/logging/argos_log.h>
14 #include <argos3/core/utility/math/rng.h>
15 #include <argos3/core/simulator/simulator.h>
16 #include <argos3/core/simulator/entity/composable_entity.h>
17 #include <argos3/core/simulator/entity/positional_entity.h>
18 #include <argos3/core/simulator/loop_functions.h>
19 #include <cstring>
20 #include "space.h"
21 
22 namespace argos {
23 
24  /****************************************/
25  /****************************************/
26 
28  m_cSimulator(CSimulator::GetInstance()),
29  m_unSimulationClock(0),
30  m_pcFloorEntity(NULL),
31  m_ptPhysicsEngines(NULL),
32  m_ptMedia(NULL) {}
33 
34  /****************************************/
35  /****************************************/
36 
38  /* Get reference to physics engine and media vectors */
41  /* Get the arena center and size */
43  GetNodeAttribute(t_tree, "size", m_cArenaSize);
45  m_cArenaCenter + m_cArenaSize / 2.0f);
46  /*
47  * Add and initialize all entities in XML
48  */
49  /* Start from the entities placed manually */
50  TConfigurationNodeIterator itArenaItem;
51  for(itArenaItem = itArenaItem.begin(&t_tree);
52  itArenaItem != itArenaItem.end();
53  ++itArenaItem) {
54  if(itArenaItem->Value() != "distribute") {
55  CEntity* pcEntity = CFactory<CEntity>::New(itArenaItem->Value());
56  pcEntity->Init(*itArenaItem);
57  CallEntityOperation<CSpaceOperationAddEntity, CSpace, void>(*this, *pcEntity);
58  }
59  }
60  /* Place the entities to distribute automatically */
61  for(itArenaItem = itArenaItem.begin(&t_tree);
62  itArenaItem != itArenaItem.end();
63  ++itArenaItem) {
64  if(itArenaItem->Value() == "distribute") {
65  Distribute(*itArenaItem);
66  }
67  }
68  }
69 
70  /****************************************/
71  /****************************************/
72 
73  void CSpace::Reset() {
74  /* Reset the simulation clock */
76  /* Reset the entities */
77  for(UInt32 i = 0; i < m_vecEntities.size(); ++i) {
78  m_vecEntities[i]->Reset();
79  }
80  }
81 
82  /****************************************/
83  /****************************************/
84 
85  void CSpace::Destroy() {
86  /* Remove all entities */
87  while(!m_vecRootEntities.empty()) {
88  CallEntityOperation<CSpaceOperationRemoveEntity, CSpace, void>(*this, *m_vecRootEntities.back());
89  }
90  }
91 
92  /****************************************/
93  /****************************************/
94 
96  const std::string& str_pattern) {
97  for(CEntity::TVector::iterator it = m_vecEntities.begin();
98  it != m_vecEntities.end(); ++it) {
99  if(MatchPattern((*it)->GetId(), str_pattern)) {
100  t_buffer.push_back(*it);
101  }
102  }
103  }
104 
105  /****************************************/
106  /****************************************/
107 
108  CSpace::TMapPerType& CSpace::GetEntitiesByType(const std::string& str_type) {
109  TMapPerTypePerId::iterator itEntities = m_mapEntitiesPerTypePerId.find(str_type);
110  if (itEntities != m_mapEntitiesPerTypePerId.end()){
111  return itEntities->second;
112  }
113  else {
114  THROW_ARGOSEXCEPTION("Entity map for type \"" << str_type << "\" not found.");
115  }
116  }
117 
118  /****************************************/
119  /****************************************/
120 
121  void CSpace::Update() {
122  /* Increase the simulation clock */
124  /* Perform the 'act' phase for controllable entities */
126  /* Update the physics engines */
127  UpdatePhysics();
128  /* Update media */
129  UpdateMedia();
130  /* Call loop functions */
132  /* Perform the 'sense+step' phase for controllable entities */
134  /* Call loop functions */
136  /* Flush logs */
137  LOG.Flush();
138  LOGERR.Flush();
139  }
140 
141  /****************************************/
142  /****************************************/
143 
145  m_vecControllableEntities.push_back(&c_entity);
146  }
147 
148  /****************************************/
149  /****************************************/
150 
152  CControllableEntity::TVector::iterator it = find(m_vecControllableEntities.begin(),
154  &c_entity);
155  if(it != m_vecControllableEntities.end()) {
156  m_vecControllableEntities.erase(it);
157  }
158  }
159 
160  /****************************************/
161  /****************************************/
162 
164  /* Get a reference to the root entity */
165  CEntity* pcToAdd = &c_entity.GetRootEntity();
166  /* Get a reference to the position of the entity */
167  const CVector3& cPos = c_entity.GetOriginAnchor().Position;
168  /* Go through engines and check which ones could house the entity */
169  CPhysicsEngine::TVector vecPotentialEngines;
170  for(size_t i = 0; i < m_ptPhysicsEngines->size(); ++i) {
171  if((*m_ptPhysicsEngines)[i]->IsPointContained(cPos)) {
172  vecPotentialEngines.push_back((*m_ptPhysicsEngines)[i]);
173  }
174  }
175  /* If no engine can house the entity, bomb out */
176  if(vecPotentialEngines.empty()) {
177  THROW_ARGOSEXCEPTION("No physics engine can house entity \"" << pcToAdd->GetId() << "\".");
178  }
179  /* If the entity is not movable, add the entity to all the matching engines */
180  if(! c_entity.IsMovable()) {
181  bool bAdded = false;
182  for(size_t i = 0; i < vecPotentialEngines.size(); ++i) {
183  bAdded |= vecPotentialEngines[i]->AddEntity(*pcToAdd);
184  }
185  if(!bAdded) {
186  THROW_ARGOSEXCEPTION("No physics engine can house entity \"" << pcToAdd->GetId() << "\".");
187  }
188  }
189  /* If the entity is movable, only one engine can be associated to the embodied entity */
190  else if(vecPotentialEngines.size() == 1) {
191  /* Only one engine matches, bingo! */
192  if(!vecPotentialEngines[0]->AddEntity(*pcToAdd)) {
193  THROW_ARGOSEXCEPTION("No physics engine can house entity \"" << pcToAdd->GetId() << "\".");
194  }
195  }
196  else {
197  /* More than one engine matches, pick the first that can manage the entity */
198  for(size_t i = 0; i < vecPotentialEngines.size(); ++i) {
199  if(vecPotentialEngines[i]->AddEntity(*pcToAdd)) return;
200  }
201  /* No engine can house the entity */
202  THROW_ARGOSEXCEPTION("No physics engine can house entity \"" << pcToAdd->GetId() << "\".");
203  }
204  }
205 
206  /****************************************/
207  /****************************************/
208 
210  public:
211  virtual ~RealNumberGenerator() {}
212  virtual CVector3 operator()(bool b_is_retry) = 0;
213  };
214 
216  public:
217  ConstantGenerator(const CVector3& c_value) :
218  m_cValue(c_value) {}
219 
220  inline virtual CVector3 operator()(bool b_is_retry) {
221  return m_cValue;
222  }
223  private:
224  CVector3 m_cValue;
225 
226  };
227 
229  public:
231  const CVector3& c_max) :
232  m_cMin(c_min),
233  m_cMax(c_max) {}
234  inline virtual CVector3 operator()(bool b_is_retry) {
235  Real fRandX =
236  m_cMax.GetX() > m_cMin.GetX() ?
237  CSimulator::GetInstance().GetRNG()->Uniform(CRange<Real>(m_cMin.GetX(), m_cMax.GetX())) :
238  m_cMax.GetX();
239  Real fRandY =
240  m_cMax.GetY() > m_cMin.GetY() ?
241  CSimulator::GetInstance().GetRNG()->Uniform(CRange<Real>(m_cMin.GetY(), m_cMax.GetY())) :
242  m_cMax.GetY();
243  Real fRandZ =
244  m_cMax.GetZ() > m_cMin.GetZ() ?
245  CSimulator::GetInstance().GetRNG()->Uniform(CRange<Real>(m_cMin.GetZ(), m_cMax.GetZ())) :
246  m_cMax.GetZ();
247  return CVector3(fRandX, fRandY, fRandZ);
248  }
249  private:
250  CVector3 m_cMin;
251  CVector3 m_cMax;
252  };
253 
255  public:
257  const CVector3& c_std_dev) :
258  m_cMean(c_mean),
259  m_cStdDev(c_std_dev) {}
260  inline virtual CVector3 operator()(bool b_is_retry) {
261  return CVector3(CSimulator::GetInstance().GetRNG()->Gaussian(m_cStdDev.GetX(), m_cMean.GetX()),
262  CSimulator::GetInstance().GetRNG()->Gaussian(m_cStdDev.GetY(), m_cMean.GetY()),
263  CSimulator::GetInstance().GetRNG()->Gaussian(m_cStdDev.GetZ(), m_cMean.GetZ()));
264  }
265  private:
266  CVector3 m_cMean;
267  CVector3 m_cStdDev;
268  };
269 
271  public:
272  GridGenerator(const CVector3 c_center,
273  const UInt32 un_layout[],
274  const CVector3 c_distances):
275  m_cCenter(c_center),
276  m_cDistances(c_distances),
277  m_unNumEntityPlaced(0) {
278  m_unLayout[0] = un_layout[0];
279  m_unLayout[1] = un_layout[1];
280  m_unLayout[2] = un_layout[2];
281  /* Check if layout is sane */
282  if( m_unLayout[0] == 0 || m_unLayout[1] == 0 || m_unLayout[2] == 0 ) {
283  THROW_ARGOSEXCEPTION("'layout' values (distribute position, method 'grid') must all be different than 0");
284  }
285  }
286 
287  virtual CVector3 operator()(bool b_is_retry) {
288  if(b_is_retry) {
289  THROW_ARGOSEXCEPTION("Impossible to place entity #" << m_unNumEntityPlaced << " in grid");
290  }
291  CVector3 cReturn;
292  if(m_unNumEntityPlaced < m_unLayout[0] * m_unLayout[1] * m_unLayout[2]) {
293  cReturn.SetX(m_cCenter.GetX() + ( m_unLayout[0] - 1 ) * m_cDistances.GetX() * 0.5 - ( m_unNumEntityPlaced % m_unLayout[0] ) * m_cDistances.GetX());
294  cReturn.SetY(m_cCenter.GetY() + ( m_unLayout[1] - 1 ) * m_cDistances.GetY() * 0.5 - ( m_unNumEntityPlaced / m_unLayout[0] ) % m_unLayout[1] * m_cDistances.GetY());
295  cReturn.SetZ(m_cCenter.GetZ() + ( m_unLayout[2] - 1 ) * m_cDistances.GetZ() * 0.5 - ( m_unNumEntityPlaced / ( m_unLayout[0] * m_unLayout[1] ) ) * m_cDistances.GetZ());
296  ++m_unNumEntityPlaced;
297  }
298  else {
299  THROW_ARGOSEXCEPTION("Distribute position, method 'grid': trying to place more entities than allowed "
300  "by the 'layout', check your 'quantity' tag");
301  }
302  return cReturn;
303  }
304 
305  private:
306  CVector3 m_cCenter;
307  UInt32 m_unLayout[3];
308  CVector3 m_cDistances;
309  UInt32 m_unNumEntityPlaced;
310  };
311 
312  /****************************************/
313  /****************************************/
314 
316  std::string strMethod;
317  GetNodeAttribute(t_tree, "method", strMethod);
318  if(strMethod == "uniform") {
319  CVector3 cMin, cMax;
320  GetNodeAttribute(t_tree, "min", cMin);
321  GetNodeAttribute(t_tree, "max", cMax);
322  if(! (cMin <= cMax)) {
323  THROW_ARGOSEXCEPTION("Uniform generator: the min is not less than or equal to max: " << cMin << " / " << cMax);
324  }
325  return new UniformGenerator(cMin, cMax);
326  }
327  else if(strMethod == "gaussian") {
328  CVector3 cMean, cStdDev;
329  GetNodeAttribute(t_tree, "mean", cMean);
330  GetNodeAttribute(t_tree, "std_dev", cStdDev);
331  return new GaussianGenerator(cMean, cStdDev);
332  }
333  else if(strMethod == "constant") {
334  CVector3 cValues;
335  GetNodeAttribute(t_tree, "values", cValues);
336  return new ConstantGenerator(cValues);
337  }
338  else if(strMethod == "grid") {
339  CVector3 cCenter,cDistances;
340  GetNodeAttribute(t_tree, "center", cCenter);
341  GetNodeAttribute(t_tree, "distances", cDistances);
342  UInt32 unLayout[3];
343  std::string strLayout;
344  GetNodeAttribute(t_tree, "layout", strLayout);
345  ParseValues<UInt32> (strLayout, 3, unLayout, ',');
346  return new GridGenerator(cCenter, unLayout, cDistances);
347  }
348  else {
349  THROW_ARGOSEXCEPTION("Unknown distribution method \"" << strMethod << "\"");
350  }
351  }
352 
353  /****************************************/
354  /****************************************/
355 
356  static CEmbodiedEntity* GetEmbodiedEntity(CEntity* pc_entity) {
357  /* Is the entity embodied itself? */
358  CEmbodiedEntity* pcEmbodiedTest = dynamic_cast<CEmbodiedEntity*>(pc_entity);
359  if(pcEmbodiedTest != NULL) {
360  return pcEmbodiedTest;
361  }
362  /* Is the entity composable with an embodied component? */
363  CComposableEntity* pcComposableTest = dynamic_cast<CComposableEntity*>(pc_entity);
364  if(pcComposableTest != NULL) {
365  if(pcComposableTest->HasComponent("body")) {
366  return &(pcComposableTest->GetComponent<CEmbodiedEntity>("body"));
367  }
368  }
369  /* No embodied entity found */
370  return NULL;
371  }
372 
373  /****************************************/
374  /****************************************/
375 
376  static CPositionalEntity* GetPositionalEntity(CEntity* pc_entity) {
377  /* Is the entity positional itself? */
378  CPositionalEntity* pcPositionalTest = dynamic_cast<CPositionalEntity*>(pc_entity);
379  if(pcPositionalTest != NULL) {
380  return pcPositionalTest;
381  }
382  /* Is the entity composable with a positional component? */
383  CComposableEntity* pcComposableTest = dynamic_cast<CComposableEntity*>(pc_entity);
384  if(pcComposableTest != NULL) {
385  if(pcComposableTest->HasComponent("position")) {
386  return &(pcComposableTest->GetComponent<CPositionalEntity>("position"));
387  }
388  }
389  /* No positional entity found */
390  return NULL;
391  }
392 
393  /****************************************/
394  /****************************************/
395 
397  try {
398  /* Get the needed nodes */
399  TConfigurationNode cPositionNode;
400  cPositionNode = GetNode(t_tree, "position");
401  TConfigurationNode cOrientationNode;
402  cOrientationNode = GetNode(t_tree, "orientation");
403  TConfigurationNode cEntityNode;
404  cEntityNode = GetNode(t_tree, "entity");
405  /* Create the real number generators */
406  RealNumberGenerator* pcPositionGenerator = CreateGenerator(cPositionNode);
407  RealNumberGenerator* pcOrientationGenerator = CreateGenerator(cOrientationNode);
408  /* How many entities? */
409  UInt32 unQuantity;
410  GetNodeAttribute(cEntityNode, "quantity", unQuantity);
411  /* How many trials before failing? */
412  UInt32 unMaxTrials;
413  GetNodeAttribute(cEntityNode, "max_trials", unMaxTrials);
414  /* Get the (optional) entity base numbering */
415  UInt64 unBaseNum = 0;
416  GetNodeAttributeOrDefault(cEntityNode, "base_num", unBaseNum, unBaseNum);
417  /* Get the entity type to add (take only the first, ignore additional if any) */
419  itEntity = itEntity.begin(&cEntityNode);
420  if(itEntity == itEntity.end()) {
421  THROW_ARGOSEXCEPTION("No entity to distribute specified.");
422  }
423  /* Get the entity base ID */
424  std::string strBaseId;
425  GetNodeAttribute(*itEntity, "id", strBaseId);
426  /* Add the requested entities */
427  for(UInt32 i = 0; i < unQuantity; ++i) {
428  /* Copy the entity XML tree */
429  TConfigurationNode tEntityTree = *itEntity;
430  /* Set progressive ID */
431  SetNodeAttribute(tEntityTree, "id", strBaseId + ToString(i+unBaseNum));
432  /* Go on until the entity is placed with no collisions or
433  the max number of trials has been exceeded */
434  UInt32 unTrials = 0;
435  bool bDone = false;
436  bool bRetry = false;
437  CEntity* pcEntity;
438  do {
439  /* Create entity */
440  pcEntity = CFactory<CEntity>::New(tEntityTree.Value());
441  /*
442  * Now that you have the entity, check whether the
443  * entity is positional or embodied or has one such
444  * component.
445  *
446  * In case the entity is positional but not embodied,
447  * there's no need to check for collisions.
448  *
449  * In case the entity is embodied, we must check for
450  * collisions.
451  *
452  * To check for collisions, we add the entity in the
453  * place where it's supposed to be, then we ask the
454  * engine if that entity is colliding with something.
455  *
456  * In case of collision, we remove the entity and try a
457  * different position/orientation.
458  */
459  /* Check whether the entity is positional */
460  CPositionalEntity* pcPositionalEntity = GetPositionalEntity(pcEntity);
461  if(pcPositionalEntity != NULL) {
462  /* Set the position */
463  SetNodeAttribute(tEntityTree, "position", (*pcPositionGenerator)(bRetry));
464  /* Set the orientation */
465  SetNodeAttribute(tEntityTree, "orientation", (*pcOrientationGenerator)(bRetry));
466  /* Init the entity (this also creates the components, if pcEntity is a composable) */
467  pcEntity->Init(tEntityTree);
468  /* Wherever we want to put the entity, it's OK, add it */
469  CallEntityOperation<CSpaceOperationAddEntity, CSpace, void>(*this, *pcEntity);
470  bDone = true;
471  }
472  else {
473  /* Assume the entity is embodied */
474  /* If the tree does not have a 'body' node, create a new one */
475  if(!NodeExists(tEntityTree, "body")) {
476  TConfigurationNode tBodyNode("body");
477  AddChildNode(tEntityTree, tBodyNode);
478  }
479  /* Get 'body' node */
480  TConfigurationNode& tBodyNode = GetNode(tEntityTree, "body");
481  /* Set the position */
482  SetNodeAttribute(tBodyNode, "position", (*pcPositionGenerator)(bRetry));
483  /* Set the orientation */
484  SetNodeAttribute(tBodyNode, "orientation", (*pcOrientationGenerator)(bRetry));
485  /* Init the entity (this also creates the components, if pcEntity is a composable) */
486  pcEntity->Init(tEntityTree);
487  /* Check whether the entity is indeed embodied */
488  CEmbodiedEntity* pcEmbodiedEntity = GetEmbodiedEntity(pcEntity);
489  if(pcEmbodiedEntity != NULL) {
490  /* Yes, the entity is embodied */
491  /* Add it to the space and to the designated physics engine */
492  CallEntityOperation<CSpaceOperationAddEntity, CSpace, void>(*this, *pcEntity);
493  /* Check if it's colliding with anything else */
494  if(pcEmbodiedEntity->IsCollidingWithSomething()) {
495  /* Set retry to true */
496  bRetry = true;
497  /* Get rid of the entity */
498  CallEntityOperation<CSpaceOperationRemoveEntity, CSpace, void>(*this, *pcEntity);
499  /* Increase the trial count */
500  ++unTrials;
501  /* Too many trials? */
502  if(unTrials > unMaxTrials) {
503  /* Yes, bomb out */
504  THROW_ARGOSEXCEPTION("Exceeded max trials when trying to distribute objects of type " <<
505  tEntityTree.Value() << " with base id \"" <<
506  strBaseId << "\". I managed to place only " << i << " objects.");
507  }
508  /* Retry with a new position */
509  }
510  else {
511  /* No collision, we're done with this entity */
512  bDone = true;
513  }
514  }
515  else {
516  THROW_ARGOSEXCEPTION("Cannot distribute entities that are not positional nor embodied, and \"" << tEntityTree.Value() << "\" is neither.");
517  }
518  }
519  }
520  while(!bDone);
521  }
522  /* Delete the generators, now unneeded */
523  delete pcPositionGenerator;
524  delete pcOrientationGenerator;
525  }
526  catch(CARGoSException& ex) {
527  THROW_ARGOSEXCEPTION_NESTED("Error while trying to distribute entities", ex);
528  }
529  }
530 
531  /****************************************/
532  /****************************************/
533 
534 }
CVector3 m_cArenaCenter
Arena center.
Definition: space.h:422
virtual CVector3 operator()(bool b_is_retry)
Definition: space.cpp:287
void IncreaseSimulationClock(UInt32 un_increase=1)
Increases the simulation clock by the wanted value.
Definition: space.h:342
std::vector< CEntity * > TVector
A vector of entities.
Definition: entity.h:97
An entity that contains a pointer to the user-defined controller.
void AddEntity(ENTITY &c_entity)
Adds an entity of the given type.
Definition: space.h:253
bool MatchPattern(const std::string &str_input, const std::string &str_pattern)
Returns true if str_pattern is matched by str_input.
A 3D vector class.
Definition: vector3.h:29
virtual void RemoveControllableEntity(CControllableEntity &c_entity)
Definition: space.cpp:151
CPhysicsEngine::TVector & GetPhysicsEngines()
Returns the list of currently existing physics engines.
Definition: simulator.h:119
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.
virtual CVector3 operator()(bool b_is_retry)
Definition: space.cpp:234
CMedium::TVector * m_ptMedia
A pointer to the list of media.
Definition: space.h:454
virtual CVector3 operator()(bool b_is_retry)=0
void Distribute(TConfigurationNode &t_tree)
Definition: space.cpp:396
float Real
Collects all ARGoS code.
Definition: datatypes.h:39
CARGoSLog LOG(std::cout, SLogColor(ARGOS_LOG_ATTRIBUTE_BRIGHT, ARGOS_LOG_COLOR_GREEN))
Definition: argos_log.h:179
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
CLoopFunctions & GetLoopFunctions()
Returns a reference to the loop functions associated to the current experiment.
Definition: simulator.h:236
virtual void AddControllableEntity(CControllableEntity &c_entity)
Definition: space.cpp:144
CEntity::TVector m_vecEntities
A vector of entities.
Definition: space.h:431
virtual CVector3 operator()(bool b_is_retry)
Definition: space.cpp:260
Real GetX() const
Returns the x coordinate of this vector.
Definition: vector3.h:93
CRandom::CRNG * GetRNG()
Returns the random generator of the "argos" category.
Definition: simulator.h:210
The basic entity type.
Definition: entity.h:89
TMapPerTypePerId m_mapEntitiesPerTypePerId
A map of maps of all the simulated entities.
Definition: space.h:442
Real GetY() const
Returns the y coordinate of this vector.
Definition: vector3.h:109
TConfigurationNode & GetNode(TConfigurationNode &t_node, const std::string &str_tag)
Given a tree root node, returns the first of its child nodes with the wanted name.
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
virtual ~RealNumberGenerator()
Definition: space.cpp:211
CEntity::TVector m_vecRootEntities
A vector of all the entities without a parent.
Definition: space.h:434
virtual void Destroy()
Destroys the space and all its entities.
Definition: space.cpp:85
This entity is a link to a body in the physics engine.
TMapPerType & GetEntitiesByType(const std::string &str_type)
Returns a map containing all the objects of a given type.
Definition: space.cpp:108
#define THROW_ARGOSEXCEPTION_NESTED(message, nested)
This macro throws an ARGoS exception with the passed message and nesting the passed exception...
CSimulator & m_cSimulator
Definition: space.h:416
CEntity & GetRootEntity()
Returns the root entity containing this entity.
Definition: entity.cpp:115
GridGenerator(const CVector3 c_center, const UInt32 un_layout[], const CVector3 c_distances)
Definition: space.cpp:272
GaussianGenerator(const CVector3 &c_mean, const CVector3 &c_std_dev)
Definition: space.cpp:256
UniformGenerator(const CVector3 &c_min, const CVector3 &c_max)
Definition: space.cpp:230
void GetEntitiesMatching(CEntity::TVector &t_buffer, const std::string &str_pattern)
Returns the entities matching a given pattern.
Definition: space.cpp:95
std::vector< CPhysicsEngine * > TVector
virtual void PostStep()
Executes user-defined logic right after a control step is executed.
CRange< CVector3 > m_cArenaLimits
Arena limits.
Definition: space.h:428
unsigned int UInt32
32-bit unsigned integer.
Definition: datatypes.h:97
CRadians Uniform(const CRange< CRadians > &c_range)
Returns a random value from a uniform distribution.
Definition: rng.cpp:87
void AddChildNode(TConfigurationNode &t_parent_node, TConfigurationNode &t_child_node)
Adds an XML node as child of another XML node.
virtual CVector3 operator()(bool b_is_retry)
Definition: space.cpp:220
static TYPE * New(const std::string &str_label)
Creates a new object of type TYPE
Definition: factory_impl.h:48
void SetX(const Real f_x)
Sets the x coordinate of this vector.
Definition: vector3.h:101
std::map< std::string, CAny, std::less< std::string > > TMapPerType
A map of entities indexed by type description.
Definition: space.h:53
CPhysicsEngine::TVector * m_ptPhysicsEngines
A pointer to the list of physics engines.
Definition: space.h:451
CMedium::TVector & GetMedia()
Returns the list of currently existing media.
Definition: simulator.h:149
bool NodeExists(TConfigurationNode &t_node, const std::string &str_tag)
Given a tree root node, returns true if one of its child nodes has the wanted name.
virtual void Init(TConfigurationNode &t_tree)
Initializes the space using the section of the XML configuration file.
Definition: space.cpp:37
CARGoSLog LOGERR(std::cerr, SLogColor(ARGOS_LOG_ATTRIBUTE_BRIGHT, ARGOS_LOG_COLOR_RED))
Definition: argos_log.h:180
ticpp::Iterator< ticpp::Element > TConfigurationNodeIterator
The iterator for the ARGoS configuration XML node.
std::string ToString(const T &t_value)
Converts the given parameter to a std::string.
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.
void SetNodeAttribute(TConfigurationNode &t_node, const std::string &str_attribute, const T &t_value)
Sets the value of the wanted node's attribute.
virtual void PreStep()
Executes user-defined logic right before a control step is executed.
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
Definition: entity.cpp:40
virtual void UpdateMedia()=0
void SetY(const Real f_y)
Sets the y coordinate of this vector.
Definition: vector3.h:117
virtual bool IsCollidingWithSomething() const
Returns true if this entity is colliding with another object.
CSpace()
Class constructor.
Definition: space.cpp:27
virtual void UpdateControllableEntitiesAct()=0
CVector3 m_cArenaSize
Arena size.
Definition: space.h:425
Real Gaussian(Real f_std_dev, Real f_mean=0.0f)
Returns a random value from a Gaussian distribution.
Definition: rng.cpp:131
CVector3 Position
The position of the anchor wrt the global coordinate system.
Definition: physics_model.h:51
unsigned long long UInt64
64-bit unsigned integer.
Definition: datatypes.h:107
virtual void Update()
Updates the space.
Definition: space.cpp:121
virtual void AddEntityToPhysicsEngine(CEmbodiedEntity &c_entity)
Definition: space.cpp:163
CControllableEntity::TVector m_vecControllableEntities
A vector of controllable entities.
Definition: space.h:445
const std::string & GetId() const
Returns the id of this entity.
Definition: entity.h:157
bool IsMovable() const
Returns true if the entity is movable.
virtual void Reset()
Reset the space and all its entities.
Definition: space.cpp:73
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
Real GetZ() const
Returns the z coordinate of this vector.
Definition: vector3.h:125
void SetZ(const Real f_z)
Sets the z coordinate of this vector.
Definition: vector3.h:133
virtual void UpdatePhysics()=0
The core class of ARGOS.
Definition: simulator.h:62
static CSimulator & GetInstance()
Returns the instance to the CSimulator class.
Definition: simulator.cpp:78
RealNumberGenerator * CreateGenerator(TConfigurationNode &t_tree)
Definition: space.cpp:315
ConstantGenerator(const CVector3 &c_value)
Definition: space.cpp:217
UInt32 m_unSimulationClock
The current simulation clock.
Definition: space.h:419
virtual void UpdateControllableEntitiesSenseStep()=0
const SAnchor & GetOriginAnchor() const
Returns a const reference to the origin anchor associated to this entity.