6 #include "IMovableItemCallback.h"
7 #include "ISimGUICallback.h"
10 #include <sys/types.h>
15 #include "IPhysicsMovableItem.h"
16 #include "IPhysicsBody.h"
18 #include "MovableItem.h"
21 #include "MotorizedJoint.h"
43 #include "ForceStimulus.h"
47 namespace ExternalStimuli
54 ForceStimulus::ForceStimulus()
59 m_lpForceXEval = NULL;
60 m_lpForceYEval = NULL;
61 m_lpForceZEval = NULL;
67 m_fltForceReportX = 0;
68 m_fltForceReportY = 0;
69 m_fltForceReportZ = 0;
71 m_lpTorqueXEval = NULL;
72 m_lpTorqueYEval = NULL;
73 m_lpTorqueZEval = NULL;
79 m_fltTorqueReportX = 0;
80 m_fltTorqueReportY = 0;
81 m_fltTorqueReportZ = 0;
84 ForceStimulus::~ForceStimulus()
92 if(m_lpForceXEval)
delete m_lpForceXEval;
93 if(m_lpForceYEval)
delete m_lpForceYEval;
94 if(m_lpForceZEval)
delete m_lpForceZEval;
96 if(m_lpTorqueXEval)
delete m_lpTorqueXEval;
97 if(m_lpTorqueYEval)
delete m_lpTorqueYEval;
98 if(m_lpTorqueZEval)
delete m_lpTorqueZEval;
101 {
Std_TraceMsg(0,
"Caught Error in desctructor of ForceStimulus\r\n",
"", -1,
false,
true);}
119 void ForceStimulus::RelativePositionX(
float fltVal)
125 void ForceStimulus::RelativePositionY(
float fltVal)
131 void ForceStimulus::RelativePositionZ(
float fltVal)
137 void ForceStimulus::ForceXEquation(std::string strVal)
140 {
delete m_lpForceXEval; m_lpForceXEval = NULL;}
142 m_strForceXEquation = strVal;
143 m_lpForceXEval = SetupEquation(strVal);
146 void ForceStimulus::ForceYEquation(std::string strVal)
149 {
delete m_lpForceYEval; m_lpForceYEval = NULL;}
151 m_strForceYEquation = strVal;
152 m_lpForceYEval = SetupEquation(strVal);
155 void ForceStimulus::ForceZEquation(std::string strVal)
158 {
delete m_lpForceZEval; m_lpForceZEval = NULL;}
160 m_strForceZEquation = strVal;
161 m_lpForceZEval = SetupEquation(strVal);
164 void ForceStimulus::TorqueXEquation(std::string strVal)
167 {
delete m_lpTorqueXEval; m_lpTorqueXEval = NULL;}
169 m_strTorqueXEquation = strVal;
170 m_lpTorqueXEval = SetupEquation(strVal);
173 void ForceStimulus::TorqueYEquation(std::string strVal)
176 {
delete m_lpTorqueYEval; m_lpTorqueYEval = NULL;}
178 m_strTorqueYEquation = strVal;
179 m_lpTorqueYEval = SetupEquation(strVal);
182 void ForceStimulus::TorqueZEquation(std::string strVal)
185 {
delete m_lpTorqueZEval; m_lpTorqueZEval = NULL;}
187 m_strTorqueZEquation = strVal;
188 m_lpTorqueZEval = SetupEquation(strVal);
204 m_fltForceX = m_fltForceY = m_fltForceZ = 0;
205 m_fltForceReportX = m_fltForceReportY = m_fltForceReportZ = 0;
206 m_fltTorqueX = m_fltTorqueY = m_fltTorqueZ = 0;
207 m_fltTorqueReportX = m_fltTorqueReportY = m_fltTorqueReportZ = 0;
227 if(m_lpForceXEval || m_lpForceYEval || m_lpForceZEval)
229 m_fltForceX = m_fltForceY = m_fltForceZ = 0;
230 m_fltForceReportX = m_fltForceReportY = m_fltForceReportZ = 0;
235 m_fltForceReportX = m_lpForceXEval->
Solve();
242 m_fltForceReportY = m_lpForceYEval->
Solve();
249 m_fltForceReportZ = m_lpForceZEval->
Solve();
253 if(m_lpBody && (m_fltForceX || m_fltForceY || m_fltForceZ))
254 m_lpBody->
AddForceAtLocalPos(m_oRelativePosition.x, m_oRelativePosition.y, m_oRelativePosition.z,
255 m_fltForceX, m_fltForceY, m_fltForceZ,
false);
258 if(m_lpTorqueXEval || m_lpTorqueYEval || m_lpTorqueZEval)
260 m_fltTorqueX = m_fltTorqueY = m_fltTorqueZ = 0;
261 m_fltTorqueReportX = m_fltTorqueReportY = m_fltTorqueReportZ = 0;
266 m_fltTorqueReportX = m_lpTorqueXEval->
Solve();
273 m_fltTorqueReportY = m_lpTorqueYEval->
Solve();
280 m_fltTorqueReportZ = m_lpTorqueZEval->
Solve();
284 if(m_lpBody && (m_fltTorqueX || m_fltTorqueY || m_fltTorqueZ))
285 m_lpBody->
AddTorque(m_fltTorqueX, m_fltTorqueY, m_fltTorqueZ,
false);
291 LOG_ERROR(
"Error Occurred while setting Joint Velocity");
299 m_lpBody->WakeDynamics();
307 if(strType ==
"FORCEX")
308 lpData = &m_fltForceReportX;
309 else if(strType ==
"FORCEY")
310 lpData = &m_fltForceReportY;
311 else if(strType ==
"FORCEZ")
312 lpData = &m_fltForceReportZ;
313 else if(strType ==
"TORQUEX")
314 lpData = &m_fltTorqueReportX;
315 else if(strType ==
"TORQUEY")
316 lpData = &m_fltTorqueReportY;
317 else if(strType ==
"TORQUEZ")
318 lpData = &m_fltTorqueReportZ;
320 THROW_TEXT_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType,
"StimulusName: " + STR(
m_strName) +
" DataType: " + strDataType);
332 if(strType ==
"POSITIONX")
334 RelativePositionX(atof(strValue.c_str()));
338 if(strType ==
"POSITIONY")
340 RelativePositionY(atof(strValue.c_str()));
344 if(strType ==
"POSITIONZ")
346 RelativePositionZ(atof(strValue.c_str()));
350 if(strType ==
"FORCEX")
352 ForceXEquation(strValue);
356 if(strType ==
"FORCEY")
358 ForceYEquation(strValue);
362 if(strType ==
"FORCEZ")
364 ForceZEquation(strValue);
368 if(strType ==
"TORQUEX")
370 TorqueXEquation(strValue);
374 if(strType ==
"TORQUEY")
376 TorqueYEquation(strValue);
380 if(strType ==
"TORQUEZ")
382 TorqueZEquation(strValue);
388 THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType,
"Data Type", strDataType);
397 aryProperties.Add(
new TypeProperty(
"PositionX", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
398 aryProperties.Add(
new TypeProperty(
"PositionY", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
399 aryProperties.Add(
new TypeProperty(
"PositionZ", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
400 aryProperties.Add(
new TypeProperty(
"ForceX", AnimatPropertyType::Float, AnimatPropertyDirection::Both));
401 aryProperties.Add(
new TypeProperty(
"ForceY", AnimatPropertyType::Float, AnimatPropertyDirection::Both));
402 aryProperties.Add(
new TypeProperty(
"ForceZ", AnimatPropertyType::Float, AnimatPropertyDirection::Both));
403 aryProperties.Add(
new TypeProperty(
"TorqueX", AnimatPropertyType::Float, AnimatPropertyDirection::Both));
404 aryProperties.Add(
new TypeProperty(
"TorqueY", AnimatPropertyType::Float, AnimatPropertyDirection::Both));
405 aryProperties.Add(
new TypeProperty(
"TorqueZ", AnimatPropertyType::Float, AnimatPropertyDirection::Both));
408 void ForceStimulus::Load(
CStdXml &oXml)
410 ActivatedItem::Load(oXml);
416 THROW_ERROR(Al_Err_lIDBlank, Al_Err_strIDBlank);
420 THROW_ERROR(Al_Err_lBodyIDBlank, Al_Err_strBodyIDBlank);
431 Std_LoadPoint(oXml,
"RelativePosition", m_oRelativePosition);
Declares the external stimulus base class.
Base class file for all Animat simulation objects.
Declares the nervous system class.
void AddVariable(std::string strVarName)
Adds a variable.
Declares the simulation recorder class.
Simulates the entire environment.
Root namespace for the base simulation library for AnimatLab.
virtual float InverseMassUnits()
Gets the inverse mass units.
Declares the body part class.
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
virtual void ResetSimulation()
Resets the simulation back to time 0.
virtual void AddTorque(float fltTx, float fltTy, float fltTz, bool bScaleUnits)
Adds a torque to this body about its center.
Simulator * m_lpSim
The pointer to a Simulation.
virtual short PhysicsStepInterval()
Gets the physics step interval.
virtual bool IntoElem()
Goes into the next element where the cursor is located.
Class that stores information about types for QueryProperty information.
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
Declares the link base class.
Declares the key frame class.
virtual Simulator * GetSimulator()
Gets the simulator pointer.
Declares the joint class.
Declares the organism class.
virtual long PhysicsStepCount()
Gets the physics step count.
Declares the activated item class.
Declares a light manager object.
Declares the bounding box class.
Declares the gain base class.
void Equation(std::string strVal)
Sets the post-fix Equation.
A standard xml manipulation class.
virtual void ResetSimulation()
Resets the simulation back to time 0.
virtual std::string GetChildString(std::string strElementName)
Gets a string value from the element with the specified name.
virtual void Deactivate()
Deactivates this item.
Standard post fix evaluation class.
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 AddForceAtLocalPos(float fltPx, float fltPy, float fltPz, float fltFx, float fltFy, float fltFz, bool bScaleUnits)
Adds a world-coordinate based force vector to this body at a specified local body position...
double Solve()
Solves the equation using the defined variable values.
void SetVariable(std::string strVarName, double dblVal)
Sets the value of a variable.
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 float * GetDataPointer(const std::string &strDataType)
Returns a float pointer to a data item of interest in this object.
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
virtual void Deactivate()
Deactivates this item.
virtual Structure * FindStructureFromAll(std::string strStructureID, bool bThrowError=true)
Searches for the first structure with the specified ID.
bool Std_IsBlank(std::string strVal)
Trims a string and tests if a string is blank.
Declares the data chart manager class.
Declares the rigid body class.
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.
Declares the structure class.
Declares the odor type class.
virtual void Initialize()
Initializes this object.
virtual float InverseDistanceUnits()
Gets the inverse distance units.
Declares the simulator class.
Declares the neural module class.
virtual float Time()
Gets the current simulation time in seconds.
Declares the activated item manager class.
Declares the external stimuli manager class.
virtual RigidBody * FindRigidBody(std::string strBodyID, bool bThrowError=true)
Finds a rigid body with a specified ID within this structure.
Declares the receptive field class.
virtual void StepSimulation()
Step the simulation for this object.
std::string m_strName
The name for this object.
virtual void Initialize()
Initializes this object.
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.