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

ROS2 async_send_request callback

asked 2021-04-15 17:33:14 -0500

scott.nortman@gmail.com gravatar image

updated 2021-04-16 16:07:32 -0500

I have created code similar to this example:

https://github.com/ros2/demos/blob/40...

However, in my code, when I call async_send_request

this->client_->async_send_request( request, callback );

I pass a callback of type

rclcpp::Client<cpp_rpispi::srv::Spixfer>::CallbackType && callback

However, in the callback, I am trying to publish to a topic, but the compiler states that the call to publish is not allowed since the callback has to be static, but the publisher is non-static.

So, how can I pass a non-static member function as the callback so I can publish a topic?

Thanks

UPDATE

Problem solved by using a local anonymous function instead.

edit retag flag offensive close merge delete

Comments

Is there any way not using anonymous function?

DC pig gravatar image DC pig  ( 2022-03-28 21:47:39 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-09-08 07:39:22 -0500

omer.tal gravatar image

The callback function should have the signature:

void callback(const rclcpp::Client<ServiceT>::SharedFuture future)

In your case:

void callback(const rclcpp::Client<cpp_rpispi::srv::Spixfer>::SharedFuture future)

edit flag offensive delete link more

Question Tools

3 followers

Stats

Asked: 2021-04-15 17:33:14 -0500

Seen: 3,549 times

Last updated: Sep 08 '22