Reputation: 495
I want to create a ROS node that is able to listen to a topic without knowing its message type. In python, this is possible as can be seen here:
https://schulz-m.github.io/2016/07/18/rospy-subscribe-to-any-msg-type/
I tried that and it works like a charm. However, I want to avoid copying the whole message; thus, i need that functionality in a roscpp nodelet.
Upvotes: 1
Views: 1391
Reputation: 4803
By nature, this sort of problem is very pythonic and much harder to work around in c++. That being said, there is one (sort of) solution out there already. Take a look at the ros_msg_parser.
The syntax isn't pretty, and I'm not even sure if it's a good idea, but it will let you generate generic subscribers. Example from the linked repo:
boost::function<void(const RosMsgParser::ShapeShifter::ConstPtr&)> callback;
callback = [&parsers, topic_name](const RosMsgParser::ShapeShifter::ConstPtr& msg) -> void {
topicCallback(*msg, topic_name, parsers);
};
ros::Subscriber subscriber = nh.subscribe(topic_name, 10, callback);
Upvotes: 0