ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A

Callback Args in ROS2

Hey All,

I was curious as to whether or not “callback_args” were going to make their way into ROS 2? If not, out of curiosity, what is the justification and are there any alternative solutions?

Thanks in advance.

There’s no reason it could not be in rclpy. In C++, you’d probably just use a lambda or std::bind to accomplish this, but for convenience it could also be in rclcpp as well.

I would file a feature request issue on rclpy and/or rclcpp and consider doing a pr after getting feedback on the approach.

Thanks for the feedback and sorry for the delayed response. I haven’t filed a feature request yet but I did find a temporary fix. I was able to get similar functionality utilizing partial functions in python.

For example:

from functools import partial
create_subscription(msg_type, ros_topic, partial(callback_function, passed_variable))

Yeah, that’s a proper solution, similar to using a lambda or std::bind in C++. We’d only provide a similar interface in rclpy as a convenience, but it’s not necessary at all.

I’d vote for implementing it, at least in rclpy. I like to think of Python as a more beginner friendly interface many times.

@Seiwert thanks for your response anyways!