8 #include "IMovableItemCallback.h"
9 #include "ISimGUICallback.h"
10 #include "IMotorizedJoint.h"
15 #include "IPhysicsMovableItem.h"
16 #include "IPhysicsBody.h"
18 #include "MovableItem.h"
41 #include "ThreadedModule.h"
80 {
Std_TraceMsg(0,
"Caught Error in desctructor of ThreadedModule\r\n",
"", -1,
false,
true);}
83 void ThreadedModule::PauseThread(
bool bVal)
103 #pragma region DataAccesMethods
109 if(strType ==
"STEPTHREADDURATION")
121 aryProperties.Add(
new TypeProperty(
"StepThreadDuration", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
126 void ThreadedModule::StartThread()
143 boost::posix_time::ptime pt = boost::posix_time::microsec_clock::universal_time() + boost::posix_time::seconds(iWaitTime);
145 boost::interprocess::scoped_lock<boost::interprocess::interprocess_mutex> lock(
m_WaitForSetupMutex);
148 m_Thread = boost::thread(&ThreadedModule::ProcessThread,
this);
150 std::cout <<
"Waiting for thread return\r\n";
156 std::cout <<
"Thread Timed out\r\n";
158 THROW_ERROR(Al_Err_lErrorSettingUpIOThread, Al_Err_strErrorSettingUpIOThread);
161 std::cout <<
"Thread returned\r\n";
164 void ThreadedModule::WaitForThreadNotifyReady()
168 boost::this_thread::sleep(boost::posix_time::microseconds(500));
171 void ThreadedModule::ProcessThread()
181 WaitForThreadNotifyReady();
191 boost::this_thread::sleep(boost::posix_time::microseconds(1000));
212 void ThreadedModule::ExitThread()
214 TRACE_DEBUG(
"ExitThread.");
224 TRACE_DEBUG(
"Joint Thread.\r\n");
226 bool bTryJoin =
false;
227 #if (BOOST_VERSION >= 105000)
228 bTryJoin =
m_Thread.try_join_for(boost::chrono::seconds(30));
250 boost::this_thread::sleep(boost::posix_time::microseconds(1000));
253 void ThreadedModule::CloseThread()
279 boost::this_thread::sleep(boost::posix_time::microseconds(1000));
293 boost::this_thread::sleep(boost::posix_time::microseconds(1000));
311 boost::this_thread::sleep(boost::posix_time::microseconds(1000));
329 boost::this_thread::sleep(boost::posix_time::microseconds(1000));
boost::thread m_Thread
Thread responsible for doing IO processing.
boost::interprocess::interprocess_condition m_WaitForSetupCond
Condition used to determine when the IO is setup.
Base class file for all Animat simulation objects.
Declares the nervous system class.
Declares the simulation recorder class.
virtual void StepThread()
This method is called from within the IO thread. It calls StepIO for each part.
bool m_bWaitingForThreadNotify
Used to signal to the IO thread that we are waiting for their return signal.
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.
Declares the body part class.
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
Simulator * m_lpSim
The pointer to a Simulation.
virtual bool Paused()
Gets whether the Simulation is paused.
Information about the standard error.
Class that stores information about types for QueryProperty information.
bool m_bPauseThread
Set to true to pause the thread processing. Set back to false to resume it.
Declares the link base class.
Declares the key frame class.
Declares the joint class.
Declares the organism class.
virtual void ExitPause()
This method is waits until the m_bIOPaused flag is set back to false.
ThreadedModule(void)
Default constructor.
virtual float StepThreadDuration()
Gets the time duration required to perform one step of the thread for all parts in this control...
virtual void StartPause()
This method is waits until the m_bIOPaused flag is set to true.
Declares the activated item class.
Declares a light manager object.
Declares the bounding box class.
virtual ~ThreadedModule(void)
Destructor.
bool m_bSetupStarted
Set to true once the thread begins its setup.
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
virtual void WaitWhilePaused()
This method is waits until the m_bPauseIO flag is set back to false.
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.
bool m_bThreadProcessing
True while the io thread processing loop is going on.
virtual void SetupThread()
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.
bool m_bEnabled
Tells if this item is enabled or not. If it is not enabled then it is not run.
virtual float * GetDataPointer(const std::string &strDataType)
Returns a float pointer to a data item of interest in this object.
bool m_bStopThread
Flags the thread processing loop to exit.
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.
boost::interprocess::interprocess_mutex m_WaitForSetupMutex
Mutex responsible for waiting until the IO is finished setting up.
Declares the structure class.
bool m_bSetupComplete
Set to true once the thread is setup correctly.
Declares the odor type class.
bool m_bThreadPaused
Is set to true once the thread loop is paused.
Declares the simulator class.
Declares the neural module class.
float m_fltStepThreadDuration
The time it takes to perform a step of the IO for all parts in this control.
Declares the activated item manager class.
Declares the external stimuli manager class.
virtual void WaitTillPaused()
This method is waits until the m_bIOPaused flag is set to true.
Declares the receptive field class.
virtual float * GetDataPointer(const std::string &strDataType)
Returns a float pointer to a data item of interest in this object.
virtual void ShutdownThread()
This method is called just before the IO thread is closed down. It gives the IO objects a chance to d...