roslibjs
roslibjs copied to clipboard
How to set the header timestamp for ros2 via ros2-web-bridge
Apparently Rclnodejs doesn't automatically set the stamp field (or at least doesn't do it when the header has some other field populated): https://github.com/RobotWebTools/ros2-web-bridge/issues/149#issuecomment-651249741
So I need to populate it. To do so I must know which is the epoch used by ROS2:
-
from_msgusesROS_TIMEas seen here to go frombuiltin_interfaces.msg.Timeto arclpy.time.Timeclass. -
ROS_TIMEmay be based on the Unix epoch or in the simulation time as stated here.
I see that both the Unix epoch and the JS epoch start at Jan 1 1970 so I guess this would work just fine:
let request = new ROSLIB.Message({
header: {
// rclnodejs doesn't automatically set the timestamp
stamp: {
sec: Math.floor( new Date() / 1000 ) ???,
nanosec: window.performance.now() ???,
},
frame_id: somethinghere
},
});
Is this the right way of setting the timestamp? I guess it would work for non-simulation scenarios.
I don't know anything about integration/compatibility if ROS2. Maybe @RobotWebTools/ros2-0 can help you out.