10 #include "IMovableItemCallback.h"
11 #include "ISimGUICallback.h"
14 #include <sys/types.h>
19 #include "IPhysicsMovableItem.h"
20 #include "IPhysicsBody.h"
22 #include "MovableItem.h"
25 #include "MotorizedJoint.h"
51 namespace ExternalStimuli
65 m_bDisableMotorWhenDone =
false;
68 m_iTargetID = DESIRED_VELOCITY_TYPE;
83 if(m_lpEval)
delete m_lpEval;
86 {
Std_TraceMsg(0,
"Caught Error in desctructor of MotorStimulus\r\n",
"", -1,
false,
true);}
97 void MotorStimulus::Equation(std::string strVal)
101 {
delete m_lpEval; m_lpEval = NULL;}
103 m_strEquation = strVal;
112 void MotorStimulus::TargetID(
int iID)
114 if(iID == DESIRED_VELOCITY_TYPE || iID == DESIRED_POSITION_TYPE)
117 THROW_PARAM_ERROR(Al_Err_lInvalidTargetID, Al_Err_strInvalidTargetID,
"ID", iID);
120 void MotorStimulus::TargetID(std::string strID)
124 if(strId ==
"VELOCITY")
125 m_iTargetID = DESIRED_VELOCITY_TYPE;
126 else if(strId ==
"POSITION")
127 m_iTargetID = DESIRED_POSITION_TYPE;
129 THROW_PARAM_ERROR(Al_Err_lInvalidTargetID, Al_Err_strInvalidTargetID,
"ID", strID);
137 m_fltValueReport = 0;
147 THROW_PARAM_ERROR(Al_Err_lJointNotMotorized, Al_Err_strJointNotMotorized,
"ID", m_strJointID);
149 m_lpPosition = m_lpJoint->GetDataPointer(
"JOINTPOSITION");
150 m_lpVelocity = m_lpJoint->GetDataPointer(
"JOINTACTUALVELOCITY");
165 if(m_iTargetID == DESIRED_VELOCITY_TYPE)
196 m_fltValueReport = m_fltValue = m_lpEval->
Solve();
202 if(m_iTargetID == DESIRED_VELOCITY_TYPE)
204 else if(m_iTargetID == DESIRED_POSITION_TYPE)
211 LOG_ERROR(
"Error Occurred while setting Joint Velocity");
222 if(m_iTargetID == DESIRED_VELOCITY_TYPE)
225 if(m_bDisableMotorWhenDone)
235 if(strType ==
"VELOCITY" || strType ==
"VALUE")
236 lpData = &m_fltValueReport;
238 THROW_TEXT_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType,
"StimulusName: " + STR(
m_strName) +
" DataType: " + strDataType);
250 if(strType ==
"VELOCITY" || strType ==
"EQUATION")
256 if(strType ==
"DISABLEWHENDONE")
262 if(strType ==
"TARGETID")
270 THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType,
"Data Type", strDataType);
279 aryProperties.Add(
new TypeProperty(
"Velocity", AnimatPropertyType::Float, AnimatPropertyDirection::Both));
280 aryProperties.Add(
new TypeProperty(
"Value", AnimatPropertyType::Float, AnimatPropertyDirection::Both));
281 aryProperties.Add(
new TypeProperty(
"Equation", AnimatPropertyType::String, AnimatPropertyDirection::Set));
282 aryProperties.Add(
new TypeProperty(
"DisableMotorWhenDone", AnimatPropertyType::Boolean, AnimatPropertyDirection::Set));
283 aryProperties.Add(
new TypeProperty(
"TargetID", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
286 void MotorStimulus::Load(
CStdXml &oXml)
288 ActivatedItem::Load(oXml);
294 THROW_ERROR(Al_Err_lIDBlank, Al_Err_strIDBlank);
298 THROW_ERROR(Al_Err_lIDBlank, Al_Err_strIDBlank);
305 DisableMotorWhenDone(oXml.
GetChildBool(
"DisableMotorWhenDone", m_bDisableMotorWhenDone));
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.
virtual void Activate()
Activates this item.
Declares the simulation recorder class.
virtual bool FindChildElement(std::string strElementName, bool fThrowError=true)
Finds a child element by name.
Root namespace for the base simulation library for AnimatLab.
virtual void Activate()
Activates this item.
Declares the body part class.
Simulator * m_lpSim
The pointer to a Simulation.
virtual short PhysicsStepInterval()
Gets the physics step interval.
virtual ~MotorStimulus()
Destructor.
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.
virtual float DesiredVelocity()
Gets the desired velocity.
Declares the link base class.
Declares the key frame class.
Declares the joint class.
Declares the organism class.
virtual float * GetDataPointer(const std::string &strDataType)
Returns a float pointer to a data item of interest in this object.
virtual long PhysicsStepCount()
Gets the physics step count.
Declares the activated item class.
Declares a light manager object.
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 bounding box class.
Declares the gain base class.
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
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 void ResetSimulation()
Resets the simulation back to time 0.
virtual bool EnableMotor()
Tells if the motor is enabled.
virtual std::string GetChildString(std::string strElementName)
Gets a string value from the element with the specified name.
bool Std_ToBool(int iVal)
Converts a value toa bool.
virtual void Initialize()
Initializes this object.
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 bool GetChildBool(std::string strElementName)
Gets a bool value from the element with the specified name.
double Solve()
Solves the equation using the defined variable values.
bool m_bEnabled
Tells if this item is enabled or not. If it is not enabled then it is not run.
void SetVariable(std::string strVarName, double dblVal)
Sets the value of a variable.
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
virtual void Deactivate()
Deactivates this item.
virtual float DesiredPosition()
Gets the desired Position.
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.
virtual void StepSimulation()
Step the simulation for this object.
Declares the structure class.
MotorStimulus()
Default constructor.
Declares the odor type class.
virtual void Initialize()
Initializes this object.
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
virtual bool UsesRadians()
Tells whether this joint uses radians or meters for its measurements.
Declares the vs motor velocity stimulus class.
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.
virtual void Deactivate()
Deactivates this item.
Declares the external stimuli manager class.
Declares the receptive field class.
std::string m_strName
The name for 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.