8 #include "IMovableItemCallback.h"
9 #include "ISimGUICallback.h"
14 #include "IPhysicsMovableItem.h"
15 #include "IPhysicsBody.h"
17 #include "MovableItem.h"
46 namespace ExternalStimuli
58 m_fltSetThreshold = 0.5;
59 m_fltPreviousSetVal = 0;
60 m_fltInitialValue = 0;
75 m_ePropertyType = AnimatPropertyType::Invalid;
77 if(m_lpEval)
delete m_lpEval;
80 {
Std_TraceMsg(0,
"Caught Error in desctructor of PropertyControlStimulus\r\n",
"", -1,
false,
true);}
106 THROW_ERROR(Al_Err_lBodyIDBlank, Al_Err_strBodyIDBlank);
110 m_ePropertyType = AnimatPropertyType::Invalid;
111 m_strPropertyName =
"";
126 void PropertyControlStimulus::Equation(std::string strVal)
130 {
delete m_lpEval; m_lpEval = NULL;}
132 m_strEquation = strVal;
155 if(
Std_Trim(strPropName).length() == 0)
156 THROW_PARAM_ERROR(Al_Err_lPropertyNameBlank, Al_Err_strPropertyNameBlank,
"Adapter ID",
m_strID);
159 THROW_PARAM_ERROR(Al_Err_lTargetDoesNotHaveProperty, Al_Err_strTargetDoesNotHaveProperty,
"Property name", strPropName);
161 AnimatPropertyType ePropertyType =
m_lpTargetObject->PropertyType(strPropName);
162 if(!(ePropertyType != AnimatPropertyType::Boolean || ePropertyType != AnimatPropertyType::Integer || ePropertyType != AnimatPropertyType::Float))
163 THROW_PARAM_ERROR(Al_Err_lTargetInvalidPropertyType, Al_Err_strTargetInvalidPropertyType,
"Property name", strPropName);
165 m_ePropertyType = ePropertyType;
168 m_ePropertyType = AnimatPropertyType::Invalid;
170 m_strPropertyName = strPropName;
182 {
return m_strPropertyName;}
198 THROW_PARAM_ERROR(Al_Err_lInvalidSetThreshold, Al_Err_strInvalidSetThreshold,
"Threshold", fltThreshold);
200 m_fltSetThreshold = fltThreshold;
212 {
return m_fltSetThreshold;}
224 m_fltInitialValue = fltVal;
225 m_fltPreviousSetVal = fltVal;
237 {
return m_fltInitialValue;}
249 m_fltFinalValue = fltVal;
261 {
return m_fltFinalValue;}
279 THROW_PARAM_ERROR(Al_Err_lNodeNotFound, Al_Err_strNodeNotFound,
"ID: ",
m_strTargetID);
283 m_fltPreviousSetVal = m_fltInitialValue;
292 m_fltPreviousSetVal = m_fltInitialValue;
293 if(m_ePropertyType != AnimatPropertyType::Invalid)
298 void PropertyControlStimulus::SetPropertyValue(
float fltVal)
301 if(m_ePropertyType != AnimatPropertyType::Invalid)
303 float fltDiff = fltVal - m_fltPreviousSetVal;
304 if(fabs(fltDiff) > m_fltSetThreshold)
306 m_fltPreviousSetVal = fltVal;
308 if(m_ePropertyType == AnimatPropertyType::Boolean)
315 else if(m_ePropertyType == AnimatPropertyType::Integer)
317 int iVal = (int) fltVal;
341 float fltInput = m_lpEval->
Solve();
343 SetPropertyValue(fltInput);
349 LOG_ERROR(
"Error Occurred while setting Joint Velocity");
359 m_fltPreviousSetVal = m_fltInitialValue;
360 if(m_ePropertyType != AnimatPropertyType::Invalid)
372 if(strType ==
"TARGETID")
378 if(strType ==
"PROPERTYNAME")
384 if(strType ==
"SETTHRESHOLD")
390 if(strType ==
"INITIALVALUE")
396 if(strType ==
"FINALVALUE")
402 if(strType ==
"EQUATION")
410 THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType,
"Data Type", strDataType);
419 aryProperties.Add(
new TypeProperty(
"TargetID", AnimatPropertyType::String, AnimatPropertyDirection::Set));
420 aryProperties.Add(
new TypeProperty(
"PropertyName", AnimatPropertyType::String, AnimatPropertyDirection::Set));
421 aryProperties.Add(
new TypeProperty(
"SetThreshold", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
422 aryProperties.Add(
new TypeProperty(
"InitialValue", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
423 aryProperties.Add(
new TypeProperty(
"FinalValue", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
424 aryProperties.Add(
new TypeProperty(
"Equation", AnimatPropertyType::String, AnimatPropertyDirection::Set));
427 void PropertyControlStimulus::Load(
CStdXml &oXml)
429 ActivatedItem::Load(oXml);
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 SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
virtual void StepSimulation()
Step the simulation for this object.
Root namespace for the base simulation library for AnimatLab.
Declares the body part class.
virtual void Initialize()
Initializes this object.
Simulator * m_lpSim
The pointer to a Simulation.
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
virtual short PhysicsStepInterval()
Gets the physics step interval.
virtual bool IntoElem()
Goes into the next element where the cursor is located.
virtual bool HasProperty(const std::string &strName)
Queries this object if it has a property with the given name.
virtual std::string TargetID()
Gets the GUID ID of the target node that will be enabled.
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.
Declares the joint class.
Declares the organism class.
std::string m_strID
The unique Id for this object.
std::string Std_Trim(std::string strVal)
Trims a string.
std::string m_strTargetID
GUID ID of the target node to enable.
virtual long PhysicsStepCount()
Gets the physics step count.
Declares the activated item class.
Declares a light manager object.
virtual float FinalValue()
Gets the final value used to set this property when the simulation ends.
Declares a stimulus class that can set any property on any object in the system.
Declares the bounding box class.
virtual std::string Type()
returns the string type name of this object.
PropertyControlStimulus()
Default constructor.
Declares the gain base class.
void Equation(std::string strVal)
Sets the post-fix Equation.
A standard xml manipulation class.
virtual float InitialValue()
Gets vthe initial value used to set this property when the simulation starts.
virtual std::string GetChildString(std::string strElementName)
Gets a string value from the element with the specified name.
virtual AnimatBase * FindByID(std::string strID, bool bThrowError=true)
Searches for the object with the specified ID.
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.
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.
bool m_bInitialized
true if item has been initialized
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
virtual void Deactivate()
Deactivates this item.
virtual void Activate()
Activates this item.
virtual ~PropertyControlStimulus()
Destructor.
virtual std::string PropertyName()
Gets the name of the property that this adapter will be setting.
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.
Declares the structure class.
AnimatBase * m_lpTargetObject
Pointer to the target node.
Declares the odor type class.
virtual void Initialize()
Initializes this object.
virtual AnimatBase * TargetObject()
Gets the target object.
virtual float SetThreshold()
Gets the threshold value used for determining when to set the value on the target object...
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 bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
Declares the receptive field class.
virtual void Deactivate()
Deactivates this item.
virtual float GetChildFloat(std::string strElementName)
Gets a float value from the element with the specified name.
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.