mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
[wpilib] Add timestamp getters with configurable time base (#7378)
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
#include <units/temperature.h>
|
||||
@@ -78,6 +79,24 @@ class RobotController {
|
||||
*/
|
||||
static int32_t GetTeamNumber();
|
||||
|
||||
/**
|
||||
* Sets a new source to provide the clock time in microseconds. Changing this
|
||||
* affects the return value of {@code GetTime}.
|
||||
*
|
||||
* @param supplier Function to return the time in microseconds.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @return The current time in microseconds.
|
||||
*/
|
||||
static uint64_t GetTime();
|
||||
|
||||
/**
|
||||
* Read the microsecond-resolution timer on the FPGA.
|
||||
*
|
||||
@@ -320,6 +339,9 @@ class RobotController {
|
||||
* @return The status of the CAN bus
|
||||
*/
|
||||
static CANStatus GetCANStatus();
|
||||
|
||||
private:
|
||||
static std::function<uint64_t()> m_timeSource;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -56,6 +56,17 @@ class TimedRobot : public IterativeRobotBase {
|
||||
|
||||
~TimedRobot() override;
|
||||
|
||||
/**
|
||||
* Return the system clock time in micrseconds 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).
|
||||
*
|
||||
* @return Robot running time in microseconds, as of the start of the current
|
||||
* periodic function.
|
||||
*/
|
||||
uint64_t GetLoopStartTime();
|
||||
|
||||
/**
|
||||
* Add a callback to run at a specific period with a starting time offset.
|
||||
*
|
||||
@@ -103,6 +114,7 @@ class TimedRobot : public IterativeRobotBase {
|
||||
|
||||
hal::Handle<HAL_NotifierHandle, HAL_CleanNotifier> m_notifier;
|
||||
std::chrono::microseconds m_startTime;
|
||||
uint64_t m_loopStartTimeUs = 0;
|
||||
|
||||
wpi::priority_queue<Callback, std::vector<Callback>, std::greater<Callback>>
|
||||
m_callbacks;
|
||||
|
||||
@@ -118,6 +118,16 @@ 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.
|
||||
*
|
||||
* @returns Robot running time in seconds.
|
||||
*/
|
||||
static units::second_t GetTimestamp();
|
||||
|
||||
/**
|
||||
* Return the FPGA system clock time in seconds.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user