8 #include "RbMovableItem.h"
11 #include "RbMotorizedJoint.h"
12 #include "RbRigidBody.h"
13 #include "RbSimulator.h"
20 RbMotorizedJoint::RbMotorizedJoint()
22 m_lpThisMotorJoint = NULL;
24 m_bJointLocked =
false;
25 m_fltPredictedPos = 0;
26 m_fltNextPredictedPos = 0;
29 RbMotorizedJoint::~RbMotorizedJoint()
33 void RbMotorizedJoint::SetThisPointers()
35 RbJoint::SetThisPointers();
37 m_lpThisMotorJoint =
dynamic_cast<MotorizedJoint *
>(
this);
38 if(!m_lpThisMotorJoint)
39 THROW_TEXT_ERROR(Rb_Err_lThisPointerNotDefined, Rb_Err_strThisPointerNotDefined,
"m_lpThisMotorJoint, " + m_lpThisAB->Name());
41 m_lpThisMotorJoint->PhysicsMotorJoint(
this);
46 void RbMotorizedJoint::CalculateServoVelocity()
48 float fltTargetPos = m_lpThisJoint->GetPositionWithinLimits(m_lpThisMotorJoint->DesiredVelocity());
49 float fltError = fltTargetPos - m_lpThisJoint->JointPosition();
51 if(m_lpThisJoint->EnableLimits())
53 float fltProp = fltError / m_lpThisJoint->GetLimitRange();
54 m_lpThisMotorJoint->DesiredVelocity(fltProp * m_lpThisMotorJoint->ServoGain());
57 m_lpThisMotorJoint->DesiredVelocity(fltError * m_lpThisMotorJoint->MaxVelocity());
60 void RbMotorizedJoint::Physics_SetVelocityToDesired()
67 if(m_lpThisMotorJoint->EnableMotor())
69 if(m_lpThisMotorJoint->MotorType() == eJointMotorType::PositionControl)
71 m_lpThisMotorJoint->SetPosition(m_lpThisMotorJoint->DesiredPosition());
72 m_lpThisMotorJoint->DesiredVelocity(0);
73 m_lpThisMotorJoint->DesiredPosition(0);
77 float fltSetPos = m_lpThisMotorJoint->DesiredPosition();
78 float fltSetVel = m_lpThisMotorJoint->DesiredVelocity();
80 if(m_lpThisMotorJoint->MotorType() == eJointMotorType::PositionVelocityControl)
81 m_lpThisMotorJoint->SetPosition(fltSetPos);
83 m_lpThisMotorJoint->SetVelocity(fltSetVel);
84 m_lpThisMotorJoint->DesiredVelocity(0);
85 m_lpThisMotorJoint->DesiredPosition(0);
87 m_lpThisMotorJoint->PrevVelocity(fltSetVel);
92 void RbMotorizedJoint::Physics_ResetSimulation()
94 m_fltPredictedPos = 0;
95 m_fltNextPredictedPos = 0;
98 void RbMotorizedJoint::Physics_CollectExtraData()
Classes for implementing the cm-labs vortex physics engine for AnimatLab.