The msg_boost_python ROS package can be used to generate Boost.Python converters for ROS messages. A compiled library is generated that registers those converters when it is imported into Python. Internally, the data is serialized and deserialized in the process. On the other hand, the conversion is fairly straightforward and no extra Python or C++ classes have to be generated from message definition: the converters operate on the regular data types generated by genpy and gencpp.
Overview
The main component is the CMake macro generate_msg_boost_python_converters
which is available after including msg_boost_python in the find_package
statement. You can generate converters for messages declared in any package.
There are small packages already included in the repository that generate converters for the common_msgs packages geometry_msgs, sensor_msgs, and shape_msgs. As already hinted above, a statement like
from geometry_msgs_boost_python import msg
registers converters for all message types in the geometry_msgs package without bringing any new “items” into Python. It is then possible to:
- Pass a Python message object to a C++ function expecting a constant shared pointer to the C++ version of the message.
- Pass a C++ message constant shared pointer into a Python message object.
Furthermore there is another macro set_boost_python_module
which is used
internally and is exposed to facilitate Boost.Python package setup within
Catkin.