CTRE Phoenix 6 C++ 25.0.0-beta-4
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 return (GetCurrentTime() - frc::Timer::GetFPGATimestamp()) + fpgaTime;
61 }
62
63}
64}
65}
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.
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 StatusCodes.h:18