dynamics2d_cylinder_model.cpp
Go to the documentation of this file.
1 
8 #include "dynamics2d_gripping.h"
9 #include "dynamics2d_engine.h"
10 
11 namespace argos {
12 
13  /****************************************/
14  /****************************************/
15 
17  CCylinderEntity& c_entity) :
18  CDynamics2DStretchableObjectModel(c_engine, c_entity) {
19  /* Get the radius of the entity */
20  Real fRadius = c_entity.GetRadius();
21  /* Create a circle object in the physics space */
22  const CVector3& cPosition = GetEmbodiedEntity().GetOriginAnchor().Position;
23  CRadians cXAngle, cYAngle, cZAngle;
24  GetEmbodiedEntity().GetOriginAnchor().Orientation.ToEulerAngles(cZAngle, cYAngle, cXAngle);
25  /*
26  * Create body and shapes
27  */
28  cpBody* ptBody;
29  if(GetEmbodiedEntity().IsMovable()) {
30  /* The cylinder is movable */
31  SetMass(c_entity.GetMass());
32  /* Create the body */
33  ptBody = cpSpaceAddBody(GetDynamics2DEngine().GetPhysicsSpace(),
34  cpBodyNew(GetMass(),
35  cpMomentForCircle(GetMass(),
36  0,
37  fRadius + fRadius,
38  cpvzero)));
39  ptBody->p = cpv(cPosition.GetX(), cPosition.GetY());
40  cpBodySetAngle(ptBody, cZAngle.GetValue());
41  /* Create the shape */
42  cpShape* ptShape = cpSpaceAddShape(GetDynamics2DEngine().GetPhysicsSpace(),
43  cpCircleShapeNew(ptBody, fRadius, cpvzero));
44  ptShape->e = 0.0; // no elasticity
45  ptShape->u = 0.7; // lots contact friction to help pushing
46  /* The shape is grippable */
48  ptShape));
49  /* Set the body so that the default methods work as expected */
50  SetBody(ptBody, c_entity.GetHeight());
51  /* Friction with ground */
54  }
55  else {
56  /* The cylinder is not movable */
57  /* Create a static body */
58  ptBody = cpBodyNewStatic();
59  ptBody->p = cpv(cPosition.GetX(), cPosition.GetY());
60  cpBodySetAngle(ptBody, cZAngle.GetValue());
61  /* Create the shape */
62  cpShape* ptShape = cpSpaceAddShape(
63  GetDynamics2DEngine().GetPhysicsSpace(),
64  cpCircleShapeNew(ptBody,
65  fRadius,
66  cpvzero));
67  ptShape->e = 0.0; // No elasticity
68  ptShape->u = 0.1; // Little contact friction to help sliding away
69  /* This shape is normal (not grippable, not gripper) */
70  ptShape->collision_type = CDynamics2DEngine::SHAPE_NORMAL;
71  /* Set the body so that the default methods work as expected */
72  SetBody(ptBody, c_entity.GetHeight());
73  }
74  }
75 
76  /****************************************/
77  /****************************************/
78 
79  void CDynamics2DCylinderModel::Resize(Real f_radius, Real f_height) {
80  /* Remove existing shape */
81  cpSpaceRemoveShape(GetDynamics2DEngine().GetPhysicsSpace(),
82  GetBody()->shapeList);
83  /* Create the shape */
84  cpShape* ptShape = cpSpaceAddShape(GetDynamics2DEngine().GetPhysicsSpace(),
85  cpCircleShapeNew(GetBody(), f_radius, cpvzero));
86  if(GetEmbodiedEntity().IsMovable()) {
87  /* The box is movable */
88  ptShape->e = 0.0; // no elasticity
89  ptShape->u = 0.7; // lots contact friction to help pushing
90  /* The shape is grippable */
92  delete GetGrippable();
94  ptShape));
95  }
96  else {
97  /* The box is not movable */
98  ptShape->e = 0.0; // No elasticity
99  ptShape->u = 0.1; // Little contact friction to help sliding away
100  /* This shape is normal (not grippable, not gripper) */
101  ptShape->collision_type = CDynamics2DEngine::SHAPE_NORMAL;
102  }
103  /* Set the body so that the default methods work as expected */
104  SetBody(GetBody(), f_height);
105  }
106 
107  /****************************************/
108  /****************************************/
109 
111 
112  /****************************************/
113  /****************************************/
114 
115 }
float Real
Collects all ARGoS code.
Definition: datatypes.h:39
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
REGISTER_STANDARD_DYNAMICS2D_OPERATIONS_ON_ENTITY(CEPuckEntity, CDynamics2DEPuckModel)
const SAnchor & GetOriginAnchor() const
Returns a const reference to the origin anchor associated to this entity.
CQuaternion Orientation
The orientation of the anchor wrt the global coordinate system.
Definition: physics_model.h:53
CVector3 Position
The position of the anchor wrt the global coordinate system.
Definition: physics_model.h:51
CEmbodiedEntity & GetEmbodiedEntity()
Returns the embodied entity associated to this physics model.
It defines the basic type CRadians, used to store an angle value in radians.
Definition: angles.h:42
Real GetValue() const
Returns the value in radians.
Definition: angles.h:111
void ToEulerAngles(CRadians &c_z_angle, CRadians &c_y_angle, CRadians &c_x_angle) const
Definition: quaternion.h:172
A 3D vector class.
Definition: vector3.h:31
Real GetX() const
Returns the x coordinate of this vector.
Definition: vector3.h:105
Real GetY() const
Returns the y coordinate of this vector.
Definition: vector3.h:121
CDynamics2DCylinderModel(CDynamics2DEngine &c_engine, CCylinderEntity &c_entity)
void Resize(Real f_radius, Real f_height)
cpFloat GetCylinderLinearFriction() const
cpFloat GetCylinderAngularFriction() const
CDynamics2DEngine & GetDynamics2DEngine()
Returns the dynamics 2D engine state.
cpBody * GetBody()
Returns the body as non-const pointer.
virtual void SetBody(cpBody *pt_body, Real f_height)
Sets the body and registers the default origin anchor method.
A stretchable and grippable object model for the dynamics 2D engine.
void SetLinearFriction(Real f_max_bias, Real f_max_force)
Sets the linear friction of this object.
void SetGrippable(CDynamics2DGrippable *pc_grippable)
void SetAngularFriction(Real f_max_bias, Real f_max_force)
Sets the angular friction of this object.