Let's say we send and receive complex type message like sensor_msgs/Image, here is the code based on
[roslibjs]():
var ros = new ROSLIB.Ros();
ros.connect('ws://localhost:9090');
var example = new ROSLIB.Topic({
ros: ros,
name: '/big_data_topic',
messageType : 'sensor_msgs/Image'
});
let dataLength = 320 * 240 * 4 * 4;
let uint8Data = new Array(dataLength);
for (let i = 0; i < dataLength; i++) {
uint8Data[i] = i % 255;
}
example.subscribe(function(message) {
var length = message.data.length;
console.log(`${length} bytes received`);
});
example.publish({
header: {stamp: {sec: 11223, nanosec: 44556}, frame_id: 'f001', },
height: 240, width: 320, encoding: 'rgba', is_bigendian: false, step: 320*16, is_dense: false,
data: Uint8Array.from(uint8Data),
});
Since there is no way to construct the message object and assign member for it, we can only publish message data in JavaScript object notation way, like above.
However, the subscriber failed to receive the message. We found the subscriber callback was never called and and got this error in from the ros2-web-bridge log:
ros2-web-bridge:Bridge Exception caught in Bridge.executeCommand(): TypeError: msg.hasMember is not a function +1m
ros2-web-bridge:Bridge Error: TypeError: msg.hasMember is not a function happened when executing command publish +1ms
ros2-web-bridge:Bridge Response: {"op":"set_level","id":"publish:/big_data_topic:3","level":"error"} +0ms
The same JavaScript object notation way of message can be published and received by rclnodejs node
Let's say we send and receive complex type message like
sensor_msgs/Image
, here is the code based on [roslibjs]():Since there is no way to construct the message object and assign member for it, we can only publish message data in JavaScript object notation way, like above.
However, the subscriber failed to receive the message. We found the subscriber callback was never called and and got this error in from the
ros2-web-bridge
log:The same JavaScript object notation way of message can be published and received by rclnodejs node