mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
[hal] Counter/Encoder: use std::numeric_limits::infinity (#6941)
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "hal/Counter.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "ConstantsInternal.h"
|
||||
@@ -300,19 +302,14 @@ double HAL_GetCounterPeriod(HAL_CounterHandle counterHandle, int32_t* status) {
|
||||
return 0.0;
|
||||
}
|
||||
tCounter::tTimerOutput output = counter->counter->readTimerOutput(status);
|
||||
double period;
|
||||
if (output.Stalled) {
|
||||
// Return infinity
|
||||
double zero = 0.0;
|
||||
period = 1.0 / zero;
|
||||
} else {
|
||||
// output.Period is a fixed point number that counts by 2 (24 bits, 25
|
||||
// integer bits)
|
||||
period = static_cast<double>(output.Period << 1) /
|
||||
static_cast<double>(output.Count);
|
||||
return std::numeric_limits<double>::infinity();
|
||||
}
|
||||
return static_cast<double>(period *
|
||||
2.5e-8); // result * timebase (currently 25ns)
|
||||
// output.Period is a fixed point number that counts by 2 (24 bits, 25
|
||||
// integer bits)
|
||||
double period = static_cast<double>(output.Period << 1) /
|
||||
static_cast<double>(output.Count);
|
||||
return period * 2.5e-8; // result * timebase (currently 25ns)
|
||||
}
|
||||
|
||||
void HAL_SetCounterMaxPeriod(HAL_CounterHandle counterHandle, double maxPeriod,
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "FPGAEncoder.h"
|
||||
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
|
||||
#include <fmt/format.h>
|
||||
@@ -128,18 +129,14 @@ double HAL_GetFPGAEncoderPeriod(HAL_FPGAEncoderHandle fpgaEncoderHandle,
|
||||
return 0.0;
|
||||
}
|
||||
tEncoder::tTimerOutput output = encoder->encoder->readTimerOutput(status);
|
||||
double value;
|
||||
if (output.Stalled) {
|
||||
// Return infinity
|
||||
double zero = 0.0;
|
||||
value = 1.0 / zero;
|
||||
} else {
|
||||
// output.Period is a fixed point number that counts by 2 (24 bits, 25
|
||||
// integer bits)
|
||||
value = static_cast<double>(output.Period << 1) /
|
||||
static_cast<double>(output.Count);
|
||||
return std::numeric_limits<double>::infinity();
|
||||
}
|
||||
double measuredPeriod = value * 2.5e-8;
|
||||
// output.Period is a fixed point number that counts by 2 (24 bits, 25
|
||||
// integer bits)
|
||||
double value = static_cast<double>(output.Period << 1) /
|
||||
static_cast<double>(output.Count);
|
||||
double measuredPeriod = value * 2.5e-8; // result * timebase (currently 25ns)
|
||||
return measuredPeriod / DECODING_SCALING_FACTOR;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user