Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
tap::algorithms::WrappedFloat Class Reference

#include <wrapped_float.hpp>

Inheritance diagram for tap::algorithms::WrappedFloat:

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
 

Detailed Description

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:

  • 10 + 1 == 1
  • 0 - 1 == 9
  • 0 == 10

Constructor & Destructor Documentation

◆ WrappedFloat()

tap::algorithms::WrappedFloat::WrappedFloat ( float  value,
float  lowerBound,
float  upperBound 
)
Parameters
[in]valuevalue to initialize with (doesn't have to be wrapped)
[in]lowerBoundlower wrapping bound, must be less than upperBound
[in]upperBoundupper wrapping bound, must be higher than lowerBound

Member Function Documentation

◆ getLowerBound()

float tap::algorithms::WrappedFloat::getLowerBound ( ) const
inline

Returns the value's lower bound.

◆ getNormalized()

WrappedFloat tap::algorithms::WrappedFloat::getNormalized ( ) const
inline

◆ getRevolutions()

int tap::algorithms::WrappedFloat::getRevolutions ( ) const
inline

◆ getUnwrappedValue()

float tap::algorithms::WrappedFloat::getUnwrappedValue ( ) const
inline

Returns the unwrapped value.

◆ getUpperBound()

float tap::algorithms::WrappedFloat::getUpperBound ( ) const
inline

Returns the value's upper bound.

◆ getWrappedValue()

float tap::algorithms::WrappedFloat::getWrappedValue ( ) const
inline

Returns the wrapped value.

◆ limitValue() [1/2]

float tap::algorithms::WrappedFloat::limitValue ( const WrappedFloat valueToLimit,
const float  min,
const float  max,
int *  status 
)
static

Runs the limitValue function from above, wrapping the min and max passed in to the same bounds as those of valueToLimit's.

See also
limitValue.
Parameters
[in]valueToLimitthe WrappedFloat whose value it is to limit
[in]minthe WrappedFloat with the same bounds as valueToLimit that valueToLimit will be limited below.
[in]maxthe WrappedFloat with the same bounds as valueToLimit that valueToLimit will be limited above.
[out]statusthe status result (what operation the limitValue function performed). The status codes are described below:
  • 0: No limiting performed
  • 1: Limited to min value
  • 2: Limited to max value
Returns
the limited value.
Exceptions

An assertion error if the WrappedFloats have different lower and upper bounds.

◆ limitValue() [2/2]

float tap::algorithms::WrappedFloat::limitValue ( const WrappedFloat valueToLimit,
const WrappedFloat min,
const WrappedFloat max,
int *  status 
)
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:

  • valueToLimit: 5, min: 1, max: 4, returns 4.
  • valueToLimit: 9, min: 1, max: 3, returns 1 (since valueToLimit is closest to 1).
  • valueToLimit: 9, min: 2, max: 1, returns 9 (since the range between min and max starts at 2, goes up to 9, then wraps around to 1).
Parameters
[in]valueToLimitthe WrappedFloat whose value it is to limit
[in]minthe WrappedFloat with the same bounds as valueToLimit that valueToLimit will be limited below.
[in]maxthe WrappedFloat with the same bounds as valueToLimit that valueToLimit will be limited above.
[out]statusthe status result (what operation the limitValue function performed). The status codes are described below:
  • 0: No limiting performed
  • 1: Limited to min value
  • 2: Limited to max value
Returns
the limited value.
Exceptions

An assertion error if the WrappedFloats have different lower and upper bounds.

◆ minDifference() [1/2]

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.

Parameters
[in]unwrappedValueThe float to compute the minDifference with. It's wrapped before computing
Returns
: A float with the signed minimum distance.
Exceptions

An assertion error if the two WrappedFloats have different lower and upper bounds.

◆ minDifference() [2/2]

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.

Parameters
[in]otherThe WrappedFloat to compute the minDifference with.
Returns
: A float with the signed minimum distance.
Exceptions

An assertion error if the two WrappedFloats have different lower and upper bounds.

◆ minInterpolate()

WrappedFloat tap::algorithms::WrappedFloat::minInterpolate ( const WrappedFloat other,
float  alpha 
) const

Interpolates along the smallest difference with another WrappedFloat.

Parameters
[in]otherThe WrappedFloat to interpolate between.
[in]alphaA float between 0-1 (0 returns this WrappedFloat's value, 1 returns the other's)
Exceptions

An assertion error if the two WrappedFloats have different lower and upper bounds.

◆ operator+() [1/2]

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.

Parameters
[in]otherThe WrappedFloat to be added with this WrappedFloat.
Returns
: A new WrappedFloat with the additive value of other and this.
Exceptions

An assertion error if the two WrappedFloats have different lower and upper bounds.

◆ operator+() [2/2]

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.

Parameters
[in]otherThe WrappedFloat to be added with this WrappedFloat.
Returns
: A new WrappedFloat with the additive value of other and this.
Exceptions

An assertion error if the two WrappedFloats have different lower and upper bounds.

◆ operator+=() [1/2]

void tap::algorithms::WrappedFloat::operator+= ( const WrappedFloat other)

Adds a WrappedFloat to this WrappedFloat given they have the same lower and upper bounds.

Parameters
[in]otherThe WrappedFloat to be added to this WrappedFloat.
Exceptions

An assertion error if the two WrappedFloats have different lower and upper bounds.

◆ operator+=() [2/2]

void tap::algorithms::WrappedFloat::operator+= ( float  other)

Adds a WrappedFloat to this WrappedFloat given they have the same lower and upper bounds.

Parameters
[in]otherThe WrappedFloat to be added to this WrappedFloat.
Exceptions

An assertion error if the two WrappedFloats have different lower and upper bounds.

◆ operator-() [1/2]

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.

Parameters
[in]otherThe WrappedFloat to be subtracted from this WrappedFloat.
Returns
: A new WrappedFloat with the subtractive value of other from this.
Exceptions

An assertion error if the two WrappedFloats have different lower and upper bounds.

◆ operator-() [2/2]

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.

Parameters
[in]otherThe WrappedFloat to be subtracted from this WrappedFloat.
Returns
: A new WrappedFloat with the subtractive value of other from this.
Exceptions

An assertion error if the two WrappedFloats have different lower and upper bounds.

◆ operator-=() [1/2]

void tap::algorithms::WrappedFloat::operator-= ( const WrappedFloat other)

Subtracts a WrappedFloat from this WrappedFloat given they have the same lower and upper bounds.

Parameters
[in]otherThe WrappedFloat to be subtracted from this WrappedFloat.
Exceptions

An assertion error if the two WrappedFloats have different lower and upper bounds.

◆ operator-=() [2/2]

void tap::algorithms::WrappedFloat::operator-= ( float  other)

Subtracts a WrappedFloat from this WrappedFloat given they have the same lower and upper bounds.

Parameters
[in]otherThe WrappedFloat to be subtracted from this WrappedFloat.
Exceptions

An assertion error if the two WrappedFloats have different lower and upper bounds.

◆ operator==()

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.

Parameters
[in]otherThe WrappedFloat to be compared this WrappedFloat.
Exceptions

An assertion error if the two WrappedFloats have different lower and upper bounds.

◆ rangeOverlap()

float tap::algorithms::WrappedFloat::rangeOverlap ( const WrappedFloat lowerA,
const WrappedFloat upperA,
const WrappedFloat lowerB,
const WrappedFloat upperB 
)
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).

