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

rospy types of message subfields

asked 2020-12-04 14:33:33 -0500

mikemodanoxxx gravatar image

Hi,

I generate an empty instance of a message type, e.g via genpy.message.get_message_class('sensor_msgs/JointState') and convert it to a string, which results in:

header: 
  seq: 0
  stamp: 
    secs: 0
    nsecs:         0
  frame_id: ''
name: []
position: []
velocity: []
effort: []

I would like to fill the arrays with default values, similar to what a "rostopic pub .." call on the command line would give me:

header:
  seq: 0
  stamp: {secs: 0, nsecs: 0}
  frame_id: ''
name: ['']
position: [0]
velocity: [0]
effort: [0]

However, on the python side I don't know how to find out what the types of the lists are, since a type() call on the individual subfields only yields 'list'. Does anyone know how to find out the type of specific fields in messages?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-12-04 15:33:50 -0500

navdlee gravatar image

You can use the _slot_types attribute to get information about the type of the attribues of a message with rospy:

>>> from sensor_msgs.msg import JointState
>>> msg = JointState()
>>> msg._slot_types
['std_msgs/Header', 'string[]', 'float64[]', 'float64[]', 'float64[]']
>>>

See: http://wiki.ros.org/msg#Client_Librar...

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2020-12-04 14:33:33 -0500

Seen: 363 times

Last updated: Dec 04 '20