9#include <argos3/core/utility/logging/argos_log.h>
10#include <argos3/core/utility/configuration/argos_configuration.h>
41 for(
auto it = m_tPhysicsModels.begin();
42 it != m_tPhysicsModels.end(); ++it) {
52 for(
auto it = m_tPhysicsModels.begin();
53 it != m_tPhysicsModels.end(); ++it) {
56 m_tPhysicsModels.clear();
64 for(
auto it = m_tPhysicsModels.begin();
65 it != m_tPhysicsModels.end(); ++it) {
66 it->second->UpdateFromEntityStatus();
70 for(
auto it = m_tPhysicsModels.begin();
71 it != m_tPhysicsModels.end(); ++it) {
72 it->second->UpdatePhysics();
75 for(
auto it = m_tPhysicsModels.begin();
76 it != m_tPhysicsModels.end(); ++it) {
80 for(
auto it = m_tPhysicsModels.begin();
81 it != m_tPhysicsModels.end(); ++it) {
82 it->second->UpdateEntityStatus();
90 return m_tPhysicsModels.size();
100 return cOutcome.
Value;
110 return cOutcome.
Value;
137 const CRay3& c_ray)
const {
139 for(
auto it = m_tPhysicsModels.begin();
140 it != m_tPhysicsModels.end();
142 if(it->second->CheckIntersectionWithRay(fTOnRay, c_ray)) {
145 &it->second->GetEmbodiedEntity(),
156 m_tPhysicsModels[str_id] = &c_model;
163 auto it = m_tPhysicsModels.find(str_id);
164 if(it != m_tPhysicsModels.end()) {
166 m_tPhysicsModels.erase(it);
169 THROW_ARGOSEXCEPTION(
"PointMass3D model id \"" << str_id <<
"\" not found in point-mass 3D engine \"" <<
GetId() <<
"\"");
178 "Carlo Pinciroli [ilpincy@gmail.com]",
180 "A 3D point-mass physics engine.",
182 "This physics engine is a 3D point-mass engine.\n\n"
184 "REQUIRED XML CONFIGURATION\n\n"
185 " <physics_engines>\n"
187 " <pointmass3d id=\"pm3d\" />\n"
189 " </physics_engines>\n\n"
191 "The 'id' attribute is necessary and must be unique among the physics engines.\n"
192 "If two engines share the same id, initialization aborts.\n\n"
194 "OPTIONAL XML CONFIGURATION\n\n"
196 "By default, there will -9.81 m/s gravity in the simulation. This can be\n"
197 "changed by specifying the 'gravity' attribute:\n\n"
199 " <physics_engines>\n"
201 " <pointmass3d id=\"pm3d\" gravity=\"-9.81\"/>\n"
203 " </physics_engines>\n\n"
205 "Multiple physics engines can also be used. If multiple physics engines are used,\n"
206 "the disjoint union of the 3D volumes within the arena assigned to each engine must cover\n"
207 "the entire arena without overlapping. If the entire arena is not covered, robots can\n"
208 "\"escape\" the configured physics engines and cause a fatal exception (this is not an\n"
209 "issue when a single physics engine is used, because the engine covers the entire arena\n"
210 "by default). To use multiple physics engines, use the following syntax (all attributes\n"
211 "are mandatory):\n\n"
213 " <physics_engines>\n"
215 " <pointmass3d id=\"pm0\">\n"
217 " <top height=\"1.0\"/>\n"
218 " <botton height=\"0.0\"/>\n"
220 " <vertex point=\"0.0, 0.0\"/>\n"
221 " <vertex point=\"4.0, 0.0\"/>\n"
222 " <vertex point=\"4.0, 4.0\"/>\n"
223 " <vertex point=\"0.0, 4.0\"/>\n"
227 " <pointmass3d id=\"pm1\">\n"
231 " </physics_engines>\n\n"
233 "A physics engine can be defined having any number of sides >= 3, as long as the\n"
234 "sides from a closed polygon in the 2D plane (vertices must be declared in the\n"
235 "XML file in counter-clockwise order). In the above example, the physics engine\n"
236 "'pm0' is assigned to the area within the arena with lower left coordinates (0,0)\n"
237 "and upper right coordinates (4,4) and vertices are specified in counter\n"
238 "clockwise order: LL, LR, UR, UL.\n\n"
240 "OPTIMIZATION HINTS\n\n"
242 "1. A single physics engine is generally sufficient for small swarms (say <= 50\n"
243 " robots) within a reasonably small arena to obtain faster than real-time\n"
244 " performance with optimized code. For larger swarms and/or large arenas multiple\n"
245 " engines should be used for maximum performance.\n\n"
247 "2. In general, using the same number of ARGoS threads as physics engines gives\n"
248 " maximum performance (1-thread per engine per CPU core).\n\n"
250 "3. Using multiple engines in simulations with any of the following characteristics\n"
251 " generally incurs more overhead due to thread context switching than the\n"
252 " performance benefits from multiple engines:\n\n"
256 " - Less available ARGoS threads than assigned physics engines\n"
257 " - Less available CPU cores than assigned ARGoS threads\n\n"
260 "4. A good starting strategy for physics engine boundary assignment is to assign\n"
261 " each physics engine the same amount of area within the arena. This will be\n"
262 " sufficient for most cases. Depending on the nature of the simulation, using\n"
263 " non-homogeneous physics engine sizes may yield increased performance. An example\n"
264 " would be a narrow hallway between larger open areas in the arena--the hallway\n"
265 " will likely experience increased robot density and assigning more physics\n"
266 " engines to that area than the relatively unpopulated open areas may increase\n"
float Real
Collects all ARGoS code.
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
#define REGISTER_PHYSICS_ENGINE(CLASSNAME, LABEL, AUTHOR, VERSION, BRIEF_DESCRIPTION, LONG_DESCRIPTION, STATUS)
The namespace containing all the ARGoS related code.
RETURN_VALUE CallEntityOperation(PLUGIN &t_plugin, CEntity &c_entity)
Calls the operation corresponding to the given context and operand Skips the function call if the ope...
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.
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
std::vector< SEmbodiedEntityIntersectionItem > TEmbodiedEntityIntersectionData
Type to use as return value for operation outcome.
virtual void Init(TConfigurationNode &t_tree)
Initializes the resource.
const std::string & GetId() const
Returns the id of this physics engine.
UInt32 GetIterations() const
Returns the number of iterations per simulation clock tick.
virtual void CheckIntersectionWithRay(TEmbodiedEntityIntersectionData &t_data, const CRay3 &c_ray) const
Check which objects in this engine intersect the given ray.
virtual bool AddEntity(CEntity &c_entity)
Adds an entity to the physics engine.
virtual bool RemoveEntity(CEntity &c_entity)
Removes an entity from the physics engine.
virtual void Destroy()
Undoes whatever was done by Init().
virtual bool IsPointContained(const CVector3 &c_point)
Returns true if the given point is contained in this physics engine.
virtual bool IsEntityTransferNeeded() const
virtual ~CPointMass3DEngine()
virtual size_t GetNumPhysicsModels()
void AddPhysicsModel(const std::string &str_id, CPointMass3DModel &c_model)
virtual void TransferEntities()
Executes the transfer of entities to other engines.
virtual void Reset()
Resets the resource.
virtual void Init(TConfigurationNode &t_tree)
Initializes the resource.
void RemovePhysicsModel(const std::string &str_id)