9 #include "VsMovableItem.h"
12 #include "VsMotorizedJoint.h"
13 #include "VsRigidBody.h"
14 #include "VsSimulator.h"
17 #include "VsDragger.h"
21 namespace ExternalStimuli
34 m_fltVelocityReport = 0;
35 m_bDisableMotorWhenDone =
false;
38 m_iTargetID = DESIRED_VELOCITY_TYPE;
53 if(m_lpEval)
delete m_lpEval;
56 {
Std_TraceMsg(0,
"Caught Error in desctructor of VsMotorVelocityStimulus\r\n",
"", -1,
false,
true);}
67 void VsMotorVelocityStimulus::VelocityEquation(std::string strVal)
71 {
delete m_lpEval; m_lpEval = NULL;}
73 m_strVelocityEquation = strVal;
74 m_lpEval =
new CStdPostFixEval;
76 m_lpEval->AddVariable(
"t");
77 m_lpEval->AddVariable(
"p");
78 m_lpEval->AddVariable(
"v");
79 m_lpEval->Equation(m_strVelocityEquation);
82 void VsMotorVelocityStimulus::TargetID(
int iID)
84 if(iID == DESIRED_VELOCITY_TYPE || iID == DESIRED_POSITION_TYPE)
87 THROW_PARAM_ERROR(Al_Err_lInvalidTargetID, Al_Err_strInvalidTargetID,
"ID", iID);
90 void VsMotorVelocityStimulus::TargetID(std::string strID)
94 if(strId ==
"VELOCITY")
95 m_iTargetID = DESIRED_VELOCITY_TYPE;
96 else if(strId ==
"POSITION")
97 m_iTargetID = DESIRED_POSITION_TYPE;
99 THROW_PARAM_ERROR(Al_Err_lInvalidTargetID, Al_Err_strInvalidTargetID,
"ID", strID);
104 ExternalStimulus::ResetSimulation();
107 m_fltVelocityReport = 0;
112 ExternalStimulus::Initialize();
115 m_lpJoint =
dynamic_cast<MotorizedJoint *
>(
m_lpSim->
FindJoint(m_strStructureID, m_strJointID));
117 THROW_PARAM_ERROR(Al_Err_lJointNotMotorized, Al_Err_strJointNotMotorized,
"ID", m_strJointID);
119 m_lpPosition = m_lpJoint->GetDataPointer(
"JOINTPOSITION");
120 m_lpVelocity = m_lpJoint->GetDataPointer(
"JOINTACTUALVELOCITY");
125 ExternalStimulus::Activate();
129 m_lpJoint->EnableMotor(
true);
131 if(m_iTargetID == DESIRED_VELOCITY_TYPE)
132 m_lpJoint->DesiredVelocity(0);
154 m_lpEval->SetVariable(
"p", *m_lpPosition);
157 m_lpEval->SetVariable(
"v", *m_lpVelocity);
159 m_fltVelocityReport = m_fltVelocity = m_lpEval->Solve();
162 if(!m_lpJoint->UsesRadians())
165 if(m_iTargetID == DESIRED_VELOCITY_TYPE)
166 m_lpJoint->DesiredVelocity(m_fltVelocity);
167 else if(m_iTargetID == DESIRED_POSITION_TYPE)
168 m_lpJoint->DesiredPosition(m_fltVelocity);
174 LOG_ERROR(
"Error Occurred while setting Joint Velocity");
181 ExternalStimulus::Deactivate();
185 if(m_iTargetID == DESIRED_VELOCITY_TYPE)
186 m_lpJoint->DesiredVelocity(0);
188 if(m_bDisableMotorWhenDone)
189 m_lpJoint->EnableMotor(
false);
198 if(strType ==
"VELOCITY" || strType ==
"VALUE")
199 lpData = &m_fltVelocityReport;
201 THROW_TEXT_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType,
"StimulusName: " + STR(
m_strName) +
" DataType: " + strDataType);
210 if(ExternalStimulus::SetData(strDataType, strValue,
false))
213 if(strType ==
"VELOCITY" || strType ==
"EQUATION")
215 VelocityEquation(strValue);
219 if(strType ==
"DISABLEWHENDONE")
225 if(strType ==
"TARGETID")
233 THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType,
"Data Type", strDataType);
238 void VsMotorVelocityStimulus::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
240 ExternalStimulus::QueryProperties(aryProperties);
242 aryProperties.Add(
new TypeProperty(
"Velocity", AnimatPropertyType::Float, AnimatPropertyDirection::Both));
243 aryProperties.Add(
new TypeProperty(
"Equation", AnimatPropertyType::String, AnimatPropertyDirection::Set));
244 aryProperties.Add(
new TypeProperty(
"DisableMotorWhenDone", AnimatPropertyType::Boolean, AnimatPropertyDirection::Set));
245 aryProperties.Add(
new TypeProperty(
"TargetID", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
248 void VsMotorVelocityStimulus::Load(CStdXml &oXml)
250 ActivatedItem::Load(oXml);
254 m_strStructureID = oXml.GetChildString(
"StructureID");
256 THROW_ERROR(Al_Err_lIDBlank, Al_Err_strIDBlank);
258 m_strJointID = oXml.GetChildString(
"JointID");
260 THROW_ERROR(Al_Err_lIDBlank, Al_Err_strIDBlank);
262 if(oXml.FindChildElement(
"Velocity",
false))
263 VelocityEquation(oXml.GetChildString(
"Velocity"));
265 VelocityEquation(oXml.GetChildString(
"Equation"));
267 DisableMotorWhenDone(oXml.GetChildBool(
"DisableMotorWhenDone", m_bDisableMotorWhenDone));
268 TargetID(oXml.GetChildString(
"TargetID",
"Velocity"));
VsMotorVelocityStimulus()
Default constructor.
virtual void Deactivate()
Deactivates this item.
virtual void StepSimulation()
Step the simulation for this object.
virtual ~VsMotorVelocityStimulus()
Destructor.
Simulator * m_lpSim
The pointer to a Simulation.
virtual short PhysicsStepInterval()
Gets the physics step interval.
virtual void ResetSimulation()
Resets the simulation back to time 0.
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
virtual void Activate()
Activates this item.
virtual long PhysicsStepCount()
Gets the physics step count.
virtual Joint * FindJoint(std::string strStructureID, std::string strJointID, bool bThrowError=true)
Finds a joint with the specified ID in the specified structure.
Declares the vs motor velocity stimulus class.
virtual float * GetDataPointer(const std::string &strDataType)
Returns a float pointer to a data item of interest in this object.
bool Std_ToBool(int iVal)
Converts a value toa bool.
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
void Std_TraceMsg(const int iLevel, std::string strMessage, std::string strSourceFile, int iSourceLine, bool bLogToFile, bool bPrintHeader)
Traces a message to the debugger window.
bool m_bEnabled
Tells if this item is enabled or not. If it is not enabled then it is not run.
bool Std_IsBlank(std::string strVal)
Trims a string and tests if a string is blank.
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
virtual float InverseDistanceUnits()
Gets the inverse distance units.
virtual float Time()
Gets the current simulation time in seconds.
virtual void Initialize()
Initializes this object.
std::string m_strName
The name for this object.