CTRE Phoenix 6 C++ 26.0.0-beta-1
Loading...
Searching...
No Matches
Utils.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
10#include <units/time.h>
11
12#include "frc/Timer.h"
13
14namespace ctre {
15namespace phoenix6 {
16namespace utils {
17
18 /**
19 * \brief Get the current timestamp.
20 *
21 * This is the time source used for status signals.
22 *
23 * This time source is typically continuous and monotonic.
24 * However, it may be overridden in simulation to use a
25 * non-monotonic, non-continuous source.
26 *
27 * \returns Current time
28 */
29 inline units::second_t GetCurrentTime()
30 {
31 return units::second_t{GetCurrentTimeSeconds()};
32 }
33 /**
34 * \brief Get the system timestamp.
35 *
36 * This is NOT the time source used for status signals.
37 * Use GetCurrentTime instead when working with status
38 * signal timing.
39 *
40 * This time source is guaranteed to be continuous and
41 * monotonic, making it useful for measuring time deltas
42 * in a robot program.
43 *
44 * \returns System time
45 */
46 inline units::second_t GetSystemTime()
47 {
48 return units::second_t{GetSystemTimeSeconds()};
49 }
50
51 /**
52 * \brief Converts an FPGA timestamp to the timebase
53 * reported by GetCurrentTime().
54 *
55 * \param fpgaTime The FPGA timestamp
56 * \returns The equivalent GetCurrentTime() timestamp
57 */
58 inline units::second_t FPGAToCurrentTime(units::second_t fpgaTime)
59 {
60 if (IsReplay()) {
61 return (GetCurrentTime() - frc::Timer::GetTimestamp()) + fpgaTime;
62 } else {
63 return (GetCurrentTime() - frc::Timer::GetFPGATimestamp()) + fpgaTime;
64 }
65 }
66 /**
67 * \brief Converts a timestamp in the timebase reported
68 * by GetCurrentTime() to an FPGA timestamp.
69 *
70 * \param currentTime The timestamp reported by GetCurrentTime()
71 * \returns The equivalent FPGA timestamp
72 */
73 inline units::second_t CurrentTimeToFPGATime(units::second_t currentTime)
74 {
75 if (IsReplay()) {
76 return (frc::Timer::GetTimestamp() - GetCurrentTime()) + currentTime;
77 } else {
78 return (frc::Timer::GetFPGATimestamp() - GetCurrentTime()) + currentTime;
79 }
80 }
81
82}
83}
84}
units::second_t CurrentTimeToFPGATime(units::second_t currentTime)
Converts a timestamp in the timebase reported by GetCurrentTime() to an FPGA timestamp.
Definition Utils.hpp:73
units::second_t GetSystemTime()
Get the system timestamp.
Definition Utils.hpp:46
CTREXPORT double GetSystemTimeSeconds()
Get the system timestamp in seconds.
CTREXPORT double GetCurrentTimeSeconds()
Get the current timestamp in seconds.
CTREXPORT bool IsReplay()
Get whether the program is running in replay mode.
units::second_t GetCurrentTime()
Get the current timestamp.
Definition Utils.hpp:29
units::second_t FPGAToCurrentTime(units::second_t fpgaTime)
Converts an FPGA timestamp to the timebase reported by GetCurrentTime().
Definition Utils.hpp:58
Definition motor_constants.h:14