Galaxis Codebase  1.0.0
Team Galaxis software stack for the Carolo Cup 2023 - ROS2 based software
clock.cpp
Go to the documentation of this file.
1 #include "utils/clock.hpp"
2 #include <chrono>
3 
4 using namespace galaxis::utils;
5 
7  auto time_now = std::chrono::system_clock::now();
8  auto time_now_ms = std::chrono::time_point_cast<std::chrono::milliseconds>(time_now);
9  auto time_value = time_now_ms.time_since_epoch();
10  return time_value.count();
11 }
12 
14  auto time_now = std::chrono::high_resolution_clock::now();
15  auto time_now_ns = std::chrono::time_point_cast<std::chrono::microseconds>(time_now);
16  auto time_value = time_now_ns.time_since_epoch();
17  return time_value.count();
18 }
19 
20 // class MicroStopwatch
22  start();
23 }
24 
27 }
28 
29 long long MicroStopwatch::get() const {
30  return get_time_now_us() - time;
31 }
32 
33 long long MicroStopwatch::get_time() const {
34  return get();
35 }
36 
38  return get() / 1000;
39 }
40 
42  start();
43 }
galaxis::utils::get_time_now_us
long long get_time_now_us()
Definition: clock.cpp:13
galaxis::utils::MicroStopwatch::MicroStopwatch
MicroStopwatch()
Definition: clock.cpp:21
clock.hpp
galaxis::utils::MicroStopwatch::restart
void restart()
Definition: clock.cpp:41
galaxis::utils::MicroStopwatch::start
void start()
Definition: clock.cpp:25
galaxis::utils::MicroStopwatch::time
long long time
Definition: clock.hpp:12
galaxis::utils::MicroStopwatch::get
long long get() const
Definition: clock.cpp:29
galaxis::utils::MicroStopwatch::get_time
long long get_time() const
Definition: clock.cpp:33
galaxis::utils::MicroStopwatch::get_milliseconds
long long get_milliseconds() const
Definition: clock.cpp:37
galaxis::utils
Definition: clock.hpp:5
galaxis::utils::get_time_now_ms
long long get_time_now_ms()
Definition: clock.cpp:6