Parameters
[in]lowerAthe first range's lower bound
[in]upperAthe first range's upper bound
[in]lowerBthe second range's lower bound
[in]upperBthe second range's upper bound
Returns
the total length of the overlapping region(s) as a float
Exceptions

An assertion error if the WrappedFloats themselves have different bounds.

◆ setUnwrappedValue()

void tap::algorithms::WrappedFloat::setUnwrappedValue ( float  newUnwrappedValue)
inline

Sets the unwrapped value.

◆ setWrappedValue()

void tap::algorithms::WrappedFloat::setWrappedValue ( float  newWrappedValue)
inline

Sets the wrapped value.

◆ shiftBounds()

void tap::algorithms::WrappedFloat::shiftBounds ( float  shiftMagnitude)

Shifts both bounds by the specified amount.

Parameters
[in]shiftMagnitudethe amount to add to each bound.

◆ withinRange()

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:

  • this: 9, min: 3, max: 7, returns false.
  • this: 5, min: 3, max: 7, returns true.
  • this: 9, min: 7, max: 3, returns true.
  • this: 5, min: 7, max: 3, returns false.
Parameters
[in]lowerBound
[in]upperBound
Returns
whether this is within the specified range
Exceptions

An assertion error if the WrappedFloats themselves have different bounds.

◆ withSameBounds()

WrappedFloat tap::algorithms::WrappedFloat::withSameBounds ( const float  value) const
inline

Member Data Documentation

◆ EPSILON

constexpr float tap::algorithms::WrappedFloat::EPSILON = 1E-8
staticconstexpr

Maximum value between floats representing bounds at which they're considered to be "equal" for assertions.


The documentation for this class was generated from the following files: