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

ROSBridge and sensor_msgs/Image - Why am I getting an extra byte?

asked 2013-12-22 09:56:13 -0500

trianta2 gravatar image

updated 2014-01-28 17:06:36 -0500

ngrennan gravatar image

I have ROSBridge server running on my host and a client I wrote connected to it. I can send and receive messages just fine. I have not had any trouble sending strings and numbers, however, when I try to send an image (of type sensor_msgs/Image) from the server to the client, something really peculiar happens.

For test purposes, I'm sending a 1 x 1 pixel image of encoding bgr8. If I send a red pixel (ie BGR value is {0,0,255}), and do rostopic echo /myImage/data, I see {0,0,255} printed to terminal. Just as expected.

However, when I receive the message on my client, the data field actually has 4 bytes of data instead of 3 (I should get 1 byte per color). I cannot figure out where this extra byte comes from, nor how to format the 4 bytes of data to get back my original BGR value.

Here is the pattern I've found so far. The following are hex values of the data I sent from the server (left side) and received on the client (right side). Sorry for the weird spacing... I couldn't figure out how to enter tabs an spaces on this website.

--Sent From Server (BGR Hex) --- Received At Client
----------- 00 00 00 ---------------------- 41 41 41 41 -----
----------- FF FF FF --------------------- 2F 2F 2F 2F -----
----------- 00 00 FF ---------------------- 41 41 44 2F -----
----------- 00 FF 00 ---------------------- 41 50 38 41 -----
----------- FF 00 00 ---------------------- 2F 77 41 41 -----

Once again, I have no idea what's happening here. I believe the endianness of the message may be an issue as well, but it doesn't help explain where the extra byte of data is coming from. Any insight would really be appreciated.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-12-23 12:19:51 -0500

trianta2 gravatar image

Answered my own question, which also answers this question, here: http://answers.ros.org/question/112806/rosbridge-how-are-data-arrays-represented-and-sent-via-json/?answer=112836#post-id-112836

I don't recall any ROSBridge documentation stating that binary data is encoded to base64 before transmitting, but that's what caused the extra byte of data.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-12-22 09:56:13 -0500

Seen: 1,284 times

Last updated: Dec 23 '13