Ask Your Question
0

How can I send JSON data to and from ROS?

asked 2017-11-05 13:10:20 -0600

qureeb gravatar image

I am currently working on a task that involves constant intercommunication between a web browser (using roslibjs) and the ROS system through the rosbridge server. Is there a way to send JSON-formatted data from the browser to a ROS node? I realize there is no JSON among the ROS system's standard data types.

edit retag flag offensive close merge delete

Comments

1

I'm confused: if you are already using roslibjs and rosbridge_suite, you are sending (and receiving) JSON data to (and from) ROS.

Can you clarify what it is you actually want to do?

gvdhoorn gravatar imagegvdhoorn ( 2017-11-05 14:12:36 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
3

answered 2017-11-05 14:14:41 -0600

gvdhoorn gravatar image

(follow up to my comment)

If you want to send JSON encoded data as part of a message to a ROS node, then I don't believe there are any special provisions for that.

Most straightforward would probably be to define a new message that stores the JSON string in a field. Any receiving node will have to know it's JSON though.

edit flag offensive delete link more
3

answered 2017-11-21 14:32:15 -0600

qureeb gravatar image

Thanks, I found a way out. I was expecting JSON to be one of ROS's standard message types. Not the case. I simply wrote a JSON-format data, stringified it, and sent it as std_msgs type.

edit flag offensive delete link more

Comments

3

This will certainly work. However it's not recommended since you're completely avoiding the message datatype checks and all the introspection tools are unable to help you. As @gvdhoorn suggests the recommended way to do this would be to define a custom message to hold your data.

tfoote gravatar imagetfoote ( 2017-11-21 15:05:25 -0600 )edit

but what if you want that stringified data into json form in c++ side.

AhteshamAziz gravatar imageAhteshamAziz ( 2019-10-07 09:48:17 -0600 )edit

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2017-11-05 13:10:20 -0600

Seen: 881 times

Last updated: Nov 21 '17