bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
timing.h
Go to the documentation of this file.
1#ifndef BITSIM_UTILS_TIMING_H
2#define BITSIM_UTILS_TIMING_H
3
8
10
11#include <chrono>
12#include <thread>
13
14namespace bitsim
15{
16namespace utils
17{
18
19using WallClock = std::chrono::steady_clock;
20
24inline real_t seconds_between(WallClock::time_point from, WallClock::time_point to)
25{
26 return std::chrono::duration<real_t>(to - from).count();
27}
28
32inline real_t milliseconds_since(WallClock::time_point t)
33{
34 return std::chrono::duration<real_t, std::milli>(WallClock::now() - t).count();
35}
36
41inline void sleep_until_step(WallClock::time_point start, long step, real_t step_size)
42{
43 std::this_thread::sleep_until(
44 start + std::chrono::microseconds(static_cast<long>(1.0e6 * step_size * step)));
45}
46
47} // namespace utils
48} // namespace bitsim
49
50#endif // BITSIM_UTILS_TIMING_H
The basic types of bitsim. Code outside this file names Eigen's matrix and vector types only through ...
Definition bitsim_utils.h:11
real_t milliseconds_since(WallClock::time_point t)
The milliseconds since a time point.
Definition timing.h:32
real_t seconds_between(WallClock::time_point from, WallClock::time_point to)
The seconds from one time point to another.
Definition timing.h:24
std::chrono::steady_clock WallClock
Definition timing.h:19
void sleep_until_step(WallClock::time_point start, long step, real_t step_size)
Sleep until step steps of step_size [s] after start, so that a loop that calls this every step keeps ...
Definition timing.h:41
Definition dc_motor_backend_base.h:9
double real_t
real_t
Definition bitsim_types.h:20