12 #include <mrpt/config.h> 18 #if defined(MRPT_OS_LINUX) 34 const int64_t wait_tim_ns =
35 static_cast<int64_t
>(1.0e9 * (period - elapsed_tim));
36 if (elapsed_tim > period || wait_tim_ns <= 0)
42 #if !defined(MRPT_OS_LINUX) 43 std::this_thread::sleep_for(std::chrono::nanoseconds(wait_tim_ns));
45 timespec ts{0, 0}, ts_remainer{0, 0};
46 ts.tv_sec = wait_tim_ns / 1000000000;
47 ts.tv_nsec = wait_tim_ns % 1000000000;
55 int err = clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, &ts_remainer);
63 stderr,
"[CRateTimer::sleep] Error %i in clock_nanosleep()\n", err);
double Tac() noexcept
Stops the stopwatch.
bool sleep()
Sleeps for some time, such as the return of this method is 1/rate (seconds) after the return of the p...
CRateTimer(const double rate_hz=1.0)
Ctor: specifies the desired rate (Hz)
mrpt::system::CTicTac m_tictac
#define ASSERT_ABOVEEQ_(__A, __B)
int fprintf(FILE *fil, const char *format,...) noexcept MRPT_printf_format_check(2
An OS-independent version of fprintf.
void setRate(const double rate_hz)
Changes the object loop rate (Hz)
#define ASSERT_ABOVE_(__A, __B)
#define ASSERT_BELOWEQ_(__A, __B)
void Tic() noexcept
Starts the stopwatch.