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

Get information about topic message at runtime

asked 2015-11-18 05:29:27 -0600

ct2034 gravatar image

updated 2015-11-18 05:42:42 -0600

I am trying to build an interface that universally bridges ROS topics to another system. I am importing the message type at runtime:

importcom = (  # import type
    "from " +
    topic_class +
    ".msg import " +
exec(importcom, globals())

This allows me to later subscribe to this topic dynamically at runtime.

My question is now: How can I gain insight in the structure of this message at runtime? Ideally I need a json object that includes the types of all the parameters that i expect in a message. e.g.:

   "angular" :
           "x": float
           "y": float 
   "linear" :
           "x": float
           "y": float 

(or something like this)

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2015-11-18 08:51:20 -0600

Dimitri Schachmann gravatar image

I don't know about any existing way to get json directly, but the output of rosmsg show should be relatively easy to parse and transform into json. e.g.:

$ rosmsg show sensor_msgs/CameraInfo
Header header
  uint32 seq
  time stamp
  string frame_id
uint32 height
uint32 width
RegionOfInterest roi
  uint32 x_offset
  uint32 y_offset
  uint32 height
  uint32 width
float64[5] D
float64[9] K
float64[9] R
float64[12] P

And if you're into python, you can checkout the implementation of rosmsg here

edit flag offensive delete link more


Could you give some hints how to get the API of rosmsg? Because I found the API of rosgraph which can parse the information about which topics the nodes are subscribing from or publishing to. But I didn't find the API to access outputs of "$rosmsg show".

Justin_Qiu gravatar image Justin_Qiu  ( 2018-05-09 09:51:34 -0600 )edit

answered 2018-05-14 03:47:40 -0600

Justin_Qiu gravatar image

Here is an API to get rosmsg through python:

After import modules:
import rospy import rosmsg import rospkg I can get the text of messages through rosmsg.list_msgs(ros_pkg) from a certain package, and get all the packages through rospkg.RosPack().list()

edit flag offensive delete link more

Question Tools



Asked: 2015-11-18 05:29:27 -0600

Seen: 832 times

Last updated: May 14 '18