RobotWebTools / rclnodejs

Node.js version of ROS 2.0 client
https://docs.ros.org/en/jazzy/Concepts/Basic/About-Client-Libraries.html#community-maintained
Apache License 2.0
328 stars 71 forks source link

Failed to receive complex type message via bridge #343

Closed qiuzhong closed 6 years ago

qiuzhong commented 6 years ago

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

qiuzhong commented 6 years ago

Move to ros2-web-bridge repo: #98