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

rosbridge v2 msg format and subscriber callback in csharp

asked 2015-03-10 03:27:52 -0600

Morgane gravatar image

With the help of the code provided here: RosBrigde client for windows in C# I managed to communicate with winros's tcp_server from my external program and subscribe to a topic. When I try to receive the topic data I face two problems:

  1. I receive a string formatted as: "topic: ... msg: {data: ...} op: ..." How do I manage to retrieve the data value of the string? my message as I have created it consists of a class with three string variables, but that doesn't seem to work
  2. I receive only one string and then the call back times out. I have put the code inside a loop but no results

Thank you for any help.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-03-10 07:41:07 -0600

rtoris288 gravatar image

rosbridge messages come in a JSON encoded string as defined in the rosbridge protocol spec ( https://github.com/RobotWebTools/rosb... ). You will need to utilize a JSON parser in C# to extract the data field which will contain your message data as a JSON object. This data comes in as a single JSON string.

edit flag offensive delete link more

Comments

So when I receive this message ex: socket.receive(recdata); recdata is a string with the format I described. I made a class with op, msg and topic members, and if rd is an instance of that class I went on an called the deserializer rd = jsonconvert.deserializeobject(recdata); rd.msg doesn't work

Morgane gravatar image Morgane  ( 2015-03-11 02:57:42 -0600 )edit

I am unfamiliar with JSON parsing in C# but I suspect something needs to be done to parse the msg field which in itself is its own JSON object. Are the other fields set correctly? Can you post the recdata string that is coming in or verify it is valid JSON ( http://jsonlint.com/)?

rtoris288 gravatar image rtoris288  ( 2015-03-11 07:03:06 -0600 )edit

yes the string is: {"topic": "/chatter", "msg":{"data": "hello world 1"}, "op": "publish"} The actual question is: what type of c# type is msg? (it must contain the string _data)

Morgane gravatar image Morgane  ( 2015-03-11 07:30:59 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-03-10 03:27:52 -0600

Seen: 1,840 times

Last updated: Mar 10 '15