gazebosim / gz-sim

Open source robotics simulator. The latest version of Gazebo.
https://gazebosim.org
Apache License 2.0
685 stars 262 forks source link

Incorrect warning msg when sim jumps back in time #2407

Closed iche033 closed 3 months ago

iche033 commented 4 months ago

Environment

In many of gz-sim's systems PostUpdate function, there is this code to print warning msg:

  if (_info.dt < std::chrono::steady_clock::duration::zero())
  {
    gzwarn << "Detected jump back in time ["
        << std::chrono::duration_cast<std::chrono::seconds>(_info.dt).count()
        << "s]. System may not work properly." << std::endl;
  }

The problem is that if _info.dt is smaller than 1 sec, std::chrono::duration_cast<std::chrono::seconds>(_info.dt).count() would produce 0, and the msg will output jump back in time [0s]

A quick fix is to change all instances of this code to std::chrono::duration<double>(_info.dt).count()

AddisonFarley commented 3 months ago

I've submitted a PR for your suggested change to the 26 files I found with this function. Your solution made sense as a double is all that is needed to track any number 0>x>1.

This is my first contribution to GZ-Sim and I tried to follow the contribution guide to the best of my ability. Any feedback is more than welcome!