9 #include <argos3/plugins/simulator/physics_engines/dynamics3d/dynamics3d_engine.h>
10 #include <argos3/plugins/simulator/physics_engines/dynamics3d/dynamics3d_shape_manager.h>
12 #include <argos3/plugins/simulator/entities/wheeled_entity.h>
13 #include <argos3/plugins/robots/e-puck/simulator/epuck_entity.h>
25 m_cWheeledEntity(c_epuck.GetWheeledEntity()) {
27 std::shared_ptr<btCollisionShape> ptrBodyShape =
29 std::shared_ptr<btCollisionShape> ptrWheelShape =
32 btVector3 cBodyInertia;
33 btVector3 cWheelInertia;
34 ptrBodyShape->calculateLocalInertia(m_fBodyMass, cBodyInertia);
35 ptrWheelShape->calculateLocalInertia(m_fWheelMass, cWheelInertia);
41 const btTransform& cStartTransform = btTransform(
42 btQuaternion(cOrientation.
GetX(),
46 btVector3(cPosition.
GetX(),
50 CAbstractBody::SData sBodyData(
51 cStartTransform * m_cBodyOffset,
52 m_cBodyGeometricOffset,
56 CAbstractBody::SData sLeftWheelData(
57 cStartTransform * m_cLeftWheelOffset,
58 m_cWheelGeometricOffset,
62 CAbstractBody::SData sRightWheelData(
63 cStartTransform * m_cRightWheelOffset,
64 m_cWheelGeometricOffset,
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);
76 m_vecBodies = {m_ptrBody, m_ptrLeftWheel, m_ptrRightWheel};
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,
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,
108 std::unique_ptr<btMultiBodyJointMotor>(
110 m_ptrLeftWheel->GetIndex(),
112 m_fWheelMotorMaxImpulse));
114 std::unique_ptr<btMultiBodyJointMotor>(
116 m_ptrRightWheel->GetIndex(),
118 m_fWheelMotorMaxImpulse));
129 btVector3 cModelAabbMin, cModelAabbMax;
131 m_ptrBody->GetShape().getAabb(m_ptrBody->GetTransform(), cModelAabbMin, cModelAabbMax);
163 c_world.addMultiBodyConstraint(m_ptrLeftMotor.get());
164 c_world.addMultiBodyConstraint(m_ptrRightMotor.get());
172 c_world.removeMultiBodyConstraint(m_ptrRightMotor.get());
173 c_world.removeMultiBodyConstraint(m_ptrLeftMotor.get());
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);
202 const btScalar CDynamics3DEPuckModel::m_fWheelMotorMaxImpulse(0.15);
203 const btScalar CDynamics3DEPuckModel::m_fWheelFriction(5.0);
The namespace containing all the ARGoS related code.
REGISTER_STANDARD_DYNAMICS3D_OPERATIONS_ON_ENTITY(CEPuckEntity, CDynamics3DEPuckModel)
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.
const SBoundingBox & GetBoundingBox() const
Returns an axis-aligned box that contains the physics model.
Real GetX() const
Returns the x coordinate of this vector.
void Set(const Real f_x, const Real f_y, const Real f_z)
Sets the vector contents from Cartesian coordinates.
Real GetY() const
Returns the y coordinate of this vector.
Real GetZ() const
Returns the z coordinate of this vector.
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
virtual void UpdateFromEntityStatus()
Updates the state of this model from the status of the associated entity.
virtual void UpdateEntityStatus()
Updates the status of the associated entity.
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)