8 #include "IMovableItemCallback.h"
9 #include "ISimGUICallback.h"
10 #include "IMotorizedJoint.h"
15 #include "IPhysicsMovableItem.h"
16 #include "IPhysicsBody.h"
18 #include "MovableItem.h"
43 #include "RobotPartInterface.h"
85 {
Std_TraceMsg(0,
"Caught Error in desctructor of RobotIOControl\r\n",
"", -1,
false,
true);}
116 void RobotIOControl::PauseIO(
bool bVal)
122 bool RobotIOControl::PauseIO() {
return m_bPauseIO;}
124 bool RobotIOControl::IOPaused() {
return m_bIOPaused;}
146 #pragma region DataAccesMethods
152 if(strType ==
"STEPIODURATION")
155 THROW_TEXT_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType,
"Robot Interface ID: " + STR(
m_strName) +
" DataType: " + strDataType);
167 if(strType ==
"ENABLED")
175 THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType,
"Data Type", strDataType);
184 aryProperties.Add(
new TypeProperty(
"StepIODuration", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
191 if(strType ==
"ROBOTPARTINTERFACE")
199 THROW_PARAM_ERROR(Al_Err_lInvalidItemType, Al_Err_strInvalidItemType,
"Item Type", strItemType);
208 if(strType ==
"ROBOTPARTINTERFACE")
216 THROW_PARAM_ERROR(Al_Err_lInvalidItemType, Al_Err_strInvalidItemType,
"Item Type", strItemType);
281 for(
int iIndex=0; iIndex<iCount; iIndex++)
286 THROW_PARAM_ERROR(Al_Err_lPartInterfaceIDNotFound, Al_Err_strPartInterfaceIDNotFound,
"ID", strID);
293 void RobotIOControl::StartIOThread()
300 boost::posix_time::ptime pt = boost::posix_time::microsec_clock::universal_time() + boost::posix_time::seconds(iWaitTime);
302 boost::interprocess::scoped_lock<boost::interprocess::interprocess_mutex> lock(
m_WaitForIOSetupMutex);
305 m_ioThread = boost::thread(&RobotIOControl::ProcessIO,
this);
307 std::cout <<
"Waiting for IO thread return\r\n";
313 std::cout <<
"IO thread Timed out\r\n";
315 THROW_ERROR(Al_Err_lErrorSettingUpIOThread, Al_Err_strErrorSettingUpIOThread);
318 std::cout <<
"IO thread returned\r\n";
321 void RobotIOControl::WaitForThreadNotifyReady()
325 boost::this_thread::sleep(boost::posix_time::microseconds(500));
328 void RobotIOControl::ProcessIO()
338 WaitForThreadNotifyReady();
348 boost::this_thread::sleep(boost::posix_time::microseconds(1000));
369 void RobotIOControl::ExitIOThread()
371 TRACE_DEBUG(
"ExitIOThread.");
381 TRACE_DEBUG(
"Joint Thread.\r\n");
383 bool bTryJoin =
false;
384 #if (BOOST_VERSION >= 105000)
385 bTryJoin =
m_ioThread.try_join_for(boost::chrono::seconds(30));
409 for(
int iIndex=0; iIndex<iCount; iIndex++)
418 boost::this_thread::sleep(boost::posix_time::microseconds(1000));
423 boost::this_thread::sleep(boost::posix_time::microseconds(1000));
437 unsigned long long lStepStartTick =
m_lpSim->GetTimerTick();
440 for(
int iIndex=0; iIndex<iCount; iIndex++)
444 unsigned long long lEndStartTick =
m_lpSim->GetTimerTick();
464 boost::this_thread::sleep(boost::posix_time::microseconds(1000));
478 boost::this_thread::sleep(boost::posix_time::microseconds(1000));
496 boost::this_thread::sleep(boost::posix_time::microseconds(1000));
514 boost::this_thread::sleep(boost::posix_time::microseconds(1000));
537 for(
int iIndex=0; iIndex<iCount; iIndex++)
561 for(
int iIndex=0; iIndex<iCount; iIndex++)
574 for(
int iIndex=0; iIndex<iCount; iIndex++)
586 for(
int iIndex=0; iIndex<iCount; iIndex++)
605 for(
int iIndex=0; iIndex<iCount; iIndex++)
611 void RobotIOControl::Load(
CStdXml &oXml)
622 for(
int iIndex=0; iIndex<iChildCount; iIndex++)
658 THROW_TEXT_ERROR(Al_Err_lConvertingClassToType, Al_Err_strConvertingClassToType,
"RobotPartInterface");
660 lpChild->ParentIOControl(
this);
671 if(lpChild)
delete lpChild;
677 if(lpChild)
delete lpChild;
678 THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
virtual void ResetSimulation()
Resets the simulation back to time 0.
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.
Declares the simulation recorder class.
Declares the Robot IO control interface base class.
virtual void SetSystemPointers(Simulator *lpSim, Structure *lpStructure, NeuralModule *lpModule, Node *lpNode, bool bVerify)
Sets the system pointers.
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.
Root namespace for the base simulation library for AnimatLab.
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
virtual void Initialize()
Initializes this object.
Declares the body part class.
RobotIOControl(void)
Default constructor.
virtual void StepSimulation()
Step the simulation for this object.
virtual bool FindElement(std::string strElementName, bool fThrowError=true)
Finds an element with the specified name.
Simulator * m_lpSim
The pointer to a Simulation.
virtual bool Paused()
Gets whether the Simulation is paused.
Information about the standard error.
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.
boost::interprocess::interprocess_condition m_WaitForIOSetupCond
Condition used to determine when the IO is setup.
virtual void Initialize()
Initializes this object.
virtual CStdPtrArray< RobotPartInterface > * Parts()
Gets the array of IO controls.
Class that stores information about types for QueryProperty information.
bool m_bStopIO
Flags the thread processing loop to exit.
Declares the link base class.
virtual void AfterResetSimulation()
Called after a simulation reset for some objects.
Declares the key frame class.
virtual void ExitPause()
This method is waits until the m_bIOPaused flag is set back to false.
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 ~RobotIOControl(void)
Destructor.
Declares the joint class.
Declares the organism class.
bool m_bWaitingForThreadNotify
Used to signal to the IO thread that we are waiting for their return signal.
virtual void StepIO()
This method is called from within the IO thread. It calls StepIO for each part.
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 void ShutdownIO()
This method is called just before the IO thread is closed down. It gives the IO objects a chance to d...
std::string Std_Trim(std::string strVal)
Trims a string.
boost::thread m_ioThread
Thread responsible for doing IO processing.
Declares the activated item class.
virtual CStdSerialize * CreateObject(std::string strModule, std::string strClassName, std::string strType, bool bThrowError=true)
Creates an object using a class factory.
virtual RobotPartInterface * LoadPartInterface(CStdXml &oXml)
Loads a child IO Control.
virtual float * GetDataPointer(const std::string &strDataType)
Returns a float pointer to a data item of interest in this object.
Declares a light manager object.
RobotInterface * m_lpParentInterface
Pointer to the parent robot interface.
Declares the bounding box class.
virtual std::string Name()
Gets the name of this object.
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.
A standard xml manipulation class.
virtual void WaitTillPaused()
This method is waits until the m_bIOPaused flag is set to true.
virtual void StepSimulation()
Step the simulation for this object.
virtual RobotPartInterface * AddPartInterface(std::string strXml)
Creates and adds a robot IO control.
virtual void SimStopping()
Called just before the simulation stops.
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
virtual std::string GetChildString(std::string strElementName)
Gets a string value from the element with the specified name.
virtual void ResetSimulation()
Resets the simulation back to time 0.
bool m_bIOPaused
Is set to true once the IO loop is paused.
bool Std_ToBool(int iVal)
Converts a value toa bool.
virtual void Load(StdUtils::CStdXml &oXml)
Loads the item using an XML data packet.
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.
CStdPtrArray< RobotPartInterface > m_aryParts
bool m_bEnabled
Tells if this item is enabled or not. If it is not enabled then it is not run.
virtual int NumberOfChildren()
Gets the number of children of the current element.
bool m_bPauseIO
Set to true to pause the IO processing. Set back to false to resume it.
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
int m_iCyclePartIdx
The index of the part that should be processed on the current step.
virtual int FindChildListPos(std::string strID, bool bThrowError=true)
Finds the array index for the child part with the specified ID.
Declares the data chart manager class.
virtual void SetupIO()
This method is called after all connections to whatever control board have been made. It calls each parts SetupIO method. For example, We connect to a Firmata microcontroller like an Arduino, and then do a setup that could take some time. We should not attempt to setup any of the pins until after the board itself has been setup. After that we need to loop through and setup all the parts.
int m_iCyclePartCount
The total number of parts that are part of any round robin cycle of updates.
Declares the rigid body class.
boost::interprocess::interprocess_mutex m_WaitForIOSetupMutex
Mutex responsible for waiting until the IO is finished setting up.
virtual void AfterResetSimulation()
Called after a simulation reset for some objects.
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
virtual void SimStopping()
Called just before the simulation stops.
Declares the structure class.
float m_fltStepIODuration
The time it takes to perform a step of the IO for all parts in this control.
Declares the odor type class.
virtual void RemovePartInterface(std::string strID, bool bThrowError=true)
Removes the rigid body with the specified ID.
bool m_bIOThreadProcessing
True while the io thread processing loop is going on.
virtual bool RemoveItem(const std::string &strItemType, const std::string &strID, bool bThrowError=true)
Removes a child item from this parent.
bool m_bSetupComplete
Set to true once the IO is setup correctly.
virtual RobotInterface * ParentInterface()
Gets the parent robot interface pointer.
Declares the robotics inerface for animatlab.
Declares the simulator class.
Declares the neural module class.
virtual bool FindChildByIndex(int iIndex, bool bThrowError=true)
Finds a child element by index.
std::string Std_ToUpper(std::string strVal)
Converts a string to upper case.
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.
virtual float StepIODuration()
Gets the time duration required to perform one step of the IO for all parts in this control...
virtual void WaitWhilePaused()
This method is waits until the m_bPauseIO flag is set back to false.
virtual void StartPause()
This method is waits until the m_bIOPaused flag is set to true.
virtual bool AddItem(const std::string &strItemType, const std::string &strXml, bool bThrowError=true, bool bDoNotInit=false)
Adds a new object to this parent.
Declares the receptive field class.
The Robotics interface configures a simulation to run on a microcontroller board. ...
std::string m_strName
The name for this object.
bool m_bSetupStarted
Set to true once the IO begins its setup.