roscpp_core icon indicating copy to clipboard operation
roscpp_core copied to clipboard

Resolution of ros::Duration::sleep() limited by implicit sleep in nanoseconds

Open YoshuaNava opened this issue 3 years ago • 0 comments

Hi, By reading through the code of the rostime package I found that ros::Duration::sleep() has an internal sleep in wall time with a length of 1,000,000 nanoseconds = 1 millisecond. Code -> https://github.com/ros/roscpp_core/blob/noetic-devel/rostime/src/time.cpp#L402

As far as I understand, the internal call to ros_wallsleep(0, 1000000); is limiting the maximum resolution of ros::Duration::sleep() to 1 millisecond in wall time.

I intend to use ros::Time inside a node that spins at a rate of 400Hz (every 2.5ms), and this aspect of the current implementation would not allow me to sleep() with a fine-enough resolution. Due to the 1ms resolution, sleep would wake up at t=2ms, or t=3ms, but never t=2.5ms.

Therefore, I have two related questions:

  1. Can one of the authors/maintainers/users confirm whether my observation is true/valid?
  2. If 1 is true, would you be open to a fix/extension to allow more fine-grained sleep durations? For example, through an optional parameter on the sleep function:
bool Duration::sleep(const uint32_t min_wall_sleep_time_ns = 1000000) const;

Thank you very much in advance.

Best regards, Yoshua Nava

YoshuaNava avatar Mar 21 '22 22:03 YoshuaNava