ros timer bug?
Hi,
I'm currently writing a simple application to publish a message only for certain time. For that I used a oneshoot timer which is setting a flag. The outcome was that the flag and so the timer event was triggered almost at the beginning of the application, although I set a long Duration period. Than I tried an example from the wki link with a similar behavior.
void callback1(const ros::TimerEvent&) {
ROS_INFO("Callback 1 triggered");
}
void callback2(const ros::TimerEvent&) {
ROS_INFO("Callback 2 triggered");
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "test");
ros::NodeHandle n;
ros::Timer timer1 = n.createTimer(ros::Duration(0.1), callback1);
ros::Timer timer2 = n.createTimer(ros::Duration(1.0), callback2);
ros::spin();
return 0;
}
Result of this Code is the following:
[ INFO] [1503044891.821472262, 1979.528000000]: Callback 1 triggered
[ INFO] [1503044891.821598505, 1979.528000000]: Callback 2 triggered
[ INFO] [1503044891.821659684, 1979.528000000]: Callback 1 triggered
[ INFO] [1503044891.821695171, 1979.528000000]: Callback 2 triggered
[ INFO] [1503044891.922356425, 1979.629000000]: Callback 1 triggered
[ INFO] [1503044892.021857347, 1979.728000000]: Callback 1 triggered
[ INFO] [1503044892.121675024, 1979.828000000]: Callback 1 triggered
[ INFO] [1503044892.221838279, 1979.928000000]: Callback 1 triggered
[ INFO] [1503044892.323168866, 1980.028000000]: Callback 1 triggered
[ INFO] [1503044892.445560190, 1980.128000000]: Callback 1 triggered
[ INFO] [1503044892.546153145, 1980.228000000]: Callback 1 triggered
[ INFO] [1503044892.647412716, 1980.329000000]: Callback 1 triggered
[ INFO] [1503044892.747397039, 1980.428000000]: Callback 1 triggered
[ INFO] [1503044892.848747723, 1980.528000000]: Callback 2 triggered
[ INFO] [1503044892.848827195, 1980.528000000]: Callback 1 triggered
[ INFO] [1503044892.950519122, 1980.628000000]: Callback 1 triggered
[ INFO] [1503044893.050009460, 1980.728000000]: Callback 1 triggered
Where I would expect that trigger 2 should occur after one second.
Am I doing something wrong or is this a known issue?
To resolve that I'm waiting before the timer creation for like 200ms.
Thanks for the help, cheers Robert
I tried this in Kinetic on Ubuntu 16.04 and it triggers properly.
I can reproduce my error when I use gazebo and launch an empty world. When I use the code above with initially executed roscore, it works! Can someone confirm that?