UInt8[] message problem

456 views
Skip to first unread message

webe...@gmail.com

unread,
Sep 9, 2015, 8:20:31 AM9/9/15
to Robot Web Tools
Hi RWT community,

I have a problem with uint8 array messages over rosbridge websocket to roslibjs. Instead of the array I put in the message the browser outputs weird stuff.

I publish a uint8[] array from the console with

$ rostopic pub /array std_msgs/UInt8MultiArray "layout:
  dim:
  - label: ''
    size: 0
    stride: 0
  data_offset: 0
data: [1, 2]"


and print it in the browser with

var sub = new ROSLIB.Topic({
  ros : ros,
  name : '/array',
  messageType : 'std_msgs/UInt8MultiArray'
});
  
sub.subscribe(function(msg) {
  console.log(msg);
}

This results in this:

You see I get the string "AQI=". It isn't an array any more.
The array [0] results in "AA=="

With UInt16MultiArray it works as expected:

Tested with Chromium and Firefox on 14.04 and Indigo.

Is this a problem of the rosbridge or is this related to roslibjs? Any suggestions on how to solve this?

Russell Toris

unread,
Sep 9, 2015, 8:43:58 AM9/9/15
to robot-w...@googlegroups.com, David Lu
I believe this is related to https://github.com/RobotWebTools/rosbridge_suite/pull/190/. uint8 are being encoded as BSON for faster transport to the browser. 

@dlu -- Do you have an example of how to read from uint8 in the browser/can we document this/should the BSON be enabled by a flag in rosbridge?

--
You received this message because you are subscribed to the Google Groups "Robot Web Tools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robot-web-too...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Russell Toris
Graduate Student | WPI Department of Computer Science
rct...@wpi.edu | http://users.wpi.edu/~rctoris/

webe...@gmail.com

unread,
Sep 15, 2015, 3:34:49 AM9/15/15
to Robot Web Tools, davi...@gmail.com
@dlu -- Any ideas about this?

David Lu

unread,
Sep 16, 2015, 1:25:07 PM9/16/15
to Robot Web Tools, davi...@gmail.com
I apologize. Rookie mistake, I replied only to Russell. Below is my original reply. 


This is not BSON encoding, as that would result in a Blob binary object instead of the string. This is the standard Base64 encoding (https://en.wikipedia.org/wiki/Base64) that is used by default when binary encoding is not enabled. 

Both encodings are transmitted quicker than the straight forward json encoding of the data. 

There are a couple options for decoding the string in Javascript, although there is a larger question of whether it should be done automatically. 

webe...@gmail.com

unread,
Sep 17, 2015, 3:26:21 AM9/17/15
to Robot Web Tools, davi...@gmail.com
Thanks very much.
A simple 
data = window.atob(msg.data)

did the trick.
Reply all
Reply to author
Forward
0 new messages