38constexpr T
ApplyDeadband(T value, T deadband, T maxMagnitude = T{1.0}) {
40 if constexpr (std::is_arithmetic_v<T>) {
46 if (magnitude > deadband) {
47 if (maxMagnitude / deadband > 1.0E12) {
69 return maxMagnitude * (
value - deadband) / (maxMagnitude - deadband);
86 return maxMagnitude * (
value + deadband) / (maxMagnitude - deadband);
102 T modulus = maximumInput - minimumInput;
105 int numMax = (input - minimumInput) / modulus;
106 input -= numMax * modulus;
109 int numMin = (input - maximumInput) / modulus;
110 input -= numMin * modulus;
127constexpr bool IsNear(T expected, T actual, T tolerance) {
128 if constexpr (std::is_arithmetic_v<T>) {
129 return std::abs(expected - actual) < tolerance;
127constexpr bool IsNear(T expected, T actual, T tolerance) {
…}
156constexpr bool IsNear(T expected, T actual, T tolerance, T min, T max) {
157 T errorBound = (max - min) / 2.0;
160 if constexpr (std::is_arithmetic_v<T>) {
161 return std::abs(error) < tolerance;
156constexpr bool IsNear(T expected, T actual, T tolerance, T min, T max) {
…}
175 units::radian_t{-std::numbers::pi},
176 units::radian_t{std::numbers::pi});
190constexpr std::signed_integral
auto FloorDiv(std::signed_integral
auto x,
191 std::signed_integral
auto y) {
195 if ((x < 0) != (y < 0) && rem != 0) {
190constexpr std::signed_integral
auto FloorDiv(std::signed_integral
auto x, {
…}
212constexpr std::signed_integral
auto FloorMod(std::signed_integral
auto x,
213 std::signed_integral
auto y) {
212constexpr std::signed_integral
auto FloorMod(std::signed_integral
auto x, {
…}
229 units::meters_per_second_t maxVelocity) {
230 if (maxVelocity < 0_mps) {
232 "maxVelocity must be a non-negative number, got {}!", maxVelocity);
236 units::meter_t dist = diff.
Norm();
240 if (dist > maxVelocity * dt) {
242 return current + diff * (maxVelocity * dt / dist);
259 units::meters_per_second_t maxVelocity) {
260 if (maxVelocity < 0_mps) {
262 "maxVelocity must be a non-negative number, got {}!", maxVelocity);
266 units::meter_t dist = diff.
Norm();
270 if (dist > maxVelocity * dt) {
272 return current + diff * (maxVelocity * dt / dist);
#define WPILIB_DLLEXPORT
Definition SymbolExports.h:36
Represents a translation in 2D space.
Definition Translation2d.h:29
constexpr units::meter_t Norm() const
Returns the norm, or distance from the origin to the translation.
Definition Translation2d.h:106
Represents a translation in 3D space.
Definition Translation3d.h:26
constexpr units::meter_t Norm() const
Returns the norm, or distance from the origin to the translation.
Definition Translation3d.h:130
static void ReportError(const S &format, Args &&... args)
Definition MathShared.h:62
constexpr UnitType abs(const UnitType x) noexcept
Compute absolute value.
Definition math.h:726
@ value
the parser finished reading a JSON value
constexpr T ApplyDeadband(T value, T deadband, T maxMagnitude=T{1.0})
Returns 0.0 if the given value is within the specified range around zero.
Definition MathUtil.h:38
constexpr std::signed_integral auto FloorMod(std::signed_integral auto x, std::signed_integral auto y)
Returns the floor modulus of the int arguments.
Definition MathUtil.h:212
WPILIB_DLLEXPORT constexpr units::radian_t AngleModulus(units::radian_t angle)
Wraps an angle to the range -π to π radians (-180 to 180 degrees).
Definition MathUtil.h:173
constexpr bool IsNear(T expected, T actual, T tolerance)
Checks if the given value matches an expected value within a certain tolerance.
Definition MathUtil.h:127
constexpr std::signed_integral auto FloorDiv(std::signed_integral auto x, std::signed_integral auto y)
Returns the largest (closest to positive infinity) int value that is less than or equal to the algebr...
Definition MathUtil.h:190
constexpr Translation2d SlewRateLimit(const Translation2d ¤t, const Translation2d &next, units::second_t dt, units::meters_per_second_t maxVelocity)
Limits translation velocity.
Definition MathUtil.h:226
constexpr T InputModulus(T input, T minimumInput, T maximumInput)
Returns modulus of input.
Definition MathUtil.h:101
constexpr T abs(const T x) noexcept
Compile-time absolute value function.
Definition abs.hpp:40
constexpr bool is_unit_t_v
Definition base.h:1870