RobWorkProject  21.8.23-
Public Types | Public Member Functions | Public Attributes | List of all members
ThreadSimulator Class Reference

Wraps a simulator in a thread safe interface, and creates a separate thread for the simulator to run in. More...

#include <ThreadSimulator.hpp>

Public Types

typedef rw::core::Ptr< ThreadSimulatorPtr
 smart pointer type
 
typedef boost::function< void(ThreadSimulator *sim, rw::kinematics::State &) > StepCallback
 The callback type for a hook into the step call.
 

Public Member Functions

 ThreadSimulator (rwlibs::simulation::Simulator::Ptr simulator)
 constructor - using the default workcell state as starting state
 
 ThreadSimulator (rwlibs::simulation::Simulator::Ptr simulator, const rw::kinematics::State &state)
 constructor
 
virtual ~ThreadSimulator ()
 destructor
 
void setRealTimeScale (double scale)
 This can be used to scale simulation time relative to Real World time. A scale of 1.0 makes the simulation run real time (if possible). A scale of 0.5 makes the simulation run twice as fast as real time, where a scale of 2 makes the simulation twice as slow. More...
 
void setTimeStep (double dt)
 sets the timestep that will be used for the calls to the step function of the simulator More...
 
void start ()
 starts the simulator constraining it too the specified period
 
void stop ()
 tries to stop the simulation and blocks until the thread is stopped
 
void postStop ()
 same as stop but this version is non-blocking.
 
void step ()
 step the simulation one timestep
 
rw::kinematics::State getState ()
 get the current state of the simuation More...
 
void setState (const rw::kinematics::State &state)
 set the state of the simulator More...
 
void reset (const rw::kinematics::State &state)
 reset the simulator to this state. The difference from the setState is that any changes to the non state-states such as the transform of the fixed frame, will also be updated. More...
 
bool isRunning ()
 test if this thread simulator is running
 
double getTime ()
 get the current simulator time in seconds
 
DynamicSimulator::Ptr getSimulator ()
 gets a pointer to the simulator. Make sure to stop the simulation before calling this function, otherwise an exception will be thrown. More...
 
void setStepCallBack (StepCallback cb)
 if set this callback function will be called once on start and then after each step of the simulator. More...
 
bool isInError ()
 the simulator might fail because of too large penetrations. This method tests if the simulator is in an error.
 
void setInError (bool inError)
 this can be used to force the resetting of an error state. More...
 

Public Attributes

boost::mutex _simMutex
 
boost::mutex _stateMutex
 

Detailed Description

Wraps a simulator in a thread safe interface, and creates a separate thread for the simulator to run in.

Member Function Documentation

◆ getSimulator()

DynamicSimulator::Ptr getSimulator ( )
inline

gets a pointer to the simulator. Make sure to stop the simulation before calling this function, otherwise an exception will be thrown.

Returns
pointer to simulator

◆ getState()

rw::kinematics::State getState ( )

get the current state of the simuation

Returns

◆ reset()

void reset ( const rw::kinematics::State state)

reset the simulator to this state. The difference from the setState is that any changes to the non state-states such as the transform of the fixed frame, will also be updated.

Parameters
state[in] the new state

◆ setInError()

void setInError ( bool  inError)
inline

this can be used to force the resetting of an error state.

Parameters
inError

◆ setRealTimeScale()

void setRealTimeScale ( double  scale)
inline

This can be used to scale simulation time relative to Real World time. A scale of 1.0 makes the simulation run real time (if possible). A scale of 0.5 makes the simulation run twice as fast as real time, where a scale of 2 makes the simulation twice as slow.

1 simTime -> max( realtime * scale , simDelayInRealTime )

Parameters
scale[in]

◆ setState()

void setState ( const rw::kinematics::State state)

set the state of the simulator

Parameters
state[in] the new state

◆ setStepCallBack()

void setStepCallBack ( StepCallback  cb)
inline

if set this callback function will be called once on start and then after each step of the simulator.

Set to NULL if no callback is wanted

◆ setTimeStep()

void setTimeStep ( double  dt)

sets the timestep that will be used for the calls to the step function of the simulator

Parameters
dt

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