#include <rtt/SimulationThread.hpp>

It behaves (to the SimulationActivity) like a perfect scheduler by executing all activities one after the other in a continuous loop and updating the system time, such that it appears to the activities as they are executed periodically.
All your activities in the same program must be a SimulationActivity for this to work, since the TimeService global time is updated when this thread runs.
By default, the update period is 0.001 seconds. If you want to run with a finer or coarser grained time step, use the Instance() method and supply another period before SimulationActivities are created.
Definition at line 69 of file SimulationThread.hpp.
Public Types | |
| typedef double | Seconds |
| typedef long | secs |
| typedef long | msecs |
| typedef long long | nsecs |
Public Member Functions | |
| virtual | ~SimulationThread () |
| Destructor. | |
| virtual bool | start () |
| Start the thread. | |
| virtual bool | isRunning () const |
| Returns true if thread is running or run( unsigned int ) is being invoked. | |
| virtual bool | start (unsigned int maxsteps) |
| Only run the simulation maxsteps time steps, then stop the SimulationThread. | |
| virtual bool | run (unsigned int maxsteps) |
| Execute maxsteps steps immediately. | |
| bool | addActivity (PeriodicActivity *t) |
| Add an Timer that will be ticked every execution period Once added, a timer can not be removed. | |
| bool | removeActivity (PeriodicActivity *t) |
| virtual bool | run (OS::RunnableInterface *r) |
| Run the functionality of one RunnableInterface object. | |
| virtual bool | stop () |
| Stop the thread. | |
| bool | setPeriod (Seconds s) |
| Set the periodicity of this thread in seconds. | |
| bool | setPeriod (secs s, nsecs ns) |
| Set the periodicity of this thread (seconds, nanoseconds). | |
| bool | setPeriod (TIME_SPEC p) |
| Set the periodicity of this thread. | |
| void | getPeriod (secs &s, nsecs &ns) const |
| Get the periodicity of this thread (seconds, nanoseconds). | |
| virtual Seconds | getPeriod () const |
| Get the periodicity of this thread in seconds. | |
| virtual nsecs | getPeriodNS () const |
| Get the periodicity of this thread in nano-seconds. | |
| virtual const char * | getName () const |
| Read the name of this task. | |
| virtual RTOS_TASK * | getTask () |
| Get the RTOS_TASK pointer FIXME should this be a const? | |
| virtual bool | setScheduler (int sched_type) |
| Change the scheduler policy in which this thread runs. | |
| virtual int | getScheduler () const |
| Get the scheduler policy in which this thread runs. | |
| virtual bool | setPriority (int priority) |
| Set the priority of this Thread. | |
| virtual int | getPriority () const |
| The priority of this Thread. | |
| virtual void | yield () |
| Yields (but to the back of the scheduler queue) the calling thread. | |
| void | setMaxOverrun (int m) |
| int | getMaxOverrun () const |
| void | terminate () |
| Exit and destroy the thread. | |
| void | emergencyStop () |
| unsigned int | threadNumber () const |
| The unique thread number. | |
Static Public Member Functions | |
| static SimulationThreadPtr | Instance (double period=0.001) |
| Create the SimulationThread with a given period. | |
| static bool | Release () |
| Releases the SimulationThread Reference counting might aid in making this call safe. | |
| static TimerThreadPtr | Instance (int priority, double periodicity) |
| Create a TimerThread with a given priority and periodicity, using the default scheduler, ORO_SCHED_RT. | |
| static TimerThreadPtr | Instance (int scheduler, int priority, double periodicity) |
| Create a TimerThread with a given scheduler, priority and periodicity. | |
Static Public Attributes | |
| static const unsigned int | MAX_ACTIVITIES = 64 |
Protected Types | |
|
typedef std::vector < boost::weak_ptr< TimerThread > > | TimerThreadList |
| A Boost weak pointer is used to store non-owning pointers to shared objects. | |
Protected Member Functions | |
| bool | initialize () |
| void | step () |
| void | finalize () |
| SimulationThread (double period) | |
| Constructor. | |
| void | reorderList () |
| virtual void | continuousStepping (bool yes_no) |
| virtual bool | setToStop () |
| Use this from within step() to stop this thread. | |
Protected Attributes | |
| OS::MutexRecursive | mutex |
| A Activity can not create a activity of same priority from step(). | |
| int | threadnb |
| Threads are given an unique number, which follows thread creation order. | |
Static Protected Attributes | |
| static TimerThreadList | TimerThreads |
| All timer threads. | |
| SimulationThreadPtr Instance | ( | double | period = 0.001 |
) | [static] |
Create the SimulationThread with a given period.
Only one SimulationThread can be created.
| period | The period in seconds at which the simulation takes steps and updates the TimeService. Only the first invocation of Instance will consider this parameter. The others will ignore it. |
Definition at line 67 of file SimulationThread.cpp.
References SimulationThread::SimulationThread().
| bool Release | ( | ) | [static] |
Releases the SimulationThread Reference counting might aid in making this call safe.
Definition at line 77 of file SimulationThread.cpp.
| bool start | ( | unsigned int | maxsteps | ) | [virtual] |
Only run the simulation maxsteps time steps, then stop the SimulationThread.
Definition at line 112 of file SimulationThread.cpp.
References PeriodicThread::start().
| bool run | ( | unsigned int | maxsteps | ) | [virtual] |
Execute maxsteps steps immediately.
This function will call the step() functions maxsteps times, without requiring start() or stop() to be called before or after. The thread is thus not used.
Definition at line 120 of file SimulationThread.cpp.
References PeriodicThread::getPeriod(), SimulationThread::isRunning(), and TimeService::secondsChange().
| bool run | ( | OS::RunnableInterface * | r | ) | [virtual, inherited] |
Run the functionality of one RunnableInterface object.
Only one RunnableInterface object can be run, the old one is disconnected.
| r | The object to run or zero to clear. |
Implements ThreadInterface.
Definition at line 282 of file PeriodicThread.cpp.
References PeriodicThread::isRunning(), and RunnableInterface::setThread().
| bool setScheduler | ( | int | sched_type | ) | [virtual, inherited] |
Change the scheduler policy in which this thread runs.
| sched_type | An OS-specific value which selects a scheduler. Orocos requires that these two values are available: |
Implements ThreadInterface.
Definition at line 368 of file PeriodicThread.cpp.
References RTT::OS::CheckScheduler(), and PeriodicThread::getScheduler().
Referenced by SimulationThread::SimulationThread().
| int getScheduler | ( | ) | const [virtual, inherited] |
Get the scheduler policy in which this thread runs.
Implements ThreadInterface.
Definition at line 404 of file PeriodicThread.cpp.
Referenced by PeriodicThread::setScheduler().
| bool setPriority | ( | int | priority | ) | [virtual, inherited] |
Set the priority of this Thread.
| priority | The priority given upon construction of this thread. It has to be interpreted in the current OS scheduler. |
Implements ThreadInterface.
Definition at line 482 of file PeriodicThread.cpp.
| int getPriority | ( | ) | const [virtual, inherited] |
The priority of this Thread.
Implements ThreadInterface.
Definition at line 487 of file PeriodicThread.cpp.
Referenced by SimulationThread::SimulationThread().
| void terminate | ( | ) | [inherited] |
Exit and destroy the thread.
Definition at line 513 of file PeriodicThread.cpp.
| bool setToStop | ( | ) | [protected, virtual, inherited] |
Use this from within step() to stop this thread.
This function will call finalize() as well, thus it is advised to call this function as the last statement in your step().
Definition at line 526 of file PeriodicThread.cpp.
OS::MutexRecursive mutex [mutable, protected, inherited] |
A Activity can not create a activity of same priority from step().
If so a deadlock will occur.
Definition at line 132 of file TimerThread.hpp.
Referenced by TimerThread::addActivity().
int threadnb [protected, inherited] |
Threads are given an unique number, which follows thread creation order.
Definition at line 182 of file ThreadInterface.hpp.
Referenced by ThreadInterface::threadNumber().
1.5.6