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

Signature of callback function for creating a timer

asked 2021-09-16 00:06:27 -0500

Ben222 gravatar image

updated 2021-09-16 00:09:38 -0500

As per the Timer tutorial, the signature of the callback function for ros::time should be void callback(const ros::TimerEvent&). However, in the TF example, the transformPoint(const tf::TransformListener& listener) as the callback doesn't conform to the required signature which means I am missing something here and not sure where to look for?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-09-16 14:37:20 -0500

Mike Scheutzow gravatar image

updated 2021-09-17 06:47:43 -0500

In my opinion, that "TF example" link is abusing the API in a very bad way is an advanced use that is very confusing to read. I suggest you ignore that example.

The Timer tutorial is the right way to code the callback for a Timer object.

Update: for your second link, if this is the only thing the node is going to do, I wouldn't use Timer object at all. This code is untested:

ros::init(argc, argv, "test");
ros::NodeHandle nh
tf::TransformListener listener(ros::Duration(10));;
ros::Rate rate(1); // Hz
while (ros::ok()) {
    transformPoint(listener);
    rate.sleep();
}

If you must use a Timer, then create a global ptr to listener and use it inside the callback. Just keep in mind that you have to create the listener after calling ros::init().

edit flag offensive delete link more

Comments

Thanks. Then what would you write alternatively for the callback transformPoint() or its caller in that example so that be matching with the Timer suggested API?

Ben222 gravatar image Ben222  ( 2021-09-16 16:33:36 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2021-09-16 00:06:27 -0500

Seen: 179 times

Last updated: Sep 17 '21