Ask Your Question

Get information about topic message at runtime

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

ct2034 gravatar image

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

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 -0500

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 -0500 )edit

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

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



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

Seen: 644 times

Last updated: May 14 '18