ARGoS 3
A parallel, multi-engine simulator for swarm robotics
dynamics3d_epuck_model.cpp
Go to the documentation of this file.
1
8
9#include <argos3/plugins/simulator/physics_engines/dynamics3d/dynamics3d_engine.h>
10#include <argos3/plugins/simulator/physics_engines/dynamics3d/dynamics3d_shape_manager.h>
11
12#include <argos3/plugins/simulator/entities/wheeled_entity.h>
13#include <argos3/plugins/robots/e-puck/simulator/epuck_entity.h>
14
15namespace argos {
16
17 /****************************************/
18 /****************************************/
19
21 CEPuckEntity& c_epuck) :
22 /* technically, the CDynamics3DMultiBodyObjectModel should be initialized with 7 children
23 links, however, setting it to 7 makes the epuck less stable for reasons. */
24 CDynamics3DMultiBodyObjectModel(c_engine, c_epuck, 3, false),
25 m_cWheeledEntity(c_epuck.GetWheeledEntity()) {
26 /* get the required collision shapes */
27 std::shared_ptr<btCollisionShape> ptrBodyShape =
29 std::shared_ptr<btCollisionShape> ptrWheelShape =
31 /* calculate the inertia of the collision objects */
32 btVector3 cBodyInertia;
33 btVector3 cWheelInertia;
34 ptrBodyShape->calculateLocalInertia(m_fBodyMass, cBodyInertia);
35 ptrWheelShape->calculateLocalInertia(m_fWheelMass, cWheelInertia);
36 /* calculate a btTransform that moves us from the global coordinate system to the
37 local coordinate system */
38 const SAnchor& sOriginAnchor = c_epuck.GetEmbodiedEntity().GetOriginAnchor();
39 const CQuaternion& cOrientation = sOriginAnchor.Orientation;
40 const CVector3& cPosition = sOriginAnchor.Position;
41 const btTransform& cStartTransform = btTransform(
42 btQuaternion(cOrientation.GetX(),
43 cOrientation.GetZ(),
44 -cOrientation.GetY(),
45 cOrientation.GetW()),
46 btVector3(cPosition.GetX(),
47 cPosition.GetZ(),
48 -cPosition.GetY()));
49 /* create a CAbstractBody::SData structure for each body */
50 CAbstractBody::SData sBodyData(
51 cStartTransform * m_cBodyOffset,
52 m_cBodyGeometricOffset,
53 cBodyInertia,
54 m_fBodyMass,
55 GetEngine().GetDefaultFriction());
56 CAbstractBody::SData sLeftWheelData(
57 cStartTransform * m_cLeftWheelOffset,
58 m_cWheelGeometricOffset,
59 cWheelInertia,
60 m_fWheelMass,
61 m_fWheelFriction);
62 CAbstractBody::SData sRightWheelData(
63 cStartTransform * m_cRightWheelOffset,
64 m_cWheelGeometricOffset,
65 cWheelInertia,
66 m_fWheelMass,
67 m_fWheelFriction);
68 /* create an anchor for the body (not strictly necessary but easier than
69 overloading CDynamics3DMultiBodyObjectModel::UpdateOriginAnchor) */
70 SAnchor* psBodyAnchor = &c_epuck.GetEmbodiedEntity().AddAnchor("body", {0.0, 0.0, 0.00125});
71 /* create the bodies */
72 m_ptrBody = std::make_shared<CBase>(*this, psBodyAnchor, ptrBodyShape, sBodyData);
73 m_ptrLeftWheel = std::make_shared<CLink>(*this, 0, nullptr, ptrWheelShape, sLeftWheelData);
74 m_ptrRightWheel = std::make_shared<CLink>(*this, 1, nullptr, ptrWheelShape, sRightWheelData);
75 /* copy the bodies to the base class */
76 m_vecBodies = {m_ptrBody, m_ptrLeftWheel, m_ptrRightWheel};
77 /* synchronize with the entity with the space */
78 Reset();
79 }
80
81 /****************************************/
82 /****************************************/
83
85 /* reset the base class */
87 /* set up wheels */
88 m_cMultiBody.setupRevolute(m_ptrLeftWheel->GetIndex(),
89 m_ptrLeftWheel->GetData().Mass,
90 m_ptrLeftWheel->GetData().Inertia,
91 m_ptrBody->GetIndex(),
92 m_cBodyToLeftWheelJointRotation,
93 btVector3(0.0, 1.0, 0.0),
94 m_cBodyToLeftWheelJointOffset,
95 m_cLeftWheelToBodyJointOffset,
96 true);
97 m_cMultiBody.setupRevolute(m_ptrRightWheel->GetIndex(),
98 m_ptrRightWheel->GetData().Mass,
99 m_ptrRightWheel->GetData().Inertia,
100 m_ptrBody->GetIndex(),
101 m_cBodyToRightWheelJointRotation,
102 btVector3(0.0, 1.0, 0.0),
103 m_cBodyToRightWheelJointOffset,
104 m_cRightWheelToBodyJointOffset,
105 true);
106 /* set up motors for the wheels */
107 m_ptrLeftMotor =
108 std::unique_ptr<btMultiBodyJointMotor>(
109 new btMultiBodyJointMotor(&m_cMultiBody,
110 m_ptrLeftWheel->GetIndex(),
111 0.0,
112 m_fWheelMotorMaxImpulse));
113 m_ptrRightMotor =
114 std::unique_ptr<btMultiBodyJointMotor>(
115 new btMultiBodyJointMotor(&m_cMultiBody,
116 m_ptrRightWheel->GetIndex(),
117 0.0,
118 m_fWheelMotorMaxImpulse));
119 /* Allocate memory and prepare the btMultiBody */
120 m_cMultiBody.finalizeMultiDof();
121 /* Synchronize with the entity in the space */
123 }
124
125 /****************************************/
126 /****************************************/
127
129 btVector3 cModelAabbMin, cModelAabbMax;
130 /* Initialize the bounding box with the base's AABB */
131 m_ptrBody->GetShape().getAabb(m_ptrBody->GetTransform(), cModelAabbMin, cModelAabbMax);
132 /* Write back the bounding box swapping the coordinate systems and the Y component */
133 GetBoundingBox().MinCorner.Set(cModelAabbMin.getX(), -cModelAabbMax.getZ(), cModelAabbMin.getY());
134 GetBoundingBox().MaxCorner.Set(cModelAabbMax.getX(), -cModelAabbMin.getZ(), cModelAabbMax.getY());
135 }
136
137 /****************************************/
138 /****************************************/
139
141 /* run the base class's implementation of this method */
143 }
144
145 /****************************************/
146 /****************************************/
147
149 /* run the base class's implementation of this method */
151 /* update joint velocities */
152 m_ptrLeftMotor->setVelocityTarget(m_cWheeledEntity.GetWheelVelocities()[0]);
153 m_ptrRightMotor->setVelocityTarget(m_cWheeledEntity.GetWheelVelocities()[1]);
154 }
155
156 /****************************************/
157 /****************************************/
158
159 void CDynamics3DEPuckModel::AddToWorld(btMultiBodyDynamicsWorld& c_world) {
160 /* run the base class's implementation of this method */
162 /* add the actuators (btMultiBodyJointMotors) constraints to the world */
163 c_world.addMultiBodyConstraint(m_ptrLeftMotor.get());
164 c_world.addMultiBodyConstraint(m_ptrRightMotor.get());
165 }
166
167 /****************************************/
168 /****************************************/
169
170 void CDynamics3DEPuckModel::RemoveFromWorld(btMultiBodyDynamicsWorld& c_world) {
171 /* remove the actuators (btMultiBodyJointMotors) constraints from the world */
172 c_world.removeMultiBodyConstraint(m_ptrRightMotor.get());
173 c_world.removeMultiBodyConstraint(m_ptrLeftMotor.get());
174 /* run the base class's implementation of this method */
176 }
177
178 /****************************************/
179 /****************************************/
180
182
183 /****************************************/
184 /****************************************/
185
186 const btVector3 CDynamics3DEPuckModel::m_cBodyHalfExtents(0.0362, 0.0236, 0.0362);
187 const btScalar CDynamics3DEPuckModel::m_fBodyMass(0.242);
188 const btTransform CDynamics3DEPuckModel::m_cBodyOffset(btQuaternion(0.0, 0.0, 0.0, 1.0), btVector3(0.0,0.00125,0.0));
189 const btTransform CDynamics3DEPuckModel::m_cBodyGeometricOffset(btQuaternion(0.0, 0.0, 0.0, 1.0), btVector3(0.0, -0.0236, 0.0));
190 const btVector3 CDynamics3DEPuckModel::m_cWheelHalfExtents(0.02125,0.0015,0.02125);
191 const btScalar CDynamics3DEPuckModel::m_fWheelMass(0.006);
192 const btTransform CDynamics3DEPuckModel::m_cWheelGeometricOffset(btQuaternion(0.0, 0.0, 0.0, 1.0), btVector3(0.0,-0.0015,0.0));
193 const btTransform CDynamics3DEPuckModel::m_cLeftWheelOffset(btQuaternion(btVector3(-1,0,0), SIMD_HALF_PI), btVector3(0.0, 0.02125, -0.0255));
194 const btTransform CDynamics3DEPuckModel::m_cRightWheelOffset(btQuaternion(btVector3(1,0,0), SIMD_HALF_PI), btVector3(0.0, 0.02125, 0.0255));
195 const btVector3 CDynamics3DEPuckModel::m_cBodyToRightWheelJointOffset(0.0, -0.0036, 0.0255);
196 const btVector3 CDynamics3DEPuckModel::m_cRightWheelToBodyJointOffset(0.0, 0.0015, 0.0);
197 const btQuaternion CDynamics3DEPuckModel::m_cBodyToRightWheelJointRotation(btVector3(-1,0,0), SIMD_HALF_PI);
198 const btVector3 CDynamics3DEPuckModel::m_cBodyToLeftWheelJointOffset(0.0, -0.0036, -0.0255);
199 const btVector3 CDynamics3DEPuckModel::m_cLeftWheelToBodyJointOffset(0.0, 0.0015, -0.0);
200 const btQuaternion CDynamics3DEPuckModel::m_cBodyToLeftWheelJointRotation(btVector3(1,0,0), SIMD_HALF_PI);
201 /* TODO calibrate these values */
202 const btScalar CDynamics3DEPuckModel::m_fWheelMotorMaxImpulse(0.15);
203 const btScalar CDynamics3DEPuckModel::m_fWheelFriction(5.0);
204
205 /****************************************/
206 /****************************************/
207
208}
#define REGISTER_STANDARD_DYNAMICS3D_OPERATIONS_ON_ENTITY(SPACE_ENTITY, DYN3D_ENTITY)
The namespace containing all the ARGoS related code.
Definition ci_actuator.h:12
const SAnchor & GetOriginAnchor() const
Returns a const reference to the origin anchor associated to this entity.
SAnchor & AddAnchor(const std::string &str_id, const CVector3 &c_rel_position=CVector3(), const CQuaternion &c_rel_orientation=CQuaternion())
Adds an anchor to the embodied entity.
An anchor related to the body of an entity.
CQuaternion Orientation
The orientation of the anchor wrt the global coordinate system.
CVector3 Position
The position of the anchor wrt the global coordinate system.
virtual void UpdateFromEntityStatus()=0
Updates the state of this model from the status of the associated entity.
const SBoundingBox & GetBoundingBox() const
Returns an axis-aligned box that contains the physics model.
virtual void UpdateEntityStatus()
Updates the status of the associated entity.
Real GetW() const
Definition quaternion.h:49
Real GetX() const
Definition quaternion.h:53
Real GetZ() const
Definition quaternion.h:61
Real GetY() const
Definition quaternion.h:57
A 3D vector class.
Definition vector3.h:31
Real GetX() const
Returns the x coordinate of this vector.
Definition vector3.h:105
void Set(const Real f_x, const Real f_y, const Real f_z)
Sets the vector contents from Cartesian coordinates.
Definition vector3.h:155
Real GetY() const
Returns the y coordinate of this vector.
Definition vector3.h:121
Real GetZ() const
Returns the z coordinate of this vector.
Definition vector3.h:137
virtual void AddToWorld(btMultiBodyDynamicsWorld &c_world)
CDynamics3DEPuckModel(CDynamics3DEngine &c_engine, CEPuckEntity &c_epuck)
virtual void UpdateEntityStatus()
Updates the status of the associated entity.
virtual void UpdateFromEntityStatus()
Updates the state of this model from the status of the associated entity.
virtual void CalculateBoundingBox()
Calculates the axis-aligned box that contains the entire physics model.
virtual void RemoveFromWorld(btMultiBodyDynamicsWorld &c_world)
CEmbodiedEntity & GetEmbodiedEntity()
const Real * GetWheelVelocities() const
std::vector< std::shared_ptr< CAbstractBody > > m_vecBodies
CDynamics3DEngine & GetEngine()
virtual void RemoveFromWorld(btMultiBodyDynamicsWorld &c_world)
virtual void AddToWorld(btMultiBodyDynamicsWorld &c_world)
static std::shared_ptr< btCollisionShape > RequestCylinder(const btVector3 &c_half_extents)