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

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
1

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

Question Tools

1 follower

Stats

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

Seen: 250 times

Last updated: Nov 14 '21