CTRE Phoenix 6 C++ 26.50.0-alpha-1
Loading...
Searching...
No Matches
TimeUtil.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) Cross The Road Electronics.  All rights reserved.
3 * License information can be found in CTRE_LICENSE.txt
4 * For support and suggestions contact support@ctr-electronics.com or file
5 * an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases
6 */
7#pragma once
8
9#include <chrono>
10#include <thread>
11
12namespace ctre {
13namespace phoenix {
14namespace platform {
15
16 /**
17 * \param timeUs How long to yield current thread in microseconds (us).
18 * If platform cannot honor us resolution, round up to nearest
19 * value that platform can honor.
20 */
21 static inline void SleepUs(int timeUs)
22 {
23 std::this_thread::sleep_for(std::chrono::microseconds{timeUs});
24 }
25
26 /** The raw current time source. */
27 std::chrono::steady_clock::duration CurrentTimeRaw();
28
29 /**
30 * Returns the current time of the system, converted to the given duration.
31 * The default duration is in microseconds.
32 *
33 * This time source is typically continuous and monotonic. However, it may
34 * be overridden in simulation to use a non-monotonic, non-continuous source.
35 */
36 template <typename DURATION = std::chrono::microseconds>
37 static inline auto CurrentTime()
38 {
39 using namespace std::chrono;
40 return duration_cast<DURATION>(CurrentTimeRaw()).count();
41 }
42
43 /**
44 * Returns the monotonic time of the system, converted to the given duration.
45 * The default duration is in microseconds.
46 *
47 * This time source is guaranteed to be continuous and monotonic.
48 */
49 template <typename DURATION = std::chrono::microseconds>
50 static inline auto SystemTime()
51 {
52 using namespace std::chrono;
53 return duration_cast<DURATION>(steady_clock::now().time_since_epoch()).count();
54 }
55
56} // namespace platform
57} // namespace phoenix
58} // namespace ctre
Definition FrcUsageReport.hpp:13
static auto CurrentTime()
Returns the current time of the system, converted to the given duration.
Definition TimeUtil.hpp:37
static void SleepUs(int timeUs)
Definition TimeUtil.hpp:21
static auto SystemTime()
Returns the monotonic time of the system, converted to the given duration.
Definition TimeUtil.hpp:50
std::chrono::steady_clock::duration CurrentTimeRaw()
The raw current time source.
Definition FrcUsageReport.hpp:12
Definition motor_constants.h:14