[wpilib] Add timestamp getters with configurable time base (#7378)

This commit is contained in:
Jonah Bonner
2024-11-16 10:43:38 -05:00
committed by GitHub
parent 91142ba5fe
commit ca51197486
27 changed files with 180 additions and 53 deletions

View File

@@ -36,7 +36,7 @@ Timer::Timer() {
units::second_t Timer::Get() const {
if (m_running) {
return (GetFPGATimestamp() - m_startTime) + m_accumulatedTime;
return (GetTimestamp() - m_startTime) + m_accumulatedTime;
} else {
return m_accumulatedTime;
}
@@ -44,12 +44,12 @@ units::second_t Timer::Get() const {
void Timer::Reset() {
m_accumulatedTime = 0_s;
m_startTime = GetFPGATimestamp();
m_startTime = GetTimestamp();
}
void Timer::Start() {
if (!m_running) {
m_startTime = GetFPGATimestamp();
m_startTime = GetTimestamp();
m_running = true;
}
}
@@ -88,6 +88,10 @@ bool Timer::IsRunning() const {
return m_running;
}
units::second_t Timer::GetTimestamp() {
return units::second_t{frc::RobotController::GetTime() * 1.0e-6};
}
units::second_t Timer::GetFPGATimestamp() {
// FPGA returns the timestamp in microseconds
return units::second_t{frc::RobotController::GetFPGATime() * 1.0e-6};