8 #include "IMovableItemCallback.h"
9 #include "ISimGUICallback.h"
14 #include "IPhysicsMovableItem.h"
15 #include "IPhysicsBody.h"
17 #include "MovableItem.h"
61 m_fltDelayBufferInterval = 0;
62 m_eDelayBufferMode = NoDelayBuffer;
93 {
Std_TraceMsg(0,
"Caught Error in desctructor of Adapter\r\n",
"", -1,
false,
true);}
117 THROW_TEXT_ERROR(Al_Err_lModuleNameBlank, Al_Err_strModuleNameBlank,
". Source Module. ID: " + strName);
142 THROW_TEXT_ERROR(Al_Err_lDataTypeBlank, Al_Err_strDataTypeBlank,
" Source ID");
167 THROW_TEXT_ERROR(Al_Err_lDataTypeBlank, Al_Err_strDataTypeBlank,
" Source DataType");
202 THROW_TEXT_ERROR(Al_Err_lModuleNameBlank, Al_Err_strModuleNameBlank,
". Target Module. ID: " + strName);
228 THROW_TEXT_ERROR(Al_Err_lDataTypeBlank, Al_Err_strDataTypeBlank,
" Target ID");
275 void Adapter::SetGain(
Gain *lpGain)
309 return m_eDelayBufferMode;
324 m_eDelayBufferMode = eMode;
325 SetDelayBufferSize();
348 Std_IsAboveMin((
float) 0, fltVal,
true,
"DelayBufferInterval",
true);
349 m_fltDelayBufferInterval = fltVal;
350 SetDelayBufferSize();
435 Std_IsAboveMin((
float) 0, fltVal,
true,
"SynchUpdateInterval",
true);
481 Std_IsAboveMin((
float) 0, fltVal,
true,
"SynchUpdateStartInterval",
true);
526 Std_IsAboveMin((
float) 0, fltVal,
true,
"InitIODisableDuration",
true);
530 void Adapter::DetachAdaptersFromSimulation()
541 THROW_TEXT_ERROR(Al_Err_lOpNotDefinedForAdapter, Al_Err_strOpNotDefinedForAdapter,
"AddExternalNodeInput");
548 float *lpData = NULL;
550 if(strType ==
"ENABLE")
552 else if(strType ==
"CALCULATEDVAL")
554 else if(strType ==
"NEXTVAL")
556 else if(strType ==
"UPDATEDVALUE")
580 void Adapter::SetOriginID(std::string strXml)
603 void Adapter::SetDestinationID(std::string strXml)
626 bool Adapter::SetData(
const std::string &strDataType,
const std::string &strValue,
bool bThrowError)
633 if(strType ==
"GAIN")
639 if(strType ==
"ORIGINID")
641 SetOriginID(strValue);
645 if(strType ==
"DESTINATIONID")
647 SetDestinationID(strValue);
651 if(strType ==
"DELAYBUFFERMODE")
657 if(strType ==
"DELAYBUFFERINTERVAL")
663 if(strType ==
"ROBOTIOSCALE")
669 if(strType ==
"SYNCHWITHROBOT")
675 if(strType ==
"SYNCHUPDATEINTERVAL")
681 if(strType ==
"SYNCHUPDATESTARTINTERVAL")
687 if(strType ==
"INITIODISABLEDURATION")
695 THROW_PARAM_ERROR(Al_Err_lInvalidItemType, Al_Err_strInvalidItemType,
"Data Type", strDataType);
704 aryProperties.Add(
new TypeProperty(
"Enable", AnimatPropertyType::Boolean, AnimatPropertyDirection::Get));
705 aryProperties.Add(
new TypeProperty(
"CalculatedVal", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
706 aryProperties.Add(
new TypeProperty(
"NextVal", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
707 aryProperties.Add(
new TypeProperty(
"UpdatedValue", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
709 aryProperties.Add(
new TypeProperty(
"Gain", AnimatPropertyType::Xml, AnimatPropertyDirection::Set));
710 aryProperties.Add(
new TypeProperty(
"DelayBufferMode", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
711 aryProperties.Add(
new TypeProperty(
"DelayBufferInterval", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
712 aryProperties.Add(
new TypeProperty(
"RobotIOScale", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
713 aryProperties.Add(
new TypeProperty(
"SynchWithRobot", AnimatPropertyType::Boolean, AnimatPropertyDirection::Set));
714 aryProperties.Add(
new TypeProperty(
"SynchUpdateInterval", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
715 aryProperties.Add(
new TypeProperty(
"SynchUpdateStartInterval", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
716 aryProperties.Add(
new TypeProperty(
"InitIODisableDuration", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
733 SetDelayBufferSize();
738 bool Adapter::NeedsRobotSynch()
763 for(
int iIdx=0; iIdx<iSize; iIdx++)
767 void Adapter::SetDelayBufferSize()
769 if(m_eDelayBufferMode == eDelayBufferMode::DelayBufferAlwaysOn ||
778 int iLength = (int) (m_fltDelayBufferInterval/fltTimeStep);
792 THROW_PARAM_ERROR(Al_Err_lNodeNotFound, Al_Err_strNodeNotFound,
"ID: ",
m_strSourceID);
797 THROW_TEXT_ERROR(Al_Err_lDataPointNotFound, Al_Err_strDataPointNotFound,
802 THROW_PARAM_ERROR(Al_Err_lNodeNotFound, Al_Err_strNodeNotFound,
"ID: ",
m_strTargetID);
814 SetDelayBufferSize();
819 void Adapter::ApplyExternalNodeInput(
int iTargetDataType,
float fltNextVal)
858 if(m_eDelayBufferMode == eDelayBufferMode::DelayBufferAlwaysOn ||
878 void Adapter::Load(
CStdXml &oXml)
virtual void Deserialize(std::string &strXml)
Deserializes a string into an xml document.
Base class file for all Animat simulation objects.
Declares the nervous system class.
Gain * m_lpGain
Pointer to the Gain that will be used to convert the source value into the target value...
virtual void PhysicsTimeStep(float fltVal)
Sets the integration time step for the physics engine.
Declares the simulation recorder class.
virtual std::string TargetModule()
Gets the name of the target NeuralModule.
virtual void SetSystemPointers(Simulator *lpSim, Structure *lpStructure, NeuralModule *lpModule, Node *lpNode, bool bVerify)
Sets the system pointers.
Adapter()
Default constructor.
virtual bool FindChildElement(std::string strElementName, bool fThrowError=true)
Finds a child element by name.
virtual bool InSimulation()
Used to determine if we are running in a simulation, or in a real control mode.
virtual std::string SourceModule()
Gets the name of the source NeuralModule.
Root namespace for the base simulation library for AnimatLab.
AnimatSim::Behavior::NeuralModule * m_lpModule
The pointer to this items parentNeuralModule. If this is not relevant for this object then this is NU...
virtual float TimeStep()
Gets the time step for this moudle in time units.
virtual float SynchUpdateStartInterval()
This is the interval that this adapter waits the first time before doing its update.
virtual eDelayBufferMode DelayBufferMode()
Returns the mode for the delay buffer.
Declares the body part class.
virtual bool ConnectedToPhysics()
Returns whether or not this adpater is connected to a physics object or not.
std::string m_strSourceModule
Name of the source NeuralModule.
virtual void StepSimulation()
Step the simulation for this object.
virtual void AddExternalNodeInput(int iTargetDataType, float fltInput)=0
Adds an external node input.
virtual Node * TargetNode()
Gets the target node.
virtual bool FindElement(std::string strElementName, bool fThrowError=true)
Finds an element with the specified name.
float m_fltUpdatedValue
Set to 1 each time the adapter was updated and 0 otherwise. Use to chart when the adpater was updated...
Simulator * m_lpSim
The pointer to a Simulation.
float m_fltEnabled
This is used for reporting the enabled state in a GetDataPointer call.
float m_fltCalculatedVal
This is the value that will was calculated for this adpater. If you are using a delay buffer this may...
virtual std::string ID()
Gets the unique GUID ID of this object.
virtual bool IntoElem()
Goes into the next element where the cursor is located.
virtual int GetTargetDataTypeIndex(const std::string &strDataType)
Used to convert a string target data type into an integer index.
virtual float * GetDataPointer(const std::string &strDataType)
Returns a float pointer to a data item of interest in this object.
Class that stores information about types for QueryProperty information.
virtual void TimeStepModified()
Notification method that the time step modified has been modified. Objects should recalculate any sli...
virtual void Initialize()
Initializes this object.
Declares the link base class.
CStdCircularArray< float > m_aryDelayBuffer
std::string m_strSourceDataType
DateType of the source variable that will be converted. This is retrieved using the GetDataPointer me...
Declares the key frame class.
virtual void Initialize()
Initializes this object.
std::string m_strTargetDataType
Node * m_lpSourceNode
Pointer to the source node.
Declares the joint class.
std::string m_strTargetModule
Name of the target NeuralModule.
Declares the organism class.
virtual int GetChildInt(std::string strElementName)
Gets an integer value from the element with the specified name.
bool Std_IsAboveMin(int iMinVal, int iVal, bool bThrowError, std::string strParamName, bool bInclusiveLimit)
Tests if a number is above a minimum value.
AnimatSim::Environment::Structure * m_lpStructure
The pointer to this items parent Structure. If this is not relevant for this object then this is NULL...
virtual bool Enabled()
Tells whether this node is enabled.
std::string m_strID
The unique Id 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.
std::string m_strSourceID
GUID ID of the source node.
std::string m_strTargetID
GUID ID of the target node.
Node * m_lpTargetNode
Pointer to the target node.
virtual void TimeStepModified()
If the time step is modified then we need to recalculate the length of the delay buffer.
Declares the activated item class.
virtual float * GetDataPointer(const std::string &strDataType)
Returns a float pointer to a data item of interest in this object.
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
Declares a light manager object.
int m_iSynchTarget
The target count for synching.
virtual bool RobotAdpaterSynch()
Gets whether we need to synch the physics adapters in a simulation to the robot physics time step...
Declares the bounding box class.
Declares the gain base class.
bool m_bConnectedToPhysics
A standard xml manipulation class.
virtual Gain * GetGain()
Gets the poitner to the gain function.
int m_iSynchUpdateStartInterval
The number of ticks between the first call to update for this adapter till the next update time...
virtual float RobotIOScale()
Gets the scale value used for calculated values for this adapter during simulation mode only...
virtual void ResetSimulation()
Resets the simulation back to time 0.
virtual std::string SourceDataType()
Gets the source data type.
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.
virtual void AddGain(std::string strXml)
Creates and adds a gain object.
virtual float DelayBufferInterval()
Returns the time interval used for the delay buffer if this adapter is set to use one...
bool Std_ToBool(int iVal)
Converts a value toa bool.
virtual std::string TargetID()
Gets the GUID ID of the target node where we will add the transformed data variable.
virtual void Load(StdUtils::CStdXml &oXml)
Loads the item using an XML data packet.
virtual std::string SourceID()
Gets the GUID ID of the source node where we will get the source data variable.
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.
bool m_bEnabled
Tells if this item is enabled or not. If it is not enabled then it is not run.
float * m_lpSourceData
Pointer to the source data varaible.
int m_iSynchCount
Keeps track of the last time we did a synch for the robot.
virtual float SynchUpdateInterval()
This is how often we need to update this particular adapter.
Base class for body parts and neural network nodes.
float m_fltSynchUpdateInterval
This is how often we need to update this particular adapter.
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
float m_fltInitIODisableDuration
bool Std_IsBlank(std::string strVal)
Trims a string and tests if a string is blank.
Declares the data chart manager class.
float m_fltNextVal
This is the value that will be passed into the adpters target.
virtual void ResetSimulation()
Resets the simulation back to time 0.
Declares the rigid body class.
virtual float CalculateGain(float fltInput)=0
Calculates the gain.
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
int m_iTargetDataType
The m_strTargetDataType string is converted to an integer for use within the simulation loop to maxim...
virtual bool SynchWithRobot()
Gets whether the m_bRobotAdpaterSynch flag applies to this adapter.
Declares the structure class.
Declares the odor type class.
virtual Node * SourceNode()
Gets the source node.
virtual ~Adapter()
Destructor.
Declares the simulator class.
Declares the neural module class.
virtual float Time()
Gets the current simulation time in seconds.
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
Declares the activated item manager class.
float m_fltSynchUpdateStartInterval
Declares the external stimuli manager class.
int m_iSynchUpdateInterval
The number of ticks between each call to update for this adapter till the next update time...
virtual float InitIODisableDuration()
Gets the duration for how long this adapter is disabled at the start of the simulation.
Gain * LoadGain(Simulator *lpSim, std::string strName, CStdXml &oXml)
Loads a gain object.
Declares the receptive field class.
virtual void AddExternalNodeInput(int iTargetDataType, float fltInput)
Adds an external node input.
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.
virtual std::string TargetDataType()
Gets the target data type.