ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Defining message types directly in Python

asked 2021-11-14 09:06:51 -0500

rgov gravatar image

updated 2021-11-14 09:22:50 -0500

I'm writing a Python script to synthesize a rosbag from data files generated outside of ROS.

It would be easiest to be able to define the ROS message types within my Python code, rather than have to write standalone .msg definition files and re-generate them over and over again as I iterate on the script.

What would this entail? I'm fine with importing from genmsg or genpy.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-11-14 09:35:01 -0500

rgov gravatar image
from genpy.dynamic import generate_dynamic
msgs = generate_dynamic('pkg/Msg', 'string data\n')

Here msgs is a dictionary whose keys are message type names and values are classes that can be used for serialization.

It is possible to pass secondary definitions for dependencies of pkg/Msg at the same time. They need to be delimited by a line of 80 = characters, then a line that is written MSG: pkg/Dep, then the fields.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2021-11-14 09:06:51 -0500

Seen: 102 times

Last updated: Nov 14 '21