rosh overview: Roshlets | Basics | Messages | Parameters | Topics | Services | Nodes | Topic Tools | Packages | Bags | Bagys | roslaunch


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()
  seq: 0
    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:


Keyword style:


Instantiate a message from YAML representation


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


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

Wiki: rosh/Overview/Messages (last edited 2010-10-22 07:55:33 by KenConley)