AnimatLab  2
Test
AnimatSim::Robotics::RobotInterface Class Reference

The Robotics interface configures a simulation to run on a microcontroller board. More...

#include <RobotInterface.h>

+ Inheritance diagram for AnimatSim::Robotics::RobotInterface:
+ Collaboration diagram for AnimatSim::Robotics::RobotInterface:

Public Member Functions

 RobotInterface (void)
 Default constructor. More...
 
virtual ~RobotInterface (void)
 Destructor. More...
 
virtual bool AddItem (const std::string &strItemType, const std::string &strXml, bool bThrowError=true, bool bDoNotInit=false)
 Adds a new object to this parent. More...
 
virtual void AfterResetSimulation ()
 Called after a simulation reset for some objects. More...
 
virtual float * GetDataPointer (const std::string &strDataType)
 Returns a float pointer to a data item of interest in this object. More...
 
virtual void Initialize ()
 Initializes this object. More...
 
virtual CStdPtrArray< RobotIOControl > * IOControls ()
 Gets the array of IO controls. More...
 
virtual void Load (CStdXml &oXml)
 
virtual float PhysicsTimeStep ()
 Gets the physics time step used within the robot framwork. More...
 
virtual void PhysicsTimeStep (float fltStep)
 Sets the physics time step used within the robot framwork. More...
 
virtual void QueryProperties (CStdPtrArray< TypeProperty > &aryProperties)
 Queries this object for a list of properties that can be changed using SetData. More...
 
virtual bool RemoveItem (const std::string &strItemType, const std::string &strID, bool bThrowError=true)
 Removes a child item from this parent. More...
 
virtual void ResetSimulation ()
 Resets the simulation back to time 0. More...
 
