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

Read rosbag with javascript?

asked 2016-02-08 14:19:42 -0600

lucasw gravatar image

updated 2020-11-21 11:34:29 -0600

I'd like to use bag files as a generic output data format, but I'd also like to display text and numbers out of the bags in a javascript browser environment. It isn't necessary to handle arrays of binary data.

Is it possible to read a bag directly from javascript (using a library)?

Or what would be a good way to save data into a bag (which is easy with the rosbag api), then programmatically convert the bag to json, yaml, or less desirably a csv? It looks like from there are command lines to convert to csv, is there an api call to do the same thing?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2016-02-09 10:23:33 -0600

lucasw gravatar image

updated 2016-02-09 10:40:16 -0600

It looks like jsonpickle will do the job:

sudo apt-get install python-jsonpickle

Then in python:

import json-pickle
from std_msgs.msg import Header
h = Header()
h.frame_id = "map"
a = jsonpickle.encode(h)

And the the following could be easily written to disk, or sent directly to a web server:

>>>> a
'{"py/object": "std_msgs.msg._Header.Header", "stamp": {"py/object": "genpy.rostime.Time", "secs": 0, "nsecs": 0}, "seq": 0, "frame_id": "map"}'

A python script could convert bags to json pickle format as a ros node or offline, and if conversion back for reading in C++ is necessary a python intermediary could read the json and write out a bag (I assume even if there is a generic C++ json pickle reader it would create strange python objects and not C++ ros messages, and additional custom conversion machinery would be required to close the loop, could be worth trying).

It looks like came to a similar conclusion.

edit flag offensive delete link more

answered 2018-04-06 10:53:21 -0600

samjabrahams gravatar image

Cruise Automation recently open sourced a Javascript library for parsing rosbag files. This should allow you to more easily get the information you're looking for directly into the browser:

edit flag offensive delete link more

Question Tools



Asked: 2016-02-08 14:19:42 -0600

Seen: 1,434 times

Last updated: Feb 09 '16