Dynamically resolve message type and subscribe to topic at runtime in roscpp ?
Is it possible to subscribe to a topic configured at runtime in a C++ node?
For example, is there an API to do the following in roscpp (adapted the code snippet seen here)?
type_name = rostopic.get_topic_type(topic_name, blocking=False)[0]
if type_name:
type_class = roslib.message.get_message_class(type_name)
subscriber = rospy.Subscriber(topic_name, type_class, callback)
May I suggest a topic change? "subscribe dynamically at runtime" is typically understood to mean: "create subscribers (for a specific msg type) at runtime". You seem to be asking how to create subscribers without knowing the msg type. That would be something else.
@gvdhoorn I updated the title to hopefully better express the intent of the question. Feel free to improve if you can come up with an even better title!
I think this is perfect. Thanks.