virtual bool SetData (const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
 Set a variable based on a string data type name. More...
 
virtual void StepSimulation ()
 Step the simulation for this object. More...
 
virtual bool SynchSim ()
 Gets whether we need to delay stepping of the physics adapters in the simulation to more closely match the real robot behavior. More...
 
virtual void SynchSim (bool bVal)
 Sets whether we need to delay stepping of the physics adapters in the simulation to more closely match the real robot behavior. More...
 
- Public Member Functions inherited from AnimatSim::AnimatBase
 AnimatBase ()
 Constructs an AnimatBase object. More...
 
virtual ~AnimatBase ()
 Destroys the AnimatBase object.. More...
 
virtual long CalculateSnapshotByteSize ()
 Calculates the snapshot byte size. More...
 
virtual void Copy (CStdSerialize *lpSource)
 
virtual void Enabled (bool bVal)
 Tells whether this item is enabled or not. This is not actually used for all objects, only specific ones. I am putting it in the base class though to prevent numerous duplications. More...
 
virtual bool Enabled ()
 Tells whether this item is enabled or not. This is not actually used for all objects, only specific ones. I am putting it in the base class though to prevent numerous duplications. More...
 
virtual NeuralModuleGetNeuralModule ()
 Gets the neural module. More...
 
virtual NodeGetNode ()
 Gets the node. More...
 
virtual SimulatorGetSimulator ()
 Gets the simulator pointer. More...
 
virtual StructureGetStructure ()
 Gets the structure for this node. More...
 
virtual bool HasProperty (const std::string &strName)
 Queries this object if it has a property with the given name. More...
 
virtual std::string ID ()
 Gets the unique GUID ID of this object. More...
 
virtual void ID (std::string strValue)
 Sets the unique GUID ID of the object. More...
 
virtual void Kill (bool bState=true)
 Kills. More...
 
virtual void Load (StdUtils::CStdXml &oXml)
 Loads the item using an XML data packet. More...
 
virtual void LoadKeyFrameSnapshot (byte *aryBytes, long &lIndex)
 Loads a key frame snapshot. More...
 
virtual std::string Name ()
 Gets the name of this object. More...
 
virtual void Name (std::string strValue)
 Sets the name of the object. Blank is acceptable. More...
 
virtual AnimatPropertyType PropertyType (const std::string &strName)
 
virtual void ReInitialize ()
 Re-initialize this object. More...
 
virtual void Reset ()
 Resets this object. More...
 
virtual void RigidBodyAdded (std::string strID)
 
virtual void RigidBodyRemoved (std::string strID)
 
virtual void SaveKeyFrameSnapshot (byte *aryBytes, long &lIndex)
 Saves a key frame snapshot. More...
 
virtual bool Selected ()
 Tells if this items is selected or not. More...
 
virtual void Selected (bool bValue, bool bSelectMultiple)
 Selects this object. More...
 
virtual bool SetData (const std::string &strDataType, const float fltValue, bool bThrowError=true)
 Set a variable based on a string data type name. More...
 
virtual bool SetData (const std::string &strDataType, const long lValue, bool bThrowError=true)
 Set a variable based on a string data type name. More...
 
virtual void SetSystemPointers (Simulator *lpSim, Structure *lpStructure, NeuralModule *lpModule, Node *lpNode, bool bVerify)
 Sets the system pointers. More...
 
virtual void SimPausing ()
 Called just before the simulation pauses. More...
 
virtual void SimStarting ()
 Called just before the simulation starts. More...
 
virtual void SimStopping ()
 Called just before the simulation stops. More...
 
virtual void TimeStepModified ()
 Notification method that the time step modified has been modified. Objects should recalculate any slice times as needed. More...
 
virtual std::string Type ()
 returns the string type name of this object. More...
 
virtual void Type (std::string strValue)
 Sets the class type for this object. More...
 
virtual void VerifySystemPointers ()
 Verify that system pointers have been set correctly. More...
 
virtual void VisualSelectionModeChanged (int iNewMode)
 Visual selection mode changed. More...
 

Static Public Member Functions

static RobotInterfaceCastToDerived (AnimatBase *lpBase)
 

Protected Member Functions

virtual RobotIOControlAddIOControl (std::string strXml)
 Creates and adds a robot IO control. More...
 
virtual int FindChildListPos (std::string strID, bool bThrowError=true)
 Finds the array index for the child part with the specified ID. More...
 
virtual RobotIOControlLoadIOControl (CStdXml &oXml)
 Loads a child IO Control. More...
 
virtual void RemoveIOControl (std::string strID, bool bThrowError=true)
 Removes the rigid body with the specified ID. More...
 

Protected Attributes

CStdPtrArray< RobotIOControlm_aryIOControls
 
bool m_bSynchSim
 
float m_fltPhysicsTimeStep
 
- Protected Attributes inherited from AnimatSim::AnimatBase
bool m_bEnabled
 Tells if this item is enabled or not. If it is not enabled then it is not run.
 
bool m_bSelected
 Tells whether the object is selected or not.
 
AnimatSim::Behavior::NeuralModulem_lpModule
 The pointer to this items parentNeuralModule. If this is not relevant for this object then this is NULL.
 
Nodem_lpNode
 The pointer to this items parent Node. If this is not relevant for this object then this is NULL.
 
Simulatorm_lpSim
 The pointer to a Simulation.
 
AnimatSim::Environment::Structurem_lpStructure
 The pointer to this items parent Structure. If this is not relevant for this object then this is NULL.
 
std::string m_strID
 The unique Id for this object.
 
std::string m_strName
 The name for this object.
 
std::string m_strType
 The type for this object. Examples are Box, Plane, Neuron, etc..
 

Detailed Description

The Robotics interface configures a simulation to run on a microcontroller board.

The robotics interface has two main purposes. The first is that it helps synchronize the simulation so it runs more like it would on real hardware. The second purpose is to configure the robotics simulation to run on the real robots microcomputer board. It contains the Robot IO controllers and robot part interfaces.

Author
dcofer
Date
9/8/2014

Definition at line 24 of file RobotInterface.h.

Constructor & Destructor Documentation

AnimatSim::Robotics::RobotInterface::RobotInterface ( void  )

Default constructor.

Author
dcofer
Date
9/8/2014

Definition at line 57 of file RobotInterface.cpp.

References m_bSynchSim, and m_fltPhysicsTimeStep.

AnimatSim::Robotics::RobotInterface::~RobotInterface ( void  )
virtual

Destructor.

Author
dcofer
Date
9/8/2014

Definition at line 69 of file RobotInterface.cpp.

References m_aryIOControls, and StdUtils::Std_TraceMsg().

+ Here is the call graph for this function:

Member Function Documentation

RobotIOControl * AnimatSim::Robotics::RobotInterface::AddIOControl ( std::string  strXml)
protectedvirtual

Creates and adds a robot IO control.

Author
dcofer
Date
3/2/2011
Parameters
strXmlThe xml data packet for loading the control node.

Definition at line 239 of file RobotInterface.cpp.

References StdUtils::CStdXml::Deserialize(), StdUtils::CStdXml::FindChildElement(), StdUtils::CStdXml::FindElement(), AnimatSim::Robotics::RobotIOControl::Initialize(), and LoadIOControl().

Referenced by AddItem().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool AnimatSim::Robotics::RobotInterface::AddItem ( const std::string &  strItemType,
const std::string &  strXml,
bool  bThrowError = true,
bool  bDoNotInit = false 
)
virtual

Adds a new object to this parent.

Generic method to add a new child item to this parent by specifying a string item type descriptor and an xml packet that can be used to load in the new object. The GUI uses this method to create new items that were added with the user interface. The item type lets the method determine what type of item is being created, like synapse, neuron, body part, etc.. It then gets the modulename, classname, and type from the xml and calls CreateObject to create the appropriate type of object. Then it passes in the xml packet to the new objects load method and does any needed initialization and adds it to the parent.

Author
dcofer
Date
2/22/2011
Parameters
strItemTypeString descriptor of the type of item that is being created.
strXmlXML packet that is used to create and load the new item.
bThrowErrorIf true then throw an error if there is a problem, otherwise return false.
Returns
true if it succeeds, false if it fails.

Reimplemented from AnimatSim::AnimatBase.

Definition at line 197 of file RobotInterface.cpp.

References AddIOControl(), and StdUtils::Std_CheckString().

+ Here is the call graph for this function:

void AnimatSim::Robotics::RobotInterface::AfterResetSimulation ( )
virtual

Called after a simulation reset for some objects.

This method is only used by some objects because they need to do some processing after the simulation has been reset.

Author
dcofer
Date
3/4/2011

Reimplemented from AnimatSim::AnimatBase.

Definition at line 330 of file RobotInterface.cpp.

References AnimatSim::AnimatBase::AfterResetSimulation(), m_aryIOControls, and AnimatSim::AnimatBase::m_bEnabled.

+ Here is the call graph for this function:

int AnimatSim::Robotics::RobotInterface::FindChildListPos ( std::string  strID,
bool  bThrowError = true 
)
protectedvirtual

Finds the array index for the child part with the specified ID.

Author
dcofer
Date
3/2/2011
Parameters
strIDID of part to find
bThrowErrorIf true and ID is not found then it will throw an error, else return NULL
Exceptions
IfbThrowError is true and ID is not found.
Returns
If bThrowError is false and ID is not found returns NULL, else returns the pointer to the found part.

Definition at line 289 of file RobotInterface.cpp.

References AnimatSim::AnimatBase::ID(), m_aryIOControls, StdUtils::Std_ToUpper(), and StdUtils::Std_Trim().

Referenced by RemoveIOControl().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

float * AnimatSim::Robotics::RobotInterface::GetDataPointer ( const std::string &  strDataType)
virtual

Returns a float pointer to a data item of interest in this object.

This is a generic method used to get a pointer to data variable of interest. It is used by a variety of systems in the simulation. The most prominent are the data charting and stimulus classes. Within this method we associate a variable with a string name. By passing in the name of the data type we are interested in we can recieve back a float pointer to that data type. We can use that to read or set the data item in other classes. For example, the data charting system gets the pointer and then each time it needs to log a data point it reads the value into an array.

Author
dcofer
Date
2/22/2011
Parameters
strDataTypename of the data item for which we are looking.
Returns
float pointer of the data item. If not found then it throws an exception.
Exceptions
IfDataType is not found.

Reimplemented from AnimatSim::AnimatBase.

Reimplemented in RoboticsAnimatSim::Robotics::RobotInterfaces::RbLANWirelessInterface.

Definition at line 147 of file RobotInterface.cpp.

References AnimatSim::AnimatBase::m_strName, and StdUtils::Std_CheckString().

+ Here is the call graph for this function:

void AnimatSim::Robotics::RobotInterface::Initialize ( )
virtual

Initializes this object.

After an object is loaded in it must be initialized before it can be used. This allows the object to retrieve any pointers or setup memory that it will need during execution. Each object is responsible for initializing any of its child objects, so you simply need to call this method on the containing class to init all child objects. It also calls VerifySystemPointers to make sure that the system pointers have been setup correctly.

Author
dcofer
Date
3/1/2011

Reimplemented from AnimatSim::AnimatBase.

Reimplemented in RoboticsAnimatSim::Robotics::RobotInterfaces::RbLANWirelessInterface.

Definition at line 306 of file RobotInterface.cpp.

References AnimatSim::AnimatBase::Initialize(), m_aryIOControls, and AnimatSim::AnimatBase::m_bEnabled.

Referenced by AnimatSim::Environment::Organism::AddRobotInterface(), and AnimatSim::Environment::Organism::Initialize().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

CStdPtrArray< RobotIOControl > * AnimatSim::Robotics::RobotInterface::IOControls ( )
virtual

Gets the array of IO controls.

Author
dcofer
Date
3/2/2011
Returns
pointer to array of IO controls.

Definition at line 88 of file RobotInterface.cpp.

References m_aryIOControls.

RobotIOControl * AnimatSim::Robotics::RobotInterface::LoadIOControl ( CStdXml oXml)
protectedvirtual

Loads a child IO Control.

Author
dcofer
Date
3/2/2011
Parameters
[in,out]oXmlThe xml data definition of the part to load.
Returns
null if it fails, else the IO control.

Definition at line 392 of file RobotInterface.cpp.

References AnimatSim::Simulator::CreateObject(), StdUtils::CStdXml::GetChildString(), StdUtils::CStdXml::IntoElem(), m_aryIOControls, AnimatSim::AnimatBase::m_lpSim, AnimatSim::AnimatBase::m_lpStructure, StdUtils::CStdXml::OutOfElem(), AnimatSim::Robotics::RobotIOControl::ParentInterface(), and AnimatSim::AnimatBase::SetSystemPointers().

Referenced by AddIOControl().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

float AnimatSim::Robotics::RobotInterface::PhysicsTimeStep ( )
virtual

Gets the physics time step used within the robot framwork.

Author
dcofer
Date
4/25/2014
Returns
Gets physics time step.

Definition at line 98 of file RobotInterface.cpp.

References m_fltPhysicsTimeStep.

Referenced by SetData().

+ Here is the caller graph for this function:

void AnimatSim::Robotics::RobotInterface::PhysicsTimeStep ( float  fltStep)
virtual

Sets the physics time step used within the robot framwork.

Author
dcofer
Date
4/25/2014
Parameters
bValSets physics time step.

Definition at line 108 of file RobotInterface.cpp.

References m_fltPhysicsTimeStep, and StdUtils::Std_IsAboveMin().

+ Here is the call graph for this function:

void AnimatSim::Robotics::RobotInterface::QueryProperties ( CStdPtrArray< TypeProperty > &  aryProperties)
virtual

Queries this object for a list of properties that can be changed using SetData.

The method provides a list of the properties that can be set using the SetData method. It gives the property name and the type of data that should be passed to it. Valid date types are Boolean, Float, Integer, and Xml.

Author
dcofer
Date
2/22/2011
Parameters
aryNamesArray list of the property names.
strTypesArray list of the type that is associated with the cooresponding name in the list.
Returns
Nothing.

Reimplemented from AnimatSim::AnimatBase.

Definition at line 191 of file RobotInterface.cpp.

References AnimatSim::AnimatBase::QueryProperties().

+ Here is the call graph for this function:

void AnimatSim::Robotics::RobotInterface::RemoveIOControl ( std::string  strID,
bool  bThrowError = true 
)
protectedvirtual

Removes the rigid body with the specified ID.

Author
dcofer
Date
3/2/2011
Parameters
strIDID of the body to remove
bThrowErrorIf true and ID is not found then it will throw an error.
Exceptions
IfbThrowError is true and ID is not found.

Definition at line 263 of file RobotInterface.cpp.

References FindChildListPos(), m_aryIOControls, and AnimatSim::Robotics::RobotIOControl::ShutdownIO().

Referenced by RemoveItem().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool AnimatSim::Robotics::RobotInterface::RemoveItem ( const std::string &  strItemType,
const std::string &  strID,
bool  bThrowError = true 
)
virtual

Removes a child item from this parent.

This is a generic method that is used to delete a child object from this parent. The GUI uses this method to remove objects from the simulation that have been deleted in the UI. The item type lets the method determine what type of item is being deleted, like synapse, neuron, body part, etc.. The ID is then used to delete that specific item.

Author
dcofer
Date
2/22/2011
Parameters
strItemTypeString descriptor of the type of item that is being created.
strIDUnique ID of the item that will be removed.
bThrowErrorIf true then throw an error if there is a problem, otherwise return false.
Returns
true if it succeeds, false if it fails.

Reimplemented from AnimatSim::AnimatBase.

Definition at line 214 of file RobotInterface.cpp.

References RemoveIOControl(), and StdUtils::Std_CheckString().

+ Here is the call graph for this function:

void AnimatSim::Robotics::RobotInterface::ResetSimulation ( )
virtual

Resets the simulation back to time 0.

This method calls the ResetSimulation method on all subitems in order to reset the simulation back to the beginning.

Author
dcofer
Date
3/1/2011

Reimplemented from AnimatSim::AnimatBase.

Definition at line 318 of file RobotInterface.cpp.

References m_aryIOControls, AnimatSim::AnimatBase::m_bEnabled, and AnimatSim::AnimatBase::ResetSimulation().

Referenced by AnimatSim::Environment::Organism::ResetSimulation().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool AnimatSim::Robotics::RobotInterface::SetData ( const std::string &  strDataType,
const std::string &  strValue,
bool  bThrowError = true 
)
virtual

Set a variable based on a string data type name.

This is a generic method that can be used to set any variable in an AnimatBase object by specifying the name of the variable and a string representation of that data. The GUI uses this method to set data into variables in the simulation when the user changes them in the UI. The value string can be as simple as a float or int, or as complex as an xml packet. It is the developers responsibilty to know what type of data is needed and to process it accordingly.

Author
dcofer
Date
2/22/2011
Parameters
strDataTypestring name of the data type to set.
strValueThe string value of the data. It is up to the developer to determine what this should be. For example, in most cases it is simply a float and you just have to convert it to a float and make the appropriate mutator method call. However, it can be any type of string, including an entire xml packet. It is the developers responsibility to know how to set and process the data as required.
bThrowErrortrue to throw error if there is a problem. If false then it will not return an error, just return false.
Returns
true if it succeeds, false if it fails.

Reimplemented from AnimatSim::AnimatBase.

Reimplemented in RoboticsAnimatSim::Robotics::RobotInterfaces::RbLANWirelessInterface.

Definition at line 159 of file RobotInterface.cpp.

References AnimatSim::AnimatBase::Enabled(), PhysicsTimeStep(), AnimatSim::AnimatBase::SetData(), StdUtils::Std_CheckString(), StdUtils::Std_ToBool(), and SynchSim().

+ Here is the call graph for this function:

void AnimatSim::Robotics::RobotInterface::StepSimulation ( )
virtual

Step the simulation for this object.

This is called on an object each time it is stepped in the simulation. this is where its simulation code is processed. However, StepSimulation is not necessarily called every single time that the simulation as a whole is stepped. A good example of this is that neural modules can have different integration time steps. So a firing rate module may have a DT of 0.5 ms, while an integrate and fire model may have one of 0.1 ms. So the firing rate module would only get its StepSimulation method called every 5th time that the other module was called. This is all handed in the StepSimulation method of the Simulator and NervousSystem.

Author
dcofer
Date
3/1/2011

Reimplemented from AnimatSim::AnimatBase.

Reimplemented in RoboticsAnimatSim::Robotics::RobotInterfaces::RbLANWirelessInterface.

Definition at line 342 of file RobotInterface.cpp.

References AnimatSim::AnimatBase::Enabled(), m_aryIOControls, AnimatSim::AnimatBase::m_bEnabled, and AnimatSim::AnimatBase::StepSimulation().

Referenced by AnimatSim::Environment::Organism::StepPhysicsEngine().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool AnimatSim::Robotics::RobotInterface::SynchSim ( )
virtual

Gets whether we need to delay stepping of the physics adapters in the simulation to more closely match the real robot behavior.

Author
dcofer
Date
5/13/2014
Returns
Gets whether we will attempt to synch sim update to robots update.

Definition at line 122 of file RobotInterface.cpp.

References m_bSynchSim.

Referenced by SetData(), AnimatSim::Environment::MotorizedJoint::SetPosition(), and AnimatSim::Environment::MotorizedJoint::SetVelocity().

+ Here is the caller graph for this function:

void AnimatSim::Robotics::RobotInterface::SynchSim ( bool  bVal)
virtual

Sets whether we need to delay stepping of the physics adapters in the simulation to more closely match the real robot behavior.

Author
dcofer
Date
5/13/2014
Parameters
bValnew value.

Definition at line 132 of file RobotInterface.cpp.

References AnimatSim::Simulator::InSimulation(), m_bSynchSim, AnimatSim::AnimatBase::m_lpSim, and AnimatSim::Simulator::RobotAdpaterSynch().

+ Here is the call graph for this function:

Member Data Documentation

CStdPtrArray<RobotIOControl> AnimatSim::Robotics::RobotInterface::m_aryIOControls
protected

A list of child parts that are connected to this part through different joints.

Definition at line 29 of file RobotInterface.h.

Referenced by AfterResetSimulation(), FindChildListPos(), Initialize(), IOControls(), LoadIOControl(), RemoveIOControl(), ResetSimulation(), StepSimulation(), and ~RobotInterface().

bool AnimatSim::Robotics::RobotInterface::m_bSynchSim
protected

If this is true and we are in simulation mode then we will set some flags in the simulation object to make it delay stepping of the physics adapter objects to more closely match the IO time step of the real robot.

Definition at line 39 of file RobotInterface.h.

Referenced by RobotInterface(), and SynchSim().

float AnimatSim::Robotics::RobotInterface::m_fltPhysicsTimeStep
protected

This is the physics time step used by the robotics framework. This is not necessarily the same thing as the physics time step used in the simulation because the robot IO is not going to be able to go as fast as we will need the sim steps to go for it to be stable.

Definition at line 34 of file RobotInterface.h.

Referenced by PhysicsTimeStep(), and RobotInterface().


The documentation for this class was generated from the following files: