Is there a general way to convert ROS messages into JSON format?
I would like to convert arbitrary ROS messages into JSON format. Is there an official way of doing this?
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org |
I would like to convert arbitrary ROS messages into JSON format. Is there an official way of doing this?
Rosbridge provides you a JSON API to ROS
I just tried the rospy_message_converter.
Works really well! :)
Rosbridge is probably the better answer, but just in case, here's a method that will at least work on messages whose content can be rendered as a string with the python str()
function.
import json
import yaml
def msg2json(msg):
''' Convert a ROS message to JSON format'''
y = yaml.load(str(msg))
return json.dumps(y,indent=4)
if __name__ == "__main__":
from geometry_msgs.msg import PoseStamped
P = PoseStamped()
print msg2json(P)
{
"header": {
"stamp": {
"secs": 0,
"nsecs": 0
},
"frame_id": "",
"seq": 0
},
"pose": {
"position": {
"y": 0.0,
"x": 0.0,
"z": 0.0
},
"orientation": {
"y": 0.0,
"x": 0.0,
"z": 0.0,
"w": 0.0
}
}
}
I don't know much about this topic, but you might be able to find something useful in the newly announced mongodb_log package, I believe MongoDB uses JSON, and I think in that package they do automated conversions from ROS messages to JSON.
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2014-10-30 21:30:04 -0500
Seen: 15,845 times
Last updated: Oct 18 '17
Display CompressedDepth Image Python cv2
Rosbridge TCP Error: __init__() got an unexpected keyword argument 'parameters'
Moveit Benchmarking cant plot PDF
Problem Listener with [closed]
Segmentation fault (core dumped)
Plugin problem launching .launch [closed]
using openni_camera to play a bag problem
Yaw problem in my wall following algorithm
Robotino ROS pcl::VoxelGrid<sensor_msgs::PointCloud2_<std::allocator<void>