[openrtm-users 01426] Using Coil::timer function

3 posts / 0 new
Last post
root
Offline
Last seen: 2 days 5 hours ago
Joined: 2009-06-23 14:31
[openrtm-users 01426] Using Coil::timer function

Hi all, I found a timer class in the coil library and am interested to use it for my components in timing my outputs. I have looked through the website and information I have, but still couldn't really figure out how to declare a listener function and use it with the timer class.
I was wondering if any of you can point me in the right direction or give me a simple example? Thanks heaps in advance. Tony

Undefined
root
Offline
Last seen: 2 days 5 hours ago
Joined: 2009-06-23 14:31
[openrtm-users 01427] Using Coil::timer function

Hello Tony

> Hi all,
> I found a timer class in the coil library and am interested to use it for my
> components in timing my outputs.
> I have looked through the website and information I have, but still couldn't
> really figure out how to declare a listener function and use it with the
> timer class.
> I was wondering if any of you can point me in the right direction or give me
> a simple example?
>
> Thanks heaps in advance.
> Tony

See the following simple example.
You can add a listener object of a class which inherits ListenerBase
pure-virtual class -> (1).
And you can also add any kind of listener objects by using template
function -> (2)

#include
#include
#include
#include

class MyListener
: public ListenerBase
{
public:
virtual void invoke()
{
std::cout << "Hello" << std::endl;
}
};

class MyClass
{
public:
void hoge()
{
std::cout << "HOGE" << std::endl;
}
};

int main(void)
{
coil::TimeValue timerinterval(0, 10000);
coil::Timer timer(timerinterval); // Timer interval is 0.01sec
MyListener listener;
MyClass myobj;

coil::TimeValue interval(1, 0);
timer.registerListener(&listener, interval); // (1) listener is
ListenerBase's subclass
timer.registerListenerObj(&myobj, &MyClass::hoge, interval/10); //
(2) any kind class member function can be added by this template
function
timer.start();

while (1) ;

}

Then, you will get

HOGE
HOGE
HOGE
HOGE
HOGE
HOGE
HOGE
HOGE
HOGE
HOGE
Hello
HOGE
HOGE

Best Regards,
Noriaki Ando

root
Offline
Last seen: 2 days 5 hours ago
Joined: 2009-06-23 14:31
[openrtm-users 01428] Using Coil::timer function

Hi Mr. Ando:Thank you so much for your help. Your example is very clear. I will give it a try and ask again if I come across any problem !ThanksTonyOn 8 October 2010 05:22, Ando Noriaki <> wrote:

Hello Tony

> Hi all,
> I found a timer class in the coil library and am interested to use it for my
> components in timing my outputs.
> I have looked through the website and information I have, but still couldn't
> really figure out how to declare a listener function and use it with the
> timer class.
> I was wondering if any of you can point me in the right direction or give me
> a simple example?
>
> Thanks heaps in advance.
> Tony

See the following simple example.
You can add a listener object of a class which inherits ListenerBase
pure-virtual class -> (1).
And you can also add any kind of listener objects by using template
function -> (2)

#include <iostream>
#include <coil/Timer.h>
#include <coil/Listener.h>
#include <coil/TimeValue.h>

class MyListener
 : public ListenerBase
{
public:
 virtual void invoke()
 {
   std::cout << "Hello" << std::endl;
 }
};

class MyClass
{
public:
 void hoge()
 {
   std::cout << "HOGE" << std::endl;
 }
};

int main(void)
{
 coil::TimeValue timerinterval(0, 10000);
 coil::Timer timer(timerinterval); // Timer interval is 0.01sec
 MyListener listener;
 MyClass myobj;

 coil::TimeValue interval(1, 0);
 timer.registerListener(&listener, interval); // (1) listener is
ListenerBase's subclass
 timer.registerListenerObj(&myobj, &MyClass::hoge, interval/10); //
(2) any kind class member function can be added by this template
function
 timer.start();

 while (1) ;

}

Then, you will get

HOGE
HOGE
HOGE
HOGE
HOGE
HOGE
HOGE
HOGE
HOGE
HOGE
Hello
HOGE
HOGE

Best Regards,
Noriaki Ando

--
Noriaki Ando, Ph.D.
    Senior Research Scientist, RT-Synthesis R.G., ISRI, AIST
    AIST Tsukuba Central 2, Tsukuba, Ibaraki 305-8568 JAPAN
    e-mail: , web: http://staff.aist.go.jp/n-ando
    OpenRTM-aist: http://www.openrtm.org

Log in or register to post comments

Download

latest Releases : 2.0.0-RELESE

2.0.0-RELESE Download page

Number of Projects

Choreonoid

Motion editor/Dynamics simulator

OpenHRP3

Dynamics simulator

OpenRTP

Integrated Development Platform

AIST RTC collection

RT-Components collection by AIST

TORK

Tokyo Opensource Robotics Association

DAQ-Middleware

Middleware for DAQ (Data Aquisition) by KEK