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

pointmass3d_engine.cpp
Go to the documentation of this file.
1 
7 #include "pointmass3d_engine.h"
8 #include "pointmass3d_model.h"
9 #include <argos3/core/utility/logging/argos_log.h>
10 #include <argos3/core/utility/configuration/argos_configuration.h>
11 
12 namespace argos {
13 
14  /****************************************/
15  /****************************************/
16 
18  m_fGravity(-9.81f) {
19  }
20 
21  /****************************************/
22  /****************************************/
23 
25  }
26 
27  /****************************************/
28  /****************************************/
29 
31  /* Init parent */
32  CPhysicsEngine::Init(t_tree);
33  /* Set gravity */
34  GetNodeAttributeOrDefault(t_tree, "gravity", m_fGravity, m_fGravity);
35  }
36 
37  /****************************************/
38  /****************************************/
39 
41  for(CPointMass3DModel::TMap::iterator it = m_tPhysicsModels.begin();
42  it != m_tPhysicsModels.end(); ++it) {
43  it->second->Reset();
44  }
45  }
46 
47  /****************************************/
48  /****************************************/
49 
51  /* Empty the physics entity map */
52  for(CPointMass3DModel::TMap::iterator it = m_tPhysicsModels.begin();
53  it != m_tPhysicsModels.end(); ++it) {
54  delete it->second;
55  }
56  m_tPhysicsModels.clear();
57  }
58 
59  /****************************************/
60  /****************************************/
61 
63  /* Update the physics state from the entities */
64  for(CPointMass3DModel::TMap::iterator it = m_tPhysicsModels.begin();
65  it != m_tPhysicsModels.end(); ++it) {
66  it->second->UpdateFromEntityStatus();
67  }
68  for(size_t i = 0; i < GetIterations(); ++i) {
69  /* Perform the step */
70  for(CPointMass3DModel::TMap::iterator it = m_tPhysicsModels.begin();
71  it != m_tPhysicsModels.end(); ++it) {
72  it->second->Step();
73  }
74  }
75  /* Update the simulated space */
76  for(CPointMass3DModel::TMap::iterator it = m_tPhysicsModels.begin();
77  it != m_tPhysicsModels.end(); ++it) {
78  it->second->UpdateEntityStatus();
79  }
80  }
81 
82  /****************************************/
83  /****************************************/
84 
86  return m_tPhysicsModels.size();
87  }
88 
89  /****************************************/
90  /****************************************/
91 
93  SOperationOutcome cOutcome =
94  CallEntityOperation<CPointMass3DOperationAddEntity, CPointMass3DEngine, SOperationOutcome>
95  (*this, c_entity);
96  return cOutcome.Value;
97  }
98 
99  /****************************************/
100  /****************************************/
101 
103  SOperationOutcome cOutcome =
104  CallEntityOperation<CPointMass3DOperationRemoveEntity, CPointMass3DEngine, SOperationOutcome>
105  (*this, c_entity);
106  return cOutcome.Value;
107  }
108 
109  /****************************************/
110  /****************************************/
111 
113  return true;
114  }
115 
116  /****************************************/
117  /****************************************/
118 
120  return false;
121  }
122 
123  /****************************************/
124  /****************************************/
125 
127  }
128 
129  /****************************************/
130  /****************************************/
131 
133  const CRay3& c_ray) const {
134  Real fTOnRay;
135  for(CPointMass3DModel::TMap::const_iterator it = m_tPhysicsModels.begin();
136  it != m_tPhysicsModels.end();
137  ++it) {
138  if(it->second->CheckIntersectionWithRay(fTOnRay, c_ray)) {
139  t_data.push_back(
141  &it->second->GetEmbodiedEntity(),
142  fTOnRay));
143  }
144  }
145  }
146 
147  /****************************************/
148  /****************************************/
149 
150  void CPointMass3DEngine::AddPhysicsModel(const std::string& str_id,
151  CPointMass3DModel& c_model) {
152  m_tPhysicsModels[str_id] = &c_model;
153  }
154 
155  /****************************************/
156  /****************************************/
157 
158  void CPointMass3DEngine::RemovePhysicsModel(const std::string& str_id) {
159  CPointMass3DModel::TMap::iterator it = m_tPhysicsModels.find(str_id);
160  if(it != m_tPhysicsModels.end()) {
161  delete it->second;
162  m_tPhysicsModels.erase(it);
163  }
164  else {
165  THROW_ARGOSEXCEPTION("PointMass3D model id \"" << str_id << "\" not found in point-mass 3D engine \"" << GetId() << "\"");
166  }
167  }
168 
169  /****************************************/
170  /****************************************/
171 
173  "pointmass3d",
174  "Carlo Pinciroli [ilpincy@gmail.com]",
175  "1.0",
176  "A 3D point-mass physics engine.",
177  "This physics engine is a 3D point-mass engine.\n\n"
178  "REQUIRED XML CONFIGURATION\n\n"
179  " <physics_engines>\n"
180  " ...\n"
181  " <pointmass3d id=\"pm3d\" />\n"
182  " ...\n"
183  " </physics_engines>\n\n"
184  "The 'id' attribute is necessary and must be unique among the physics engines.\n"
185  "If two engines share the same id, initialization aborts.\n\n"
186  "OPTIONAL XML CONFIGURATION\n\n"
187  "None for the time being.\n\n"
188  ,
189  "Under development"
190  );
191 
192 }
void AddPhysicsModel(const std::string &str_id, CPointMass3DModel &c_model)
A 3D vector class.
Definition: vector3.h:29
virtual bool RemoveEntity(CEntity &c_entity)
Removes an entity from the physics engine.
virtual void CheckIntersectionWithRay(TEmbodiedEntityIntersectionData &t_data, const CRay3 &c_ray) const
Check which objects in this engine intersect the given ray.
virtual void Destroy()
Undoes whatever was done by Init().
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.
float Real
Collects all ARGoS code.
Definition: datatypes.h:39
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
virtual void TransferEntities()
Executes the transfer of entities to other engines.
The basic entity type.
Definition: entity.h:89
virtual void Init(TConfigurationNode &t_tree)
Initializes the resource.
virtual size_t GetNumPhysicsModels()
REGISTER_PHYSICS_ENGINE(CDynamics2DEngine,"dynamics2d","Carlo Pinciroli [ilpincy@gmail.com]","1.0","A 2D dynamics physics engine.","This physics engine is a 2D dynamics engine based on the Chipmunk library\n""(http://code.google.com/p/chipmunk-physics) version 6.0.1.\n\n""REQUIRED XML CONFIGURATION\n\n"" <physics_engines>\n"" ...\n"" <dynamics2d id=\"dyn2d\" />\n"" ...\n"" </physics_engines>\n\n""The 'id' attribute is necessary and must be unique among the physics engines.\n""It is used in the subsequent section <arena_physics> to assign entities to\n""physics engines. If two engines share the same id, initialization aborts.\n\n""OPTIONAL XML CONFIGURATION\n\n""It is possible to set how many iterations this physics engine performs between\n""each simulation step. By default, this physics engine performs 10 steps every\n""two simulation steps. This means that, if the simulation step is 100ms, the\n""physics engine step is, by default, 10ms. Sometimes, collisions and joints are\n""not simulated with sufficient precision using these parameters. By increasing\n""the number of iterations, the temporal granularity of the solver increases and\n""with it its accuracy, at the cost of higher computational cost. To change the\n""number of iterations per simulation step use this syntax:\n\n"" <physics_engines>\n"" ...\n"" <dynamics2d id=\"dyn2d\"\n"" iterations=\"20\" />\n"" ...\n"" </physics_engines>\n\n""The plane of the physics engine can be translated on the Z axis, to simulate\n""for example hovering objects, such as flying robots. To translate the plane\n""2m up the Z axis, use the 'elevation' attribute as follows:\n\n"" <physics_engines>\n"" ...\n"" <dynamics2d id=\"dyn2d\"\n"" elevation=\"2.0\" />\n"" ...\n"" </physics_engines>\n\n""When not specified, the elevation is zero, which means that the plane\n""corresponds to the XY plane.\n\n""The friction parameters between the ground and movable boxes and cylinders can\n""be overridden. You can set both the linear and angular friction parameters.\n""The default value is 1.49 for each of them. To override the values, use this\n""syntax (all attributes are optional):\n\n"" <physics_engines>\n"" ...\n"" <dynamics2d id=\"dyn2d\"\n"" <friction box_linear_friction=\"1.0\"\n"" box_angular_friction=\"2.0\"\n"" cylinder_linear_friction=\"3.0\"\n"" cylinder_angular_friction=\"4.0\" />\n"" </dynamics2d>\n"" ...\n"" </physics_engines>\n\n""For the the robots that use velocity-based control, such as ground robots with\n""the differential_steering actuator (e.g. the foot-bot and the e-puck), it is\n""possible to customize robot-specific attributes that set the maximum force and\n""torque the robot has. The syntax is as follows, taking a foot-bot as example:\n\n"" <arena ...>\n"" ...\n"" <foot-bot id=\"fb0\">\n"" <body position=\"0.4,2.3,0.25\" orientation=\"45,0,0\" />\n"" <controller config=\"mycntrl\" />\n"" <!-- Specify new value for max_force and max_torque -->\n"" <dynamics2d>\n"" <differential_steering max_force=\"0.1\" max_torque=\"0.1\"/>\n"" </dynamics2d>\n"" </foot-bot>\n"" ...\n"" </arena>\n\n""The attributes 'max_force' and 'max_torque' are both optional, and they take the\n""robot-specific default if not set. Check the code of the dynamics2d model of the\n""robot you're using to know the default values.\n\n""By default, this engine uses the bounding-box tree method for collision shape\n""indexing. This method is the default in Chipmunk and it works well most of the\n""times. However, if you are running simulations with hundreds or thousands of\n""identical robots, a different shape collision indexing is available: the spatial\n""hash. The spatial hash is a grid stored in a hashmap. To get the max out of this\n""indexing method, you must set two parameters: the cell size and the suggested\n""minimum number of cells in the space. According to the documentation of\n""Chipmunk, the cell size should correspond to the size of the bounding box of the\n""most common object in the simulation; the minimum number of cells should be at\n""least 10x the number of objects managed by the physics engine. To use this\n""indexing method, use this syntax (all attributes are mandatory):\n\n"" <physics_engines>\n"" ...\n"" <dynamics2d id=\"dyn2d\"\n"" <spatial_hash cell_size=\"1.0\"\n"" cell_num=\"2.0\" />\n"" </dynamics2d>\n"" ...\n"" </physics_engines>\n","Usable")
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
Type to use as return value for operation outcome.
Definition: entity.h:352
const std::string & GetId() const
Returns the id of this physics engine.
virtual bool IsPointContained(const CVector3 &c_point)
Returns true if the given point is contained in this physics engine.
std::vector< SEmbodiedEntityIntersectionItem > TEmbodiedEntityIntersectionData
virtual bool AddEntity(CEntity &c_entity)
Adds an entity to the physics engine.
virtual void Reset()
Resets the resource.
virtual bool IsEntityTransferNeeded() const
UInt32 GetIterations() const
Returns the number of iterations per simulation clock tick.
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
virtual void Init(TConfigurationNode &t_tree)
Initializes the resource.
void RemovePhysicsModel(const std::string &str_id)