roslibjs icon indicating copy to clipboard operation
roslibjs copied to clipboard

How to set the header timestamp for ros2 via ros2-web-bridge

Open ManuelZ opened this issue 4 years ago • 1 comments

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_msg uses ROS_TIME as seen here to go from builtin_interfaces.msg.Time to a rclpy.time.Time class.
  • ROS_TIME may 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.

ManuelZ avatar Apr 06 '21 19:04 ManuelZ

I don't know anything about integration/compatibility if ROS2. Maybe @RobotWebTools/ros2-0 can help you out.

MatthijsBurgh avatar Aug 26 '21 15:08 MatthijsBurgh