38constexpr T
ApplyDeadband(T value, T deadband, T maxMagnitude = T{1.0}) {
40 if constexpr (std::is_arithmetic_v<T>) {
46 if (magnitude < deadband) {
71 return (1.0 + deadband / (maxMagnitude - deadband)) * (
value - deadband);
93 return (1.0 + deadband / (maxMagnitude - deadband)) * (
value + deadband);
120constexpr T
CopySignPow(T value,
double exponent, T maxMagnitude = T{1.0}) {
121 if constexpr (std::is_arithmetic_v<T>) {
142 T modulus = maximumInput - minimumInput;
145 int numMax = (input - minimumInput) / modulus;
146 input -= numMax * modulus;
149 int numMin = (input - maximumInput) / modulus;
150 input -= numMin * modulus;
167constexpr bool IsNear(T expected, T actual, T tolerance) {
168 if constexpr (std::is_arithmetic_v<T>) {
169 return std::abs(expected - actual) < tolerance;
196constexpr bool IsNear(T expected, T actual, T tolerance, T min, T max) {
197 T errorBound = (max - min) / 2.0;
200 if constexpr (std::is_arithmetic_v<T>) {
201 return std::abs(error) < tolerance;
215 units::radian_t{-std::numbers::pi},
216 units::radian_t{std::numbers::pi});
230constexpr std::signed_integral
auto FloorDiv(std::signed_integral
auto x,
231 std::signed_integral
auto y) {
235 if ((x < 0) != (y < 0) && rem != 0) {
252constexpr std::signed_integral
auto FloorMod(std::signed_integral
auto x,
253 std::signed_integral
auto y) {
269 units::meters_per_second_t maxVelocity) {
270 if (maxVelocity < 0_mps) {
272 "maxVelocity must be a non-negative number, got {}!", maxVelocity);
276 units::meter_t dist = diff.
Norm();
280 if (dist > maxVelocity * dt) {
282 return current + diff * (maxVelocity * dt / dist);
299 units::meters_per_second_t maxVelocity) {
300 if (maxVelocity < 0_mps) {
302 "maxVelocity must be a non-negative number, got {}!", maxVelocity);
306 units::meter_t dist = diff.
Norm();
310 if (dist > maxVelocity * dt) {
312 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:30
constexpr units::meter_t Norm() const
Returns the norm, or distance from the origin to the translation.
Definition Translation3d.h:134
static void ReportError(const S &format, Args &&... args)
Definition MathShared.h:48
constexpr UnitType abs(const UnitType x) noexcept
Compute absolute value.
Definition math.h:726
constexpr UnitTypeLhs copysign(const UnitTypeLhs x, const UnitTypeRhs y) noexcept
Copy sign.
Definition math.h:615
@ value
the parser finished reading a JSON value
Definition SystemServer.h:9
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:252
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:213
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:167
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:230
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:266
constexpr T InputModulus(T input, T minimumInput, T maximumInput)
Returns modulus of input.
Definition MathUtil.h:141
constexpr T CopySignPow(T value, double exponent, T maxMagnitude=T{1.0})
Raises the input to the power of the given exponent while preserving its sign.
Definition MathUtil.h:120
constexpr T abs(const T x) noexcept
Compile-time absolute value function.
Definition abs.hpp:40
constexpr T1 copysign(const T1 x, const T2 y) noexcept
Compile-time copy sign function.
Definition copysign.hpp:41
constexpr common_t< T1, T2 > pow(const T1 base, const T2 exp_term) noexcept
Compile-time power function.
Definition pow.hpp:82
constexpr bool is_unit_t_v
Definition base.h:1870