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

Problem with ros::Timer [closed]

asked 2012-08-23 22:39:02 -0500

g.aterido gravatar image

updated 2014-01-28 17:13:26 -0500

ngrennan gravatar image


I have trouble creating a timer in Ros. I defined a class in which one of its members is the timer callback. To create it, in the constructor of the class I put the following:

timer = nh.createTimer(ros::Duration(0.1), &summit_xl_path_planning::PathPlanningSpin, this);

("timer" is a ros::Timer member of the class)

And then define the callback as below:

void summit_xl_path_planning::PathPlanningSpin(const ros::TimerEvent& e)

Finally in the main summit_xl_path_planning I create a class, to make things work. I run the node using rosrun.

The problem is that I never get to run the timer. The program compiles. When I run everything I put in the constructor is done, but then nothing else happens. I have reviewed the tutorials thousands of times, but I can not see I'm doing wrong. Can anybody help?

I'm using Ubuntu 12.04 and Fuerte.

Thanks in advance and best regards

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by g.aterido
close date 2012-11-28 21:52:04

1 Answer

Sort by ยป oldest newest most voted

answered 2012-08-23 22:49:32 -0500

Lorenz gravatar image

Unfortunately, you didn't give us enough information (e.g. source code) in your question so I can just guess. Here a few things that can go wrong:

  • Are you calling ros::spin() or ros::spinOnce() in a loop somewhere in your program? Spinning will call the timer callbacks.

  • Is your NodeHandle object maybe stack allocated in the constructor and destroyed at the end of it? The live time of timer objects, publishers and subscribers is bound to the NodeHandle they were created with. Make sure that the NodeHandle is a member variable of the class that starts the timer.

edit flag offensive delete link more


Thanks! I was callin ros::spin(), but the NodeHandle was not a member variable of the class. Sorry for this dummy question ;)

g.aterido gravatar image g.aterido  ( 2012-08-24 00:21:44 -0500 )edit

Question Tools


Asked: 2012-08-23 22:39:02 -0500

Seen: 1,591 times

Last updated: Aug 23 '12