Take the Byte as example, there is a ByteArrayWrapper class in the generated/std_msgs/std_msgs__msg__Byte.js. It stands for an array of the Byte message type. However, it cannot be used to createPublisher. This code
const rclnodejs = require('./rclnodejs/index.js');
rclnodejs.init().then(() => {
var node = rclnodejs.createNode('byte_publisher');
var Byte = rclnodejs.require('std_msgs').msg.Byte;
var ByteArray = Byte.ArrayType;
var msg = new ByteArray(3);
msg.setWrappers([1, 2, 3]);
// console.log(`${msg.data}`);
console.log(msg.data[0].data); // print 1
var publisher = node.createPublisher(ByteArray, 'chatter');
setInterval(() => {
console.log(`Publishing: ${msg.data}`);
publisher.publish(msg);
}, 500);
rclnodejs.spin(node);
}).catch((err) => {
console.log(err);
});
will lead a TypeError when calls createPublisher:
1
TypeError: typeClass.type is not a function
at Function.createPublisher (/home/qiuzhong/Workspace/Work/ros2/tmp/rclnodejs/lib/publisher.js:57:26)
at Node.createPublisher (/home/qiuzhong/Workspace/Work/ros2/tmp/rclnodejs/lib/node.js:111:31)
at rclnodejs.init.then (/home/qiuzhong/Workspace/Work/ros2/tmp/publisher.js:106:24)
at process._tickCallback (internal/process/next_tick.js:109:7)
at Module.runMain (module.js:606:11)
at run (bootstrap_node.js:389:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:504:3
Take the
Byteas example, there is aByteArrayWrapperclass in thegenerated/std_msgs/std_msgs__msg__Byte.js. It stands for an array of theBytemessage type. However, it cannot be used tocreatePublisher. This codewill lead a
TypeErrorwhen callscreatePublisher: