|
Fang-Robotics-MCB
Fang Robotics Team Codebase
|
#include <wrapped_float.hpp>

Public Member Functions | |
| WrappedFloat (float value, float lowerBound, float upperBound) | |
| WrappedFloat | withSameBounds (const float value) const |
| bool | operator== (const WrappedFloat &other) const |
| void | operator+= (const WrappedFloat &other) |
| void | operator-= (const WrappedFloat &other) |
| WrappedFloat | operator+ (const WrappedFloat &other) const |
| WrappedFloat | operator- (const WrappedFloat &other) const |
| void | operator+= (float other) |
| void | operator-= (float other) |
| WrappedFloat | operator+ (float other) const |
| WrappedFloat | operator- (float other) const |
| float | minDifference (const WrappedFloat &other) const |
| float | minDifference (const float &unwrappedValue) const |
| WrappedFloat | minInterpolate (const WrappedFloat &other, float alpha) const |
| void | shiftBounds (float shiftMagnitude) |
| bool | withinRange (const WrappedFloat &lowerBound, const WrappedFloat &upperBound) const |
| float | getUnwrappedValue () const |
| float | getWrappedValue () const |
| void | setWrappedValue (float newWrappedValue) |
| void | setUnwrappedValue (float newUnwrappedValue) |
| WrappedFloat | getNormalized () const |
| int | getRevolutions () const |
| float | getUpperBound () const |
| float | getLowerBound () const |
Static Public Member Functions | |
| static float | limitValue (const WrappedFloat &valueToLimit, const WrappedFloat &min, const WrappedFloat &max, int *status) |
| static float | limitValue (const WrappedFloat &valueToLimit, const float min, const float max, int *status) |
| static float | rangeOverlap (const WrappedFloat &lowerA, const WrappedFloat &upperA, const WrappedFloat &lowerB, const WrappedFloat &upperB) |
Static Public Attributes | |
| static constexpr float | EPSILON = 1E-8 |
Wraps a float to allow easy comparison and manipulation of sensor readings that wrap (e.g. 0 to 360). Lower bound is "inclusive" and upper bound is "exclusive". The range would be represented as [0, 360).
For bounds 0 - 10, logically:
| tap::algorithms::WrappedFloat::WrappedFloat | ( | float | value, |
| float | lowerBound, | ||
| float | upperBound | ||
| ) |
| [in] | value | value to initialize with (doesn't have to be wrapped) |
| [in] | lowerBound | lower wrapping bound, must be less than upperBound |
| [in] | upperBound | upper wrapping bound, must be higher than lowerBound |
|
inline |
Returns the value's lower bound.
|
inline |
|
inline |
|
inline |
Returns the unwrapped value.
|
inline |
Returns the value's upper bound.
|
inline |
Returns the wrapped value.
|
static |
Runs the limitValue function from above, wrapping the min and max passed in to the same bounds as those of valueToLimit's.
| [in] | valueToLimit | the WrappedFloat whose value it is to limit |
| [in] | min | the WrappedFloat with the same bounds as valueToLimit that valueToLimit will be limited below. |
| [in] | max | the WrappedFloat with the same bounds as valueToLimit that valueToLimit will be limited above. |
| [out] | status | the status result (what operation the limitValue function performed). The status codes are described below:
|
An assertion error if the WrappedFloats have different lower and upper bounds.
|
static |
Limits the passed WrappedFloat between the closest of the min or max value if outside the min and max value's wrapped range.
The min and max must have the same wrapped bounds as the valueToLimit.
For example given a value wrapped from -10 to 10, with the following conditions:
| [in] | valueToLimit | the WrappedFloat whose value it is to limit |
| [in] | min | the WrappedFloat with the same bounds as valueToLimit that valueToLimit will be limited below. |
| [in] | max | the WrappedFloat with the same bounds as valueToLimit that valueToLimit will be limited above. |
| [out] | status | the status result (what operation the limitValue function performed). The status codes are described below:
|
An assertion error if the WrappedFloats have different lower and upper bounds.
| float tap::algorithms::WrappedFloat::minDifference | ( | const float & | unwrappedValue | ) | const |
Finds the minimum difference against another value. Can be thought of as the minimum distance between two points on a circle's perimeter.
| [in] | unwrappedValue | The float to compute the minDifference with. It's wrapped before computing |
An assertion error if the two WrappedFloats have different lower and upper bounds.
| float tap::algorithms::WrappedFloat::minDifference | ( | const WrappedFloat & | other | ) | const |
Finds the minimum difference against another wrapped value. Can be thought of as the minimum distance between two points on a circle's perimeter.
| [in] | other | The WrappedFloat to compute the minDifference with. |
An assertion error if the two WrappedFloats have different lower and upper bounds.
| WrappedFloat tap::algorithms::WrappedFloat::minInterpolate | ( | const WrappedFloat & | other, |
| float | alpha | ||
| ) | const |
Interpolates along the smallest difference with another WrappedFloat.
| [in] | other | The WrappedFloat to interpolate between. |
| [in] | alpha | A float between 0-1 (0 returns this WrappedFloat's value, 1 returns the other's) |
An assertion error if the two WrappedFloats have different lower and upper bounds.
| WrappedFloat tap::algorithms::WrappedFloat::operator+ | ( | const WrappedFloat & | other | ) | const |
Adds a given WrappedFloat to this WrappedFloat given they have the same lower and upper bounds, returning the resultant WrappedFloat.
| [in] | other | The WrappedFloat to be added with this WrappedFloat. |
other and this. An assertion error if the two WrappedFloats have different lower and upper bounds.
| WrappedFloat tap::algorithms::WrappedFloat::operator+ | ( | float | other | ) | const |
Adds a given WrappedFloat to this WrappedFloat given they have the same lower and upper bounds, returning the resultant WrappedFloat.
| [in] | other | The WrappedFloat to be added with this WrappedFloat. |
other and this. An assertion error if the two WrappedFloats have different lower and upper bounds.
| void tap::algorithms::WrappedFloat::operator+= | ( | const WrappedFloat & | other | ) |
Adds a WrappedFloat to this WrappedFloat given they have the same lower and upper bounds.
| [in] | other | The WrappedFloat to be added to this WrappedFloat. |
An assertion error if the two WrappedFloats have different lower and upper bounds.
| void tap::algorithms::WrappedFloat::operator+= | ( | float | other | ) |
Adds a WrappedFloat to this WrappedFloat given they have the same lower and upper bounds.
| [in] | other | The WrappedFloat to be added to this WrappedFloat. |
An assertion error if the two WrappedFloats have different lower and upper bounds.
| WrappedFloat tap::algorithms::WrappedFloat::operator- | ( | const WrappedFloat & | other | ) | const |
Subtracts a given WrappedFloat from this WrappedFloat given they have the same lower and upper bounds, returning the resultant WrappedFloat.
| [in] | other | The WrappedFloat to be subtracted from this WrappedFloat. |
other from this. An assertion error if the two WrappedFloats have different lower and upper bounds.
| WrappedFloat tap::algorithms::WrappedFloat::operator- | ( | float | other | ) | const |
Subtracts a given WrappedFloat from this WrappedFloat given they have the same lower and upper bounds, returning the resultant WrappedFloat.
| [in] | other | The WrappedFloat to be subtracted from this WrappedFloat. |
other from this. An assertion error if the two WrappedFloats have different lower and upper bounds.
| void tap::algorithms::WrappedFloat::operator-= | ( | const WrappedFloat & | other | ) |
Subtracts a WrappedFloat from this WrappedFloat given they have the same lower and upper bounds.
| [in] | other | The WrappedFloat to be subtracted from this WrappedFloat. |
An assertion error if the two WrappedFloats have different lower and upper bounds.
| void tap::algorithms::WrappedFloat::operator-= | ( | float | other | ) |
Subtracts a WrappedFloat from this WrappedFloat given they have the same lower and upper bounds.
| [in] | other | The WrappedFloat to be subtracted from this WrappedFloat. |
An assertion error if the two WrappedFloats have different lower and upper bounds.
| bool tap::algorithms::WrappedFloat::operator== | ( | const WrappedFloat & | other | ) | const |
Two WrappedFloats are considered equal if their wrapped values are equal. This does not account for floating point imprecision, so for robust equality checks, minDifference should be used.
| [in] | other | The WrappedFloat to be compared this WrappedFloat. |
An assertion error if the two WrappedFloats have different lower and upper bounds.
|
static |
Calculates how much of the two given wrapped ranges overlap. If mentally visualizing on a circle, this method takes two arbitrary arcs on the perimeter and returns the length of the overlapping portion(s).
| [in] | lowerA | the first range's lower bound |
| [in] | upperA | the first range's upper bound |
| [in] | lowerB | the second range's lower bound |
| [in] | upperB | the second range's upper bound |
An assertion error if the WrappedFloats themselves have different bounds.
|
inline |
Sets the unwrapped value.
|
inline |
Sets the wrapped value.
| void tap::algorithms::WrappedFloat::shiftBounds | ( | float | shiftMagnitude | ) |
Shifts both bounds by the specified amount.
| [in] | shiftMagnitude | the amount to add to each bound. |
| bool tap::algorithms::WrappedFloat::withinRange | ( | const WrappedFloat & | lowerBound, |
| const WrappedFloat & | upperBound | ||
| ) | const |
Checks whether this is within the wrapped range defined from lowerBound to upperBound. For example given a value wrapped from 0 to 10, with the following conditions:
| [in] | lowerBound | |
| [in] | upperBound |
this is within the specified range An assertion error if the WrappedFloats themselves have different bounds.
|
inline |
|
staticconstexpr |
Maximum value between floats representing bounds at which they're considered to be "equal" for assertions.