[Documentation] [TitleIndex] [WordIndex

Messages

Dynamically import and instantiate a message

The msg object gives you access to any of the messages that can be located on your ROS_PACKAGE_PATH. It gives you direct access to the message class itself, i.e.

In [1]: msg.std_msgs.String
Out[1]: <class 'std_msgs.msg._String.String'>

You can instantiate a message with default values like so:

In [15]: msg.sensor_msgs.JointState()
Out[15]: 
header: 
  seq: 0
  stamp: 
    secs: 0
    nsecs: 0
  frame_id: ''
name: []
position: []
velocity: []
effort: []

You can pass constructor arguments the same way you do when using rospy, e.g.

Arg style:

msg.std_msgs.String('data')

Keyword style:

msg.geometry_msgs.Quaternion(w=1.0)

Instantiate a message from YAML representation

EXPERIMENTAL/VOLATILE

You can call the msg object with a YAML string and a message class to load into, e.g. create a std_msgs/String instance with data set to "foo".

msg('data: foo', msg.std_msgs.String)

Instantiate a message from dict representation

EXPERIMENTAL/VOLATILE

You can call the msg object with a Python dict and a message class to load into. This dict representation is equivalent to the loaded form of the YAML representation, aka the rostopic echo representation.

msg({'data': 'foo'}, msg.std_msgs.String)

rosmsg show

In [1]: show(msg.sensor_msgs.JointState)
Header header
  uint32 seq
  time stamp
  string frame_id
string[] name
float64[] position
float64[] velocity
float64[] effort

2024-11-23 17:51