RTT::SimulationThread Class Reference

This thread is the simulated real-time periodic thread in the Orocos system. More...

#include <rtt/SimulationThread.hpp>

Inheritance diagram for RTT::SimulationThread:
RTT::TimerThread RTT::OS::PeriodicThread RTT::OS::ThreadInterface

List of all members.

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 in Seconds.
bool setPeriod (secs s, nsecs ns)
bool setPeriod (TIME_SPEC p)
 Set the periodicity of this thread.
void getPeriod (secs &s, nsecs &ns) const
virtual Seconds getPeriod () const
 Get the periodicity in Seconds.
virtual nsecs getPeriodNS () const
 Get the periodicity in nanoseconds.
virtual bool isActive () const
 Returns whether the thread is active.
virtual const char * getName () const
 Read the name of this task.
virtual RTOS_TASK * getTask ()
 Get the RTOS_TASK pointer.
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 (put 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 (within the same process).

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.

Detailed Description

This thread is the simulated real-time periodic thread in the Orocos system.

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.

See also:
TimerThread

Definition at line 69 of file SimulationThread.hpp.


Member Function Documentation

virtual Seconds RTT::OS::PeriodicThread::getPeriod (  )  const [virtual, inherited]

Get the periodicity in Seconds.

Return zero if non periodic.

Implements RTT::OS::ThreadInterface.

virtual nsecs RTT::OS::PeriodicThread::getPeriodNS (  )  const [virtual, inherited]

Get the periodicity in nanoseconds.

Return zero if non periodic.

Implements RTT::OS::ThreadInterface.

virtual int RTT::OS::PeriodicThread::getPriority (  )  const [virtual, inherited]

The priority of this Thread.

Returns:
The priority given upon construction of this thread or set with setPriority. The returned number has to be interpreted in the current OS scheduler.
See also:
setScheduler

Implements RTT::OS::ThreadInterface.

virtual int RTT::OS::PeriodicThread::getScheduler (  )  const [virtual, inherited]

Get the scheduler policy in which this thread runs.

Returns:
An OS-specific value which represents the used scheduler.
See also:
setScheduler

Implements RTT::OS::ThreadInterface.

virtual RTOS_TASK* RTT::OS::PeriodicThread::getTask (  )  [inline, virtual, inherited]

Get the RTOS_TASK pointer.

Note:
Using this function leads to non-portable code. It is here for users which wish to tweak OS specific thread settings.

Implements RTT::OS::ThreadInterface.

Definition at line 119 of file PeriodicThread.hpp.

static SimulationThreadPtr RTT::SimulationThread::Instance ( double  period = 0.001  )  [static]

Create the SimulationThread with a given period.

Only one SimulationThread can be created.

Parameters:
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.
virtual bool RTT::OS::PeriodicThread::isActive (  )  const [virtual, inherited]

Returns whether the thread is active.

A thread is active between the invocation of start() and the invocation of stop().

Implements RTT::OS::ThreadInterface.

static bool RTT::SimulationThread::Release (  )  [static]

Releases the SimulationThread Reference counting might aid in making this call safe.

Returns:
true on success, false on failure
virtual bool RTT::OS::PeriodicThread::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.

Parameters:
r The object to run or zero to clear.
Returns:
true if accepted, false if the thread is running.

Implements RTT::OS::ThreadInterface.

virtual bool RTT::SimulationThread::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.

Returns:
false if maxsteps == 0
Postcondition:
When run() returns, step() has been called maxsteps times.
bool RTT::OS::PeriodicThread::setPeriod ( Seconds  new_period  )  [virtual, inherited]

Set the periodicity in Seconds.

Parameters:
new_period A positive number expressing the period
Returns:
true if it was accepted, false otherwise.

Implements RTT::OS::ThreadInterface.

virtual bool RTT::OS::PeriodicThread::setPriority ( int  priority  )  [virtual, inherited]

Set the priority of this Thread.

Parameters:
priority The priority given upon construction of this thread. It has to be interpreted in the current OS scheduler.
See also:
setScheduler

Implements RTT::OS::ThreadInterface.

virtual bool RTT::OS::PeriodicThread::setScheduler ( int  sched_type  )  [virtual, inherited]

Change the scheduler policy in which this thread runs.

Parameters:
sched_type An OS-specific value which selects a scheduler. Orocos requires that these two values are available:

  • ORO_SCHED_RT: Hint the OS that this thread should be scheduled as a priority or real-time process.
  • ORO_SCHED_OTHER: Hint the OS that this thread should not be scheduled as a priority or real-time process.

Your OS can in addition provide other sched_type's which map more naturally to the schedulers present. If your OS does not make a distinction between real-time and other, both values may map to the same scheduler type.

Returns:
true if the change could be made.

Implements RTT::OS::ThreadInterface.

virtual bool RTT::OS::PeriodicThread::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().

virtual bool RTT::SimulationThread::start ( unsigned int  maxsteps  )  [virtual]

Only run the simulation maxsteps time steps, then stop the SimulationThread.

Returns:
false if maxsteps == 0 or if thread could not be started.
virtual bool RTT::SimulationThread::start (  )  [virtual]

Start the Thread.

Postcondition:
initialize() is called first
The Thread is running
Returns:
true if the function did succeed. false otherwise.

Reimplemented from RTT::OS::PeriodicThread.

virtual bool RTT::OS::PeriodicThread::stop (  )  [virtual, inherited]

Stop the Thread.

Postcondition:
The Thread is no longer being run
finalize() is called when the Thread is stopped.
Returns:
true if the function did succeed. false otherwise.

Implements RTT::OS::ThreadInterface.

void RTT::OS::PeriodicThread::terminate (  )  [inherited]

Exit and destroy the thread.

Precondition:
this is only called from within the destructor.
Postcondition:
the thread does no longer exist.

Member Data Documentation

OS::MutexRecursive RTT::TimerThread::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.

int RTT::OS::ThreadInterface::threadnb [protected, inherited]

Threads are given an unique number, which follows thread creation order.

See also:
OS::threads

Definition at line 191 of file ThreadInterface.hpp.


The documentation for this class was generated from the following file:
Generated on Thu Dec 23 13:22:44 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3