Getting Time in component

Hi,

What is the way to play with time inside a component ? Is it something in
Orocos or should I use standard Linux services ?
Basically what I whant to do is to check for how long a data has not been
published in a port :

if(NewData==inPort(cmd))
{
// manage cmd
...
}
else
{
//if we didn't receive something for a long time go into panic !
....
}

I read this in the component builder manual :

4. Time Measurement and Conversion
4.1. The TimeService

The TimeService<http://www.orocos.org/stable/documentation/rtt/v2.x/api/html/classRTT_1_1os_1_1TimeService.html>is
implemented using the Singleton design pattern. You can query it for
the
current (virtual) time in clock ticks or in seconds. The idea here is that
it is responsible for synchronising with other (distributed) cores, for
doing, for example compliant motion with two robots. This functionality is
not yet implemented though.

When the SimulationThread<http://www.orocos.org/stable/documentation/rtt/v2.x/api/html/classRTT_1_1extras_1_1SimulationThread.html>is
used and started, it will change the TimeService's clock with each
period
( to simulate time progress). Also other threads (!) In the system will
notice this change, but time is guaranteed to increase monotonously.
4.2. Usage Example

Also take a look at the interface documentation.

#include <rtt/os/TimeService.hp

#include <rtt/Time.hp

TimeService::ticks timestamp = TimeService
<http://www.orocos.org/stable/documentation/rtt/v2.x/api/html/classRTT_1_1os_1_1TimeService.html>::Instance()->getTicks();
//...

Seconds elapsed = TimeService::Instance()->secondsSince( timestamp );

Is it still up to date ? Shall I use this ?

Ruben Smits's picture

Getting Time in component

On Wednesday 04 May 2011 16:35:36 Willy Lambert wrote:
> Hi,
>
> What is the way to play with time inside a component ? Is it something in
> Orocos or should I use standard Linux services ? Basically what I whant to
> do is to check for how long a data has not been published in a port :
>
> if(NewData==inPort(cmd))
> {
> // manage cmd
> ...
> }
> else
> {
> //if we didn't receive something for a long time go into panic !
> ....
> }
>
>
> I read this in the component builder manual :
>
> 4. Time Measurement and Conversion
> 4.1. The TimeService
>
> The
> TimeService<http://www.orocos.org/stable/documentation/rtt/v2.x/api/html/cl
> assRTT_1_1os_1_1TimeService.html> is implemented using the Singleton design
> pattern. You can query it for the current (virtual) time in clock ticks or
> in seconds. The idea here is that it is responsible for synchronising with
> other (distributed) cores, for doing, for example compliant motion with two
> robots. This functionality is not yet implemented though.
>
> When the
> SimulationThread<http://www.orocos.org/stable/documentation/rtt/v2.x/api/ht
> ml/classRTT_1_1extras_1_1SimulationThread.html> is used and started, it will
> change the TimeService's clock with each period ( to simulate time
> progress). Also other threads (!) In the system will notice this change,
> but time is guaranteed to increase monotonously.
>
> 4.2. Usage Example
>
> Also take a look at the interface documentation.
>
> #include <rtt/os/TimeService.hp

> #include <rtt/Time.hp

>
> TimeService::ticks timestamp =
> TimeService<http://www.orocos.org/stable/documentation/rtt/v2.x/api/html/cl
> assRTT_1_1os_1_1TimeService.html>::Instance()->getTicks();
>
> //...
>
> Seconds elapsed = TimeService::Instance()->secondsSince( timestamp );
>
> Is it still up to date ? Shall I use this ?

I have been and still am using this to do time measurements in my component.
You could also take a look into the TimerComponent:
This is the API docs, I don't know whether it is documented elsewhere too:
http://www.orocos.org/stable/documentation/ocl/v2.x/api/html/classOCL_1_...

-- Ruben