ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

What am i doing wrong with ros::timer in rqt?

asked 2014-02-23 09:32:08 -0600

Blizzard gravatar image

updated 2016-10-24 09:01:26 -0600

ngrennan gravatar image

Hello,

i have some problems with making the ros::timer work. Usually if i need a timer within a class i add these three lines to the header:

  void timerCallback(const ros::TimerEvent& event);
  ros::Timer m_timer;
  ros::NodeHandle m_nh;

and in the cpp file i add this line for example to the constructor:

m_timer = m_nh.createTimer(ros::Duration(1), &MyClass::timerCallback, this);

Last but not least i add a callback function to the cpp:

void MyClass::timerCallback(const ros::TimerEvent& event)
{
  // something that has to be done frequently
  ROS_INFO("Beep");
}

Unfortunatly it does not work this way in an rqt plugin. For some reason the callback function is never thrown. Please help me with that. I'm using ROS Hydro on Kubuntu 12.04.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2014-02-27 09:34:38 -0600

Dirk Thomas gravatar image

Currently for the C++ plugins in rqt there is no spinning ROS thread therefore ROS timers do not work. Temporary you could work around it by using Qt timers instead.

I have created two pull requests which will add the functionality to rqt. If you want to give it a try checkout the branches of the following two pull request into your workspace: https://github.com/ros-visualization/... and https://github.com/ros-visualization/... Then your timer should fire as expected.

edit flag offensive delete link more

Comments

Thank you very much. Now it works like expected. Will these two branches be merged into future versions of rqt and qt_gui_core? I hope so.

Blizzard gravatar image Blizzard  ( 2014-02-27 14:12:48 -0600 )edit

All ROS distros are currently being released form the same branch for those repos. So yes, all will receive the change soon.

Dirk Thomas gravatar image Dirk Thomas  ( 2014-02-27 14:30:59 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2014-02-23 09:32:08 -0600

Seen: 523 times

Last updated: Feb 27 '14