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

This commit is contained in:
Alexander Maryanovsky 2020-02-18 15:42:25 +02:00 committed by Andrew Tridgell
parent 0d5a0f392c
commit d73043fc2f
2 changed files with 4 additions and 4 deletions

View File

@ -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
}

View File

@ -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