cyberbotics / webots

Webots Robot Simulator
https://cyberbotics.com
Apache License 2.0
3.21k stars 1.68k forks source link

ROS sensor messages from the same update have slightly different timestamps #6524

Open lucasw opened 6 months ago

lucasw commented 6 months ago

Describe the Bug

Sensors all have slightly different timestamps even though their data is from the same sim update step. Perhaps this is desirable behavior, adds realistic noise to the system, so a fix could be made optional, though in my case I'm building an Odometry message out of gyro, gps, & inertial sensors so I'd like them to be exactly synchronized rather than approximately.

Using an approximate time sync message filter in ros is a workaround, but I'd rather synchronize right at the source.

Instead of assigning a new ros::Time::now() per sensor right before it publishes (https://github.com/cyberbotics/webots/blob/master/projects/default/controllers/ros/RosGyro.cpp#L40), set a single timestamp in the root sensor update method and pass it down to each sensor publish.

It looks easy enough so I'll do it myself in a few days, though it'll be a lot of 1-2 changes across many files to provide a stamp to every publish method.

Steps to Reproduce

Put multiple sensors on a vehicle and publish them to ros.

Expected behavior

Exact same timestamps from sensors with same update period.

Screenshots

None

System

Additional context

None

omichel commented 5 months ago

Yes, that seems to be a good default behavior. Please go ahead with the implementation and open a PR that we will review.