ARGoS  3
A parallel, multi-engine simulator for swarm robotics
dynamics2d_box_model.cpp
Go to the documentation of this file.
1 
7 #include "dynamics2d_box_model.h"
8 #include "dynamics2d_gripping.h"
9 #include "dynamics2d_engine.h"
10 
11 namespace argos {
12 
13  /****************************************/
14  /****************************************/
15 
17  CBoxEntity& c_entity) :
18  CDynamics2DStretchableObjectModel(c_engine, c_entity) {
19  /* Get the size of the entity */
20  CVector3 cHalfSize = c_entity.GetSize() * 0.5f;
21  /* Create a polygonal object in the physics space */
22  /* Start defining the vertices
23  NOTE: points must be defined in a clockwise winding
24  */
25  cpVect tVertices[] = {
26  cpv(-cHalfSize.GetX(), -cHalfSize.GetY()),
27  cpv(-cHalfSize.GetX(), cHalfSize.GetY()),
28  cpv( cHalfSize.GetX(), cHalfSize.GetY()),
29  cpv( cHalfSize.GetX(), -cHalfSize.GetY())
30  };
31  const CVector3& cPosition = GetEmbodiedEntity().GetOriginAnchor().Position;
32  CRadians cXAngle, cYAngle, cZAngle;
33  GetEmbodiedEntity().GetOriginAnchor().Orientation.ToEulerAngles(cZAngle, cYAngle, cXAngle);
34  /*
35  * Create body and shapes
36  */
37  cpBody* ptBody;
38  if(GetEmbodiedEntity().IsMovable()) {
39  /* The box is movable */
40  SetMass(c_entity.GetMass());
41  /* Create the body */
42  ptBody =
43  cpSpaceAddBody(GetDynamics2DEngine().GetPhysicsSpace(),
44  cpBodyNew(GetMass(),
45  cpMomentForPoly(GetMass(),
46  4,
47  tVertices,
48  cpvzero)));
49  ptBody->p = cpv(cPosition.GetX(), cPosition.GetY());
50  cpBodySetAngle(ptBody, cZAngle.GetValue());
51  /* Create the shape */
52  cpShape* ptShape =
53  cpSpaceAddShape(GetDynamics2DEngine().GetPhysicsSpace(),
54  cpPolyShapeNew(ptBody,
55  4,
56  tVertices,
57  cpvzero));
58  ptShape->e = 0.0; // no elasticity
59  ptShape->u = 0.7; // lots contact friction to help pushing
60  /* The shape is grippable */
62  ptShape));
63  /* Set the body so that the default methods work as expected */
64  SetBody(ptBody, c_entity.GetSize().GetZ());
65  /* Friction with ground */
66  SetLinearFriction(0.0f, 1.49f);
67  SetAngularFriction(0.0f, 1.49f);
68  }
69  else {
70  /* The box is not movable */
71  /* Create a static body */
72  ptBody = cpBodyNewStatic();
73  ptBody->p = cpv(cPosition.GetX(), cPosition.GetY());
74  cpBodySetAngle(ptBody, cZAngle.GetValue());
75  /* Create the shape */
76  cpShape* ptShape =
77  cpSpaceAddShape(GetDynamics2DEngine().GetPhysicsSpace(),
78  cpPolyShapeNew(ptBody,
79  4,
80  tVertices,
81  cpvzero));
82  ptShape->e = 0.0; // No elasticity
83  ptShape->u = 0.1; // Little contact friction to help sliding away
84  /* This shape is normal (not grippable, not gripper) */
85  ptShape->collision_type = CDynamics2DEngine::SHAPE_NORMAL;
86  /* Set the body so that the default methods work as expected */
87  SetBody(ptBody, c_entity.GetSize().GetZ());
88  }
89  }
90 
91  /****************************************/
92  /****************************************/
93 
95 
96  /****************************************/
97  /****************************************/
98 
99 }
argos::CEmbodiedEntity::GetOriginAnchor
const SAnchor & GetOriginAnchor() const
Returns a const reference to the origin anchor associated to this entity.
Definition: embodied_entity.h:119
argos::SAnchor::Orientation
CQuaternion Orientation
The orientation of the anchor wrt the global coordinate system.
Definition: physics_model.h:53
argos::CVector3::GetZ
Real GetZ() const
Returns the z coordinate of this vector.
Definition: vector3.h:125
argos::CDynamics2DStretchableObjectModel
A stretchable and grippable object model for the dynamics 2D engine.
Definition: dynamics2d_stretchable_object_model.h:32
dynamics2d_box_model.h
argos
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
argos::CVector3
A 3D vector class.
Definition: vector3.h:29
argos::CDynamics2DModel::GetDynamics2DEngine
CDynamics2DEngine & GetDynamics2DEngine()
Returns the dynamics 2D engine state.
Definition: dynamics2d_model.h:48
argos::CRadians
It defines the basic type CRadians, used to store an angle value in radians.
Definition: angles.h:42
argos::CDynamics2DStretchableObjectModel::SetGrippable
void SetGrippable(CDynamics2DGrippable *pc_grippable)
Definition: dynamics2d_stretchable_object_model.h:56
argos::CDynamics2DGrippable
Definition: dynamics2d_gripping.h:84
argos::CBoxEntity::GetMass
Real GetMass() const
Definition: box_entity.h:88
argos::CBoxEntity
Definition: box_entity.h:20
argos::CDynamics2DEngine::SHAPE_NORMAL
@ SHAPE_NORMAL
Definition: dynamics2d_engine.h:47
argos::CDynamics2DEngine
Definition: dynamics2d_engine.h:42
argos::REGISTER_STANDARD_DYNAMICS2D_OPERATIONS_ON_ENTITY
REGISTER_STANDARD_DYNAMICS2D_OPERATIONS_ON_ENTITY(CEPuckEntity, CDynamics2DEPuckModel)
argos::CVector3::GetX
Real GetX() const
Returns the x coordinate of this vector.
Definition: vector3.h:93
argos::CDynamics2DStretchableObjectModel::SetAngularFriction
void SetAngularFriction(Real f_max_bias, Real f_max_force)
Sets the angular friction of this object.
Definition: dynamics2d_stretchable_object_model.cpp:73
argos::CRadians::GetValue
Real GetValue() const
Returns the value in radians.
Definition: angles.h:111
argos::CQuaternion::ToEulerAngles
void ToEulerAngles(CRadians &c_z_angle, CRadians &c_y_angle, CRadians &c_x_angle) const
Definition: quaternion.h:171
argos::CDynamics2DStretchableObjectModel::SetLinearFriction
void SetLinearFriction(Real f_max_bias, Real f_max_force)
Sets the linear friction of this object.
Definition: dynamics2d_stretchable_object_model.cpp:58
dynamics2d_gripping.h
dynamics2d_engine.h
argos::CDynamics2DBoxModel
Definition: dynamics2d_box_model.h:20
argos::CDynamics2DSingleBodyObjectModel::SetBody
virtual void SetBody(cpBody *pt_body, Real f_height)
Sets the body and registers the default origin anchor method.
Definition: dynamics2d_single_body_object_model.cpp:132
argos::CDynamics2DStretchableObjectModel::SetMass
void SetMass(Real f_mass)
Definition: dynamics2d_stretchable_object_model.h:52
argos::CVector3::GetY
Real GetY() const
Returns the y coordinate of this vector.
Definition: vector3.h:109
argos::CDynamics2DBoxModel::CDynamics2DBoxModel
CDynamics2DBoxModel(CDynamics2DEngine &c_engine, CBoxEntity &c_entity)
Definition: dynamics2d_box_model.cpp:16
argos::CBoxEntity::GetSize
const CVector3 & GetSize() const
Definition: box_entity.h:80
argos::CDynamics2DStretchableObjectModel::GetMass
Real GetMass() const
Definition: dynamics2d_stretchable_object_model.h:48
argos::SAnchor::Position
CVector3 Position
The position of the anchor wrt the global coordinate system.
Definition: physics_model.h:51
argos::CPhysicsModel::GetEmbodiedEntity
CEmbodiedEntity & GetEmbodiedEntity()
Returns the embodied entity associated to this physics model.
Definition: physics_model.h:133