Browse Source

SITL: get_wall_time_us() to use a monotonic clock on non-Windows systems

zr-v5.1
Alexander Maryanovsky 5 years ago committed by Andrew Tridgell
parent
commit
d73043fc2f
  1. 6
      libraries/SITL/SIM_Aircraft.cpp
  2. 2
      libraries/SITL/SIM_Aircraft.h

6
libraries/SITL/SIM_Aircraft.cpp

@ -447,9 +447,9 @@ uint64_t Aircraft::get_wall_time_us() const @@ -447,9 +447,9 @@ uint64_t Aircraft::get_wall_time_us() const
tPrev = now;
return last_ret_us;
#else
struct timeval tp;
gettimeofday(&tp, nullptr);
return static_cast<uint64_t>(tp.tv_sec * 1.0e6 + tp.tv_usec);
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return uint64_t(ts.tv_sec * 1000000ULL + ts.tv_nsec / 1000ULL);
#endif
}

2
libraries/SITL/SIM_Aircraft.h

@ -248,7 +248,7 @@ protected: @@ -248,7 +248,7 @@ protected:
/* add noise based on throttle level (from 0..1) */
void add_noise(float throttle);
/* return wall clock time in microseconds since 1970 */
/* return a monotonic wall clock time in microseconds */
uint64_t get_wall_time_us(void) const;
// update attitude and relative position

Loading…
Cancel
Save