ARGoS
3
A parallel, multi-engine simulator for swarm robotics
|
Go to the documentation of this file.
11 #include <argos3/core/simulator/simulator.h>
12 #include <argos3/core/simulator/entity/embodied_entity.h>
22 m_fStaticHashCellSize(0.1f),
23 m_fActiveHashCellSize(2.0f * 0.085036758f),
24 m_nStaticHashCells(1000),
25 m_nActiveHashCells(1000),
51 cpResetShapeIdCounter();
53 m_ptGroundBody = cpBodyNew(INFINITY, INFINITY);
55 m_ptSpace = cpSpaceNew();
67 cpSpaceAddCollisionHandler(
86 for(CDynamics2DModel::TMap::iterator it = m_tPhysicsModels.begin();
87 it != m_tPhysicsModels.end(); ++it) {
90 cpSpaceReindexStatic(m_ptSpace);
98 for(CDynamics2DModel::TMap::iterator it = m_tPhysicsModels.begin();
99 it != m_tPhysicsModels.end(); ++it) {
100 it->second->UpdateFromEntityStatus();
107 for(CDynamics2DModel::TMap::iterator it = m_tPhysicsModels.begin();
108 it != m_tPhysicsModels.end(); ++it) {
109 it->second->UpdateEntityStatus();
118 for(CDynamics2DModel::TMap::iterator it = m_tPhysicsModels.begin();
119 it != m_tPhysicsModels.end(); ++it) {
122 m_tPhysicsModels.clear();
124 cpSpaceFree(m_ptSpace);
125 cpBodyFree(m_ptGroundBody);
132 return m_tPhysicsModels.size();
140 CallEntityOperation<CDynamics2DOperationAddEntity, CDynamics2DEngine, SOperationOutcome>
142 cpResetShapeIdCounter();
143 return cOutcome.
Value;
151 CallEntityOperation<CDynamics2DOperationRemoveEntity, CDynamics2DEngine, SOperationOutcome>
153 return cOutcome.
Value;
164 const CRay3& c_ray) :
169 static void Dynamics2DSegmentQueryFunc(cpShape* pt_shape, cpFloat f_t, cpVect,
void* pt_data) {
171 SDynamics2DSegmentHitData& sData = *
reinterpret_cast<SDynamics2DSegmentHitData*
>(pt_data);
173 CDynamics2DModel& cModel = *
reinterpret_cast<CDynamics2DModel*
>(pt_shape->body->data);
174 CVector3 cIntersectionPoint;
175 sData.Ray.GetPoint(cIntersectionPoint, f_t);
176 if((cIntersectionPoint.GetZ() >= cModel.GetBoundingBox().MinCorner.GetZ()) &&
177 (cIntersectionPoint.GetZ() <= cModel.GetBoundingBox().MaxCorner.GetZ()) ) {
179 sData.Intersections.push_back(
180 SEmbodiedEntityIntersectionItem(
181 &cModel.GetEmbodiedEntity(),
187 const CRay3& c_ray)
const {
196 Dynamics2DSegmentQueryFunc,
205 const cpBody* pt_body) {
206 c_new_pos.
SetX(pt_body->p.x);
207 c_new_pos.
SetY(pt_body->p.y);
208 c_new_pos.
SetZ(c_original_pos.
GetZ());
224 m_tPhysicsModels[str_id] = &c_model;
231 CDynamics2DModel::TMap::iterator it = m_tPhysicsModels.find(str_id);
232 if(it != m_tPhysicsModels.end()) {
234 m_tPhysicsModels.erase(it);
246 "Carlo Pinciroli [ilpincy@gmail.com]",
248 "A 2D dynamics physics engine.",
249 "This physics engine is a 2D dynamics engine based on the Chipmunk library\n"
250 "(http://code.google.com/p/chipmunk-physics).\n\n"
251 "REQUIRED XML CONFIGURATION\n\n"
252 " <physics_engines>\n"
254 " <dynamics2d id=\"dyn2d\" />\n"
256 " </physics_engines>\n\n"
257 "The 'id' attribute is necessary and must be unique among the physics engines.\n"
258 "It is used in the subsequent section <arena_physics> to assign entities to\n"
259 "physics engines. If two engines share the same id, initialization aborts.\n\n"
260 "OPTIONAL XML CONFIGURATION\n\n"
261 "The plane of the physics engine can be translated on the Z axis, to simulate\n"
262 "for example hovering objects, such as flying robots. To translate the plane\n"
263 "2m up the Z axis, use the 'elevation' attribute as follows:\n\n"
264 " <physics_engines>\n"
266 " <dynamics2d id=\"dyn2d\"\n"
267 " elevation=\"2.0\" />\n"
269 " </physics_engines>\n\n"
270 "When not specified, the elevation is zero, which means that the plane\n"
271 "corresponds to the XY plane.\n",
Real GetZ() const
Returns the z coordinate of this vector.
const std::string & GetId() const
Returns the id of this physics engine.
void SetX(const Real f_x)
Sets the x coordinate of this vector.
The namespace containing all the ARGoS related code.
It defines the basic type CRadians, used to store an angle value in radians.
The exception that wraps all errors in ARGoS.
int ManageCollisionBetweenGripperAndGrippable(cpArbiter *pt_arb, cpSpace *pt_space, void *p_data)
virtual void Init(TConfigurationNode &t_tree)
Initializes the resource.
UInt32 GetIterations() const
Returns the number of iterations per simulation clock tick.
virtual size_t GetNumPhysicsModels()
static const CVector3 Z
The z axis.
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
CQuaternion & FromAngleAxis(const CRadians &c_angle, const CVector3 &c_vector)
Real GetX() const
Returns the x coordinate of this vector.
void AddPhysicsModel(const std::string &str_id, CDynamics2DModel &c_model)
int BeginCollisionBetweenGripperAndGrippable(cpArbiter *pt_arb, cpSpace *pt_space, void *p_data)
void SetZ(const Real f_z)
Sets the z coordinate of this vector.
void OrientationPhysicsToSpace(CQuaternion &c_new_orient, cpBody *pt_body)
#define THROW_ARGOSEXCEPTION_NESTED(message, nested)
This macro throws an ARGoS exception with the passed message and nesting the passed exception.
virtual bool AddEntity(CEntity &c_entity)
Adds an entity to the physics engine.
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
void RemovePhysicsModel(const std::string &str_id)
Real GetPhysicsClockTick() const
Returns the length of the physics engine tick.
SVolume & GetVolume()
Returns the boundary faces for the volume associated to this engine.
The base class for models in the dynamics 2D engine.
virtual void CheckIntersectionWithRay(TEmbodiedEntityIntersectionData &t_data, const CRay3 &c_ray) const
Check which objects in this engine intersect the given ray.
void PositionPhysicsToSpace(CVector3 &c_new_pos, const CVector3 &c_original_pos, const cpBody *pt_body)
SHorizontalFace * TopFace
SHorizontalFace * BottomFace
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 void Destroy()
Undoes whatever was done by Init().
virtual void Init(TConfigurationNode &t_tree)
Initializes the resource.
A boundary face for top/bottom parts of the volume.
Type to use as return value for operation outcome.
SDynamics2DSegmentHitData(TEmbodiedEntityIntersectionData &t_data, const CRay3 &c_ray)
Real GetY() const
Returns the y coordinate of this vector.
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).\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" "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", "Under development")
std::vector< SEmbodiedEntityIntersectionItem > TEmbodiedEntityIntersectionData
virtual void Reset()
Resets the resource.
virtual bool RemoveEntity(CEntity &c_entity)
Removes an entity from the physics engine.
TEmbodiedEntityIntersectionData & Intersections
void SetY(const Real f_y)
Sets the y coordinate of this vector.