[hal,wpilib] Rename FPGA clock to monotonic clock (#8672)

- Remove status return from HAL level (clock getting should never fail)
- Remove 32-bit timestamp expand function
- Make monotonic_clock.hpp (formerly fpga_clock.hpp) header-only and
move to root hal include directory
This commit is contained in:
Peter Johnson
2026-03-15 15:08:41 -07:00
committed by GitHub
parent 1a5b023235
commit e944ae9aca
59 changed files with 233 additions and 358 deletions

View File

@@ -64,9 +64,10 @@ class TimedRobot : public IterativeRobotBase {
/**
* Return the system clock time in microseconds for the start of the current
* periodic loop. This is in the same time base as Timer.GetFPGATimestamp(),
* but is stable through a loop. It is updated at the beginning of every
* periodic callback (including the normal periodic loop).
* periodic loop. This is in the same time base as
* Timer.GetMonotonicTimestamp(), but is stable through a loop. It is updated
* at the beginning of every periodic callback (including the normal periodic
* loop).
*
* @return Robot running time in microseconds, as of the start of the current
* periodic function.
@@ -107,11 +108,11 @@ class TimedRobot : public IterativeRobotBase {
std::chrono::microseconds period, std::chrono::microseconds offset)
: func{std::move(func)},
period{period},
expirationTime(
startTime + offset + period +
(std::chrono::microseconds{wpi::RobotController::GetFPGATime()} -
startTime) /
period * period) {}
expirationTime(startTime + offset + period +
(std::chrono::microseconds{
wpi::RobotController::GetMonotonicTime()} -
startTime) /
period * period) {}
bool operator>(const Callback& rhs) const {
return expirationTime > rhs.expirationTime;

View File

@@ -114,7 +114,7 @@ class MotorSafety {
bool m_enabled = false;
// The FPGA clock value when the motor has expired
wpi::units::second_t m_stopTime = Timer::GetFPGATimestamp();
wpi::units::second_t m_stopTime = Timer::GetMonotonicTimestamp();
mutable wpi::util::mutex m_thisMutex;
};

View File

@@ -91,9 +91,10 @@ class PeriodicOpMode : public OpMode {
/**
* Return the system clock time in microseconds for the start of the current
* periodic loop. This is in the same time base as Timer.getFPGATimestamp(),
* but is stable through a loop. It is updated at the beginning of every
* periodic callback (including the normal periodic loop).
* periodic loop. This is in the same time base as
* Timer::GetMonotonicTimestamp(), but is stable through a loop. It is updated
* at the beginning of every periodic callback (including the normal periodic
* loop).
*
* @return Robot running time in microseconds, as of the start of the current
* periodic function.

View File

@@ -60,22 +60,21 @@ class RobotController {
static void SetTimeSource(std::function<uint64_t()> supplier);
/**
* Read the microsecond timestamp. By default, the time is based on the FPGA
* hardware clock in microseconds since the FPGA started. However, the return
* value of this method may be modified to use any time base, including
* non-monotonic and non-continuous time bases.
* Read the microsecond timestamp. By default, the time is based on the
* monotonic clock. However, the return value of this method may be modified
* to use any time base, including non-monotonic and non-continuous time
* bases.
*
* @return The current time in microseconds.
*/
static uint64_t GetTime();
/**
* Read the microsecond-resolution timer on the FPGA.
* Read the microsecond-resolution monotonic timer.
*
* @return The current time in microseconds according to the FPGA (since FPGA
* reset).
* @return The current monotonic time in microseconds.
*/
static uint64_t GetFPGATime();
static uint64_t GetMonotonicTime();
/**
* Read the battery voltage.

View File

@@ -25,7 +25,7 @@ void Wait(wpi::units::second_t seconds);
* @return The time, just in case you want the robot to start autonomous at 8pm
* on Saturday.
*/
wpi::units::second_t GetTime();
wpi::units::second_t GetSystemTime();
/**
* A timer class.
@@ -119,24 +119,22 @@ class Timer {
bool IsRunning() const;
/**
* Return the clock time in seconds. By default, the time is based on the FPGA
* hardware clock in seconds since the FPGA started. However, the return value
* of this method may be modified to use any time base, including
* non-monotonic time bases.
* Return the clock time in seconds. By default, the time is the time returned
* by GetMonotonicTimestamp(). However, the return value of this method may be
* modified to use any time base, including non-monotonic time bases.
*
* @returns Robot running time in seconds.
*/
static wpi::units::second_t GetTimestamp();
/**
* Return the FPGA system clock time in seconds.
* Return the monotonic clock time in seconds.
*
* Return the time from the FPGA hardware clock in seconds since the FPGA
* started. Rolls over after 71 minutes.
* Return the time from the monotonic clock in seconds.
*
* @returns Robot running time in seconds.
* @returns Monotonic time in seconds.
*/
static wpi::units::second_t GetFPGATimestamp();
static wpi::units::second_t GetMonotonicTimestamp();
/**
* Return the approximate match time. The FMS does not send an official match

View File

@@ -7,7 +7,7 @@
#include <chrono>
#include <string_view>
#include "wpi/hal/cpp/fpga_clock.hpp"
#include "wpi/hal/monotonic_clock.hpp"
#include "wpi/util/StringMap.hpp"
namespace wpi::util {
@@ -65,9 +65,9 @@ class Tracer {
private:
static constexpr std::chrono::milliseconds kMinPrintPeriod{1000};
wpi::hal::fpga_clock::time_point m_startTime;
wpi::hal::fpga_clock::time_point m_lastEpochsPrintTime =
wpi::hal::fpga_clock::epoch();
wpi::hal::monotonic_clock::time_point m_startTime;
wpi::hal::monotonic_clock::time_point m_lastEpochsPrintTime =
wpi::hal::monotonic_clock::epoch();
wpi::util::StringMap<std::chrono::nanoseconds> m_epochs;
};