Parse rostopics to JSON

asked 2020-07-29 02:56:09 -0600

acp gravatar image

Dear People.

I do have a rosbag with some topics like:

- gps_global_position      
 - global_position_compass_hdg
 -  imu_data
 -  zed_right_image_rect_color_compressed
 -  occupied_cells_vis_array    
 -  rtabmap_cloud_map    
 -  rtabmap_octomap_occupied_space    
 -  octomap_point_cloud_centers zed_odom

I would like to create a node in ROS where I am able to parse them into a JSON format.

The question is:

Is that possible?

If it possible, what shall be the way to do it?

Is there any suitable package for doing it?

I appreciate any help :)

Cheers

edit retag flag offensive close merge delete

Comments

the rosbridge_suite does send arbitrary ROS topics to e.g. websockets in a json format. You could check out the implementation there, seems like this file might be a good start. Follow the extract_json_values function...

mgruhler gravatar image mgruhler  ( 2020-07-29 03:11:41 -0600 )edit
1

Or use rospy_message_converter which supports msg <-> JSON conversion as well.

gvdhoorn gravatar image gvdhoorn  ( 2020-07-29 03:44:44 -0600 )edit
1

And this reads a bit like a duplicate of #q196365.

gvdhoorn gravatar image gvdhoorn  ( 2020-07-29 03:45:20 -0600 )edit

Thank you so much for the answer.

I have used rospy_message_converter as stated below, it works well :) Now I would like to send the topics that are in json format to RabbitMQ, how can I do that?

Thank you :)

#!/usr/bin/env python

 import rospy
 from rospy_message_converter import json_message_converter
 from sensor_msgs.msg import Imu


 def ImuJsonCallBack(imu_data_):
       imu_json_ = json_message_converter.convert_ros_message_to_json(imu_data_)
       print("\n")
       print(imu_json_)
       print("\n") 

 def main():
     rospy.init_node('ros2json', anonymous=True)
     rospy.Subscriber("/mavros/imu/data", Imu, ImuJsonCallBack)
     rospy.spin()


 if __name__ == '__main__':
    main()
acp gravatar image acp  ( 2020-07-30 00:51:58 -0600 )edit
1

Now I would like to send the topics that are in json format to RabbitMQ, how can I do that?

This does not seem like a ROS question any more.

I would suggest you post it on a different forum.

gvdhoorn gravatar image gvdhoorn  ( 2020-07-30 04:22:38 -0600 )edit