0
$\begingroup$

Rosanswers logo

Not sure if it's possible programmatically.


Originally posted by ahtsan on ROS Answers with karma: 112 on 2019-08-08

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Yes, you can dynamically create new subscriptions in c++ at run time.

Use the create_subscription method on Node

http://docs.ros2.org/latest/api/rclcpp/index.html


Originally posted by tfoote with karma: 58457 on 2019-08-08

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by ahtsan on 2019-08-08:
How about discovering new topics that are created during run time?

Comment by tfoote on 2019-08-08:
Sure. You can get the list of topics and their types that have been discovered at any time from the API.

See http://docs.ros2.org/latest/api/rclcpp/index.html (search for “introspecting the ROS graph”)

Comment by ahtsan on 2019-08-08:
But if type is not known in advance, how can we create the subscription? As the message type is needed at the time of subscription creation.

Comment by tfoote on 2019-08-08:
Use the api linked above in the comment to get the list of topics and their types before you call create subscription. Or know through some other means what type you're expecting. The callback must match the type too so you're going to need to have an idea about the type beforehand anyway.

Comment by ahtsan on 2019-08-08:
Got it. Thanks!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.