rclnodejs
Version:
ROS2.0 JavaScript client with Node.js
58 lines (48 loc) • 1.46 kB
JavaScript
// Thorough latency/throughput test matching the exact issue scenario
;
const rclnodejs = require('./index.js');
async function main() {
await rclnodejs.init();
const node = new rclnodejs.Node('test_node');
let lastTs;
let msgCount = 0;
const hzSamples = [];
node.createSubscription(
'std_msgs/msg/Float64MultiArray',
'/map_to_base_link_pose2d',
(msg) => {
const now = Date.now();
msgCount++;
if (lastTs) {
const hz = 1000 / (now - lastTs);
hzSamples.push(hz);
console.log('Raw Hz:', hz.toFixed(2));
}
lastTs = now;
}
);
rclnodejs.spin(node);
console.log('Waiting for messages on /map_to_base_link_pose2d at ~10Hz...');
console.log('Run this in another terminal:');
console.log(
' ros2 topic pub -r 10 /map_to_base_link_pose2d std_msgs/msg/Float64MultiArray "{data: [1.0, 2.0, 3.0]}"'
);
setTimeout(() => {
if (hzSamples.length > 0) {
const avgHz = hzSamples.reduce((a, b) => a + b, 0) / hzSamples.length;
console.log(`\n--- Summary ---`);
console.log(`Messages: ${msgCount}, Avg Hz: ${avgHz.toFixed(2)}`);
if (avgHz < 5) {
console.log('*** REGRESSION DETECTED ***');
} else {
console.log('Performance OK');
}
} else {
console.log('No messages received');
}
node.stop();
rclnodejs.shutdown();
process.exit(0);
}, 15000);
}
main().catch(console.error);