[openrtm-users 01428] Re: Using Coil::timer function

Tony Kuo ikuo005 @ aucklanduni.ac.nz
2010年 10月 8日 (金) 04:53:13 JST


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 !

Thanks
Tony

On 8 October 2010 05:22, Ando Noriaki <n-ando @ aist.go.jp> 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: n-ando @ aist.go.jp, web: http://staff.aist.go.jp/n-ando
>     OpenRTM-aist: http://www.openrtm.org
>
>
>
-------------- next part --------------
HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...
URL: <http://www.openrtm.org/pipermail/openrtm-users/attachments/20101008/7a2c26e4/attachment-0001.html>


openrtm-users メーリングリストの案内