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

Revision history [back]

Unfortunately you can't do this, not even in Python. If you subscribe to a topic with message type A and receive message type B, ROS will complain about the MD5 sum.

Even if it was possible, your approach can't do any real-time checking, as the C++ templates (implemented in the subscriber) create functions/classes at compile time.

This example seems to arise from the fact that "sr_robot_msgs::JointControllerState" and "pr2_controllers_msgs::JointControllerState" are basically the same message, so why two different types?

Unfortunately you can't do this, not even this in Python. If C++.

First of all, if you subscribe to a topic with message type A and receive message type B, ROS will complain about the MD5 sum.

Even if it was possible, your approach can't do any real-time checking, as the C++ templates (implemented in the subscriber) create functions/classes at compile time.

So the main problem is that C++ requires the declaration of the callback function signature at compile time. AFAIK there is no general "Message" class from which all the messages inherit, so polymorphism is not an option.

This example seems to arise from the fact that "sr_robot_msgs::JointControllerState" and "pr2_controllers_msgs::JointControllerState" are basically the same message, so why two different types?