7 #include "VsMovableItem.h"
10 #include "VsMotorizedJoint.h"
11 #include "VsRigidBody.h"
12 #include "VsSimulator.h"
14 #include "VsForceStimulus.h"
15 #include "VsDragger.h"
19 namespace ExternalStimuli
26 VsForceStimulus::VsForceStimulus()
32 m_lpForceXEval = NULL;
33 m_lpForceYEval = NULL;
34 m_lpForceZEval = NULL;
40 m_fltForceReportX = 0;
41 m_fltForceReportY = 0;
42 m_fltForceReportZ = 0;
44 m_lpTorqueXEval = NULL;
45 m_lpTorqueYEval = NULL;
46 m_lpTorqueZEval = NULL;
52 m_fltTorqueReportX = 0;
53 m_fltTorqueReportY = 0;
54 m_fltTorqueReportZ = 0;
57 VsForceStimulus::~VsForceStimulus()
66 if(m_lpForceXEval)
delete m_lpForceXEval;
67 if(m_lpForceYEval)
delete m_lpForceYEval;
68 if(m_lpForceZEval)
delete m_lpForceZEval;
70 if(m_lpTorqueXEval)
delete m_lpTorqueXEval;
71 if(m_lpTorqueYEval)
delete m_lpTorqueYEval;
72 if(m_lpTorqueZEval)
delete m_lpTorqueZEval;
75 {
Std_TraceMsg(0,
"Caught Error in desctructor of VsForceStimulus\r\n",
"", -1,
false,
true);}
78 CStdPostFixEval *VsForceStimulus::SetupEquation(std::string strEquation)
80 CStdPostFixEval *lpEquation = NULL;
84 lpEquation =
new CStdPostFixEval;
85 lpEquation->AddVariable(
"t");
86 lpEquation->Equation(strEquation);
93 void VsForceStimulus::RelativePositionX(
float fltVal)
96 m_oRelativePosition.x = fltVal * m_lpSim->InverseDistanceUnits();
99 void VsForceStimulus::RelativePositionY(
float fltVal)
102 m_oRelativePosition.y = fltVal * m_lpSim->InverseDistanceUnits();
105 void VsForceStimulus::RelativePositionZ(
float fltVal)
108 m_oRelativePosition.z = fltVal * m_lpSim->InverseDistanceUnits();
111 void VsForceStimulus::ForceXEquation(std::string strVal)
114 {
delete m_lpForceXEval; m_lpForceXEval = NULL;}
116 m_strForceXEquation = strVal;
117 m_lpForceXEval = SetupEquation(strVal);
120 void VsForceStimulus::ForceYEquation(std::string strVal)
123 {
delete m_lpForceYEval; m_lpForceYEval = NULL;}
125 m_strForceYEquation = strVal;
126 m_lpForceYEval = SetupEquation(strVal);
129 void VsForceStimulus::ForceZEquation(std::string strVal)
132 {
delete m_lpForceZEval; m_lpForceZEval = NULL;}
134 m_strForceZEquation = strVal;
135 m_lpForceZEval = SetupEquation(strVal);
138 void VsForceStimulus::TorqueXEquation(std::string strVal)
141 {
delete m_lpTorqueXEval; m_lpTorqueXEval = NULL;}
143 m_strTorqueXEquation = strVal;
144 m_lpTorqueXEval = SetupEquation(strVal);
147 void VsForceStimulus::TorqueYEquation(std::string strVal)
150 {
delete m_lpTorqueYEval; m_lpTorqueYEval = NULL;}
152 m_strTorqueYEquation = strVal;
153 m_lpTorqueYEval = SetupEquation(strVal);
156 void VsForceStimulus::TorqueZEquation(std::string strVal)
159 {
delete m_lpTorqueZEval; m_lpTorqueZEval = NULL;}
161 m_strTorqueZEquation = strVal;
162 m_lpTorqueZEval = SetupEquation(strVal);
167 ExternalStimulus::Initialize();
170 m_lpStructure = m_lpSim->FindStructureFromAll(m_strStructureID);
171 m_lpBody = m_lpStructure->FindRigidBody(m_strBodyID);
172 m_lpVsBody =
dynamic_cast<VsRigidBody *
>(m_lpBody);
177 ExternalStimulus::ResetSimulation();
179 m_fltForceX = m_fltForceY = m_fltForceZ = 0;
180 m_fltForceReportX = m_fltForceReportY = m_fltForceReportZ = 0;
181 m_fltTorqueX = m_fltTorqueY = m_fltTorqueZ = 0;
182 m_fltTorqueReportX = m_fltTorqueReportY = m_fltTorqueReportZ = 0;
193 if(m_lpSim->PhysicsStepCount() == m_lpSim->PhysicsStepInterval())
203 if(m_lpForceXEval || m_lpForceYEval || m_lpForceZEval)
205 m_fltForceX = m_fltForceY = m_fltForceZ = 0;
206 m_fltForceReportX = m_fltForceReportY = m_fltForceReportZ = 0;
210 m_lpForceXEval->SetVariable(
"t", m_lpSim->Time());
211 m_fltForceReportX = m_lpForceXEval->Solve();
212 m_fltForceX = m_fltForceReportX * m_lpSim->InverseMassUnits() * m_lpSim->InverseDistanceUnits();
217 m_lpForceYEval->SetVariable(
"t", m_lpSim->Time());
218 m_fltForceReportY = m_lpForceYEval->Solve();
219 m_fltForceY = m_fltForceReportY * m_lpSim->InverseMassUnits() * m_lpSim->InverseDistanceUnits();
224 m_lpForceZEval->SetVariable(
"t", m_lpSim->Time());
225 m_fltForceReportZ = m_lpForceZEval->Solve();
226 m_fltForceZ = m_fltForceReportZ * m_lpSim->InverseMassUnits() * m_lpSim->InverseDistanceUnits();
229 fltF[0] = m_fltForceX; fltF[1] = m_fltForceY; fltF[2] = m_fltForceZ;
230 fltP[0] = m_oRelativePosition.x; fltP[1] = m_oRelativePosition.y; fltP[2] = m_oRelativePosition.z;
232 if(m_lpVsBody->Part() && (m_fltForceX || m_fltForceY || m_fltForceZ))
233 m_lpVsBody->Part()->addForceAtLocalPosition(fltF, fltP);
236 if(m_lpTorqueXEval || m_lpTorqueYEval || m_lpTorqueZEval)
238 m_fltTorqueX = m_fltTorqueY = m_fltTorqueZ = 0;
239 m_fltTorqueReportX = m_fltTorqueReportY = m_fltTorqueReportZ = 0;
243 m_lpTorqueXEval->SetVariable(
"t", m_lpSim->Time());
244 m_fltTorqueReportX = m_lpTorqueXEval->Solve();
245 m_fltTorqueX = m_fltTorqueReportX * m_lpSim->InverseMassUnits() * m_lpSim->InverseDistanceUnits() * m_lpSim->InverseDistanceUnits();
250 m_lpTorqueYEval->SetVariable(
"t", m_lpSim->Time());
251 m_fltTorqueReportY = m_lpTorqueYEval->Solve();
252 m_fltTorqueY = m_fltTorqueReportY * m_lpSim->InverseMassUnits() * m_lpSim->InverseDistanceUnits() * m_lpSim->InverseDistanceUnits();
257 m_lpTorqueZEval->SetVariable(
"t", m_lpSim->Time());
258 m_fltTorqueReportZ = m_lpTorqueZEval->Solve();
259 m_fltTorqueZ = m_fltTorqueReportZ * m_lpSim->InverseMassUnits() * m_lpSim->InverseDistanceUnits() * m_lpSim->InverseDistanceUnits();
262 fltF[0] = m_fltTorqueX; fltF[1] = m_fltTorqueY; fltF[2] = m_fltTorqueZ;
264 if(m_lpVsBody->Part() && (m_fltTorqueX || m_fltTorqueY || m_fltTorqueZ))
265 m_lpVsBody->Part()->addTorque (fltF);
271 LOG_ERROR(
"Error Occurred while setting Joint Velocity");
278 if(m_lpVsBody->Part())
279 m_lpVsBody->Part()->wakeDynamics();
287 if(strType ==
"FORCEX")
288 lpData = &m_fltForceReportX;
289 else if(strType ==
"FORCEY")
290 lpData = &m_fltForceReportY;
291 else if(strType ==
"FORCEZ")
292 lpData = &m_fltForceReportZ;
293 else if(strType ==
"TORQUEX")
294 lpData = &m_fltTorqueReportX;
295 else if(strType ==
"TORQUEY")
296 lpData = &m_fltTorqueReportY;
297 else if(strType ==
"TORQUEZ")
298 lpData = &m_fltTorqueReportZ;
300 THROW_TEXT_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType,
"StimulusName: " + STR(
m_strName) +
" DataType: " + strDataType);
309 if(ExternalStimulus::SetData(strDataType, strValue,
false))
312 if(strType ==
"POSITIONX")
314 RelativePositionX(atof(strValue.c_str()));
318 if(strType ==
"POSITIONY")
320 RelativePositionY(atof(strValue.c_str()));
324 if(strType ==
"POSITIONZ")
326 RelativePositionZ(atof(strValue.c_str()));
330 if(strType ==
"FORCEX")
332 ForceXEquation(strValue);
336 if(strType ==
"FORCEY")
338 ForceYEquation(strValue);
342 if(strType ==
"FORCEZ")
344 ForceZEquation(strValue);
348 if(strType ==
"TORQUEX")
350 TorqueXEquation(strValue);
354 if(strType ==
"TORQUEY")
356 TorqueYEquation(strValue);
360 if(strType ==
"TORQUEZ")
362 TorqueZEquation(strValue);
368 THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType,
"Data Type", strDataType);
373 void VsForceStimulus::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
375 ExternalStimulus::QueryProperties(aryProperties);
377 aryProperties.Add(
new TypeProperty(
"PositionX", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
378 aryProperties.Add(
new TypeProperty(
"PositionY", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
379 aryProperties.Add(
new TypeProperty(
"PositionZ", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
380 aryProperties.Add(
new TypeProperty(
"ForceX", AnimatPropertyType::Float, AnimatPropertyDirection::Both));
381 aryProperties.Add(
new TypeProperty(
"ForceY", AnimatPropertyType::Float, AnimatPropertyDirection::Both));
382 aryProperties.Add(
new TypeProperty(
"ForceZ", AnimatPropertyType::Float, AnimatPropertyDirection::Both));
383 aryProperties.Add(
new TypeProperty(
"TorqueX", AnimatPropertyType::Float, AnimatPropertyDirection::Both));
384 aryProperties.Add(
new TypeProperty(
"TorqueY", AnimatPropertyType::Float, AnimatPropertyDirection::Both));
385 aryProperties.Add(
new TypeProperty(
"TorqueZ", AnimatPropertyType::Float, AnimatPropertyDirection::Both));
388 void VsForceStimulus::Load(CStdXml &oXml)
390 ActivatedItem::Load(oXml);
394 m_strStructureID = oXml.GetChildString(
"StructureID");
396 THROW_ERROR(Al_Err_lIDBlank, Al_Err_strIDBlank);
398 m_strBodyID = oXml.GetChildString(
"BodyID");
400 THROW_ERROR(Al_Err_lBodyIDBlank, Al_Err_strBodyIDBlank);
402 ForceXEquation(oXml.GetChildString(
"ForceX",
""));
403 ForceYEquation(oXml.GetChildString(
"ForceY",
""));
404 ForceZEquation(oXml.GetChildString(
"ForceZ",
""));
406 TorqueXEquation(oXml.GetChildString(
"TorqueX",
""));
407 TorqueYEquation(oXml.GetChildString(
"TorqueY",
""));
408 TorqueZEquation(oXml.GetChildString(
"TorqueZ",
""));
411 Std_LoadPoint(oXml,
"RelativePosition", m_oRelativePosition);
416 m_oRelativePosition *= m_lpSim->InverseDistanceUnits();
virtual void ResetSimulation()
Resets the simulation back to time 0.
A common class for all rigid body data specific to vortex.
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
Simulator * m_lpSim
The pointer to a Simulation.
virtual void Deactivate()
Deactivates this item.
virtual Simulator * GetSimulator()
Gets the simulator pointer.
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
virtual void StepSimulation()
Step the simulation for this object.
virtual void Initialize()
Initializes this object.
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.
virtual void Deactivate()
Deactivates this item.
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.
bool Std_LoadPoint(CStdXml &oXml, std::string strName, CStdIPoint &oPoint, bool bThrowError)
Standard load point.
virtual float * GetDataPointer(const std::string &strDataType)
Returns a float pointer to a data item of interest in this object.
std::string m_strName
The name for this object.