Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
numops Namespace Reference

Namespace containing functions related to operations on numbers and other datatypes. More...

Classes

struct  CoordinatePoint
 This struct represents a point in a 3D coordinate system. More...
 

Functions

template<typename T >
constexpr T Clamp (T tValue, T tMin, T tMax)
 Clamps a given value from going above or below a given threshold.
 
template<typename T >
bool Bounded (T tValue, T tMin, T tMax, const bool bInclusive=true)
 Checks if a given value is between the given maximum and minimum ranges.
 
template<typename T >
constexpr T MapRange (const T tValue, const T tOldMinimum, const T tOldMaximum, const T tNewMinimum, const T tNewMaximum)
 Maps a value to a new range given the old range.
 
template<typename T >
constexpr T InputAngleModulus (T tValue, T tMinValue, T tMaxValue)
 Calculates the modulus of an input angle.
 
template<typename T >
constexpr T AngularDifference (T tFirstValue, T tSecondValue)
 Calculates the distance in degrees between two angles. This function accounts for wrap around so that the most acute or smallest radial distance between the two points is returned. The distance is positive if going from the first angle to the second angle results in clockwise motion.
 
template<typename T >
constexpr void CoordinateFrameRotate3D (std::vector< CoordinatePoint< T > > &vPointCloud, const double dXRotationDegrees, const double dYRotationDegrees, const double dZRotationDegrees)
 This method will rotate a list of 3D coordinate points a variable amount of degrees around the X, Y, and Z axis in a standard coordinate plane. Any amount of points can be given and any angle of rotation can be given for each individual X, Y, and Z axis as long as the points all share the same coordinate system.
 

Detailed Description

Namespace containing functions related to operations on numbers and other datatypes.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-07-06

Function Documentation

◆ Clamp()

template<typename T >
constexpr T numops::Clamp ( tValue,
tMin,
tMax 
)
inlineconstexpr

Clamps a given value from going above or below a given threshold.

Template Parameters
T- Template argument for given value type.
Parameters
tValue- The value to clamp.
tMin- Minimum value quantity.
tMax- Maximum value quantity.
Returns
constexpr T - The clamped value.
Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu), ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-06-20
83 {
84 return std::max(std::min(tMax, tValue), tMin);
85 }
Here is the caller graph for this function:

◆ Bounded()

template<typename T >
bool numops::Bounded ( tValue,
tMin,
tMax,
const bool  bInclusive = true 
)
inline

Checks if a given value is between the given maximum and minimum ranges.

Template Parameters
T- Template argument for given value type.
Parameters
tValue- The value to check.
tMin- The minimum bound for the value to be valid.
tMax- The maximum bound for the value to be valid.
Returns
true - The value is within the bounds.
false - The value is not within the bounds.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-10-16
102 {
103 // Check if value is inclusive or not.
104 if (bInclusive)
105 {
106 // Return true if the given value is valid.
107 return (tValue >= tMin) && (tValue <= tMax);
108 }
109 else
110 {
111 // Return true if the given value is valid.
112 return (tValue > tMin) && (tValue < tMax);
113 }
114 }
Here is the caller graph for this function:

◆ MapRange()

template<typename T >
constexpr T numops::MapRange ( const T  tValue,
const T  tOldMinimum,
const T  tOldMaximum,
const T  tNewMinimum,
const T  tNewMaximum 
)
inlineconstexpr

Maps a value to a new range given the old range.

Template Parameters
T- Template value specifying the type of the number to map to new range.
Parameters
tValue- The value to remap.
tOldMinimum- The current range's minimum value.
tOldMaximum- The current range's maximum value.
tNewMinimum- The new range's minimum value.
tNewMaximum- The new range's maximum value.
Returns
constexpr T - The resultant templated type mapped to the new range.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-09-22
132 {
133 // Check if the ranges are valid.
134 if (tOldMinimum == tOldMaximum || tNewMinimum == tNewMaximum)
135 {
136 // Submit logger message.
137 std::cerr << "MAPRANGE: The old/new range is not valid." << std::endl;
138
139 // Return old, given value.
140 return tValue;
141 }
142
143 // Perform the mapping using linear interpolation.
144 T tOldValueRange = tOldMaximum - tOldMinimum;
145 T tNewValueRange = tNewMaximum - tNewMinimum;
146 T tScaledValue = (tValue - tOldMinimum) / tOldValueRange;
147
148 // Return new mapped value.
149 return tNewMinimum + tScaledValue * tNewValueRange;
150 }
Here is the caller graph for this function:

◆ InputAngleModulus()

template<typename T >
constexpr T numops::InputAngleModulus ( tValue,
tMinValue,
tMaxValue 
)
inlineconstexpr

Calculates the modulus of an input angle.

Template Parameters
T- Template value specifying the type of the number to find modulus of.
Parameters
tValue- Input value to wrap.
tMinValue- The minimum value expected from the input. INCLUSIVE
tMaxValue- The maximum value expected from the input. NOT INCLUSIVE
Returns
constexpr T - The wrapped value.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-10-19
166 {
167 // Determine the correct modulus number.
168 T tModulus = tMaxValue - tMinValue;
169
170 // Wrap input if it's above the maximum input.
171 int nNumMax = (tValue - tMinValue) / tModulus;
172 tValue -= nNumMax * tModulus;
173 // Wrap input if it's below the minimum input.
174 int nNumMin = (tValue - tMaxValue) / tModulus;
175 tValue -= nNumMin * tModulus;
176
177 // Check if the final value is the max value, set to min.
178 if (tValue == tMaxValue)
179 {
180 tValue = tMinValue;
181 }
182
183 // Return wrapped number.
184 return tValue;
185 }
Here is the caller graph for this function:

◆ AngularDifference()

template<typename T >
constexpr T numops::AngularDifference ( tFirstValue,
tSecondValue 
)
inlineconstexpr

Calculates the distance in degrees between two angles. This function accounts for wrap around so that the most acute or smallest radial distance between the two points is returned. The distance is positive if going from the first angle to the second angle results in clockwise motion.

Template Parameters
T- Template value specifying the type of the number to find difference of.
Parameters
tFirstValue- The first value.
tSecondValue- The second value. This will be subtracted from the first value.
Returns
constexpr T - The smallest angular distance.
Note
This function expects the two values to be between 0-360.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2024-04-03
205 {
206 // Check input.
207 if (!Bounded<T>(tFirstValue, 0, 360) && !Bounded<T>(tSecondValue, 0, 360))
208 {
209 // Submit logger message.
210 std::cerr << "ANGULARDIFFERENCE: An input value is not valid must be between 0-360. The result difference will not be accurate!" << std::endl;
211 }
212
213 // Find absolute difference between the two values.
214 T tDifference = std::abs(tFirstValue - tSecondValue);
215 // If greater than 180 degrees, subtract 360/
216 if (tDifference > 180)
217 {
218 // Wrap value.
219 tDifference -= 360;
220
221 // Check if first values is bigger than second value. If it is, flip sign so that clockwise is positive.
222 if (tFirstValue > tSecondValue)
223 {
224 tDifference *= -1;
225 }
226 }
227
228 // Return value.
229 return tDifference;
230 }
Here is the caller graph for this function:

◆ CoordinateFrameRotate3D()

template<typename T >
constexpr void numops::CoordinateFrameRotate3D ( std::vector< CoordinatePoint< T > > &  vPointCloud,
const double  dXRotationDegrees,
const double  dYRotationDegrees,
const double  dZRotationDegrees 
)
inlineconstexpr

This method will rotate a list of 3D coordinate points a variable amount of degrees around the X, Y, and Z axis in a standard coordinate plane. Any amount of points can be given and any angle of rotation can be given for each individual X, Y, and Z axis as long as the points all share the same coordinate system.

The math for this is based off of these website links for a general 3D cartesian coordinate rotation.

Each X, Y, and Z component of a point are affected by the new rotation around the X, Y, and Z axis in that order. (Note that any other order of rotations can result in different resultant point locations, so keep that in mind when setting parameters.) Because each cartesian component is affected by each axis' rotation, we can represent the rotation of the point in terms of the following three matrices:

            [1      0           0     ]
Rx(theta) = [0  cos(theta) -sin(theta)]
            [0  sin(theta)  cos(theta)]

            [cos(theta) 0   sin(theta)]
Ry(theta) = [0          1       0     ]
            [-sin(theta) 0  cos(theta)]

            [cos(theta) -sin(theta)  0]
Rz(theta) = [sin(theta)  cos(theta)  0]
            [0             0         1]

Finally multiply each point by the determinate of each of these matrices multiplied together to get the new point after being rotated around each axis.

[X] [X] [Y] = A * [Y] [Z`] [Z]

(Where A is Rz(theta) * Ry(theta) * Rx(theta); X, Y, Z are the original points; X, Y, Z` are the new points.)

So for example, rotating point [1, 0, 0] 90 degrees around the Z-axis would result in this point:

| 0 -1 0 | |1| |0| | 1 0 0 | * |0| = |1| | 0 0 1 | |0| |0|

Template Parameters
T- The data type of the values stored in the CoordinatePoint struct.
Parameters
vPointCloud- A reference to a vector of CoordinatePoint<T> structs used to store the X, Y, and Z values of each point. This will contain the rotated modified points after this function completes.
dXRotationDegrees- The degree amount to rotate the points around the x-axis.
dYRotationDegrees- The degree amount to rotate the points around the y-axis.
dZRotationDegrees- The degree amount to rotate the points around the z-axis.
Note
Rotation will happen the the order of X-axis, Y-axis, Z-axis with the positive angle direction being clockwise when looking from the origin and looking down the vector arrow.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2024-04-21
291 {
292 // Convert input degrees to radians.
293 double dXRotationRadians = (dXRotationDegrees * M_PI) / 180.0;
294 double dYRotationRadians = (dYRotationDegrees * M_PI) / 180.0;
295 double dZRotationRadians = (dZRotationDegrees * M_PI) / 180.0;
296
297 // Find the cosine and sine for the X-axis rotation matrix.
298 double dCosA = cos(dXRotationRadians);
299 double dSinA = sin(dXRotationRadians);
300 // Find the cosine and sine for the Y-axis rotation matrix.
301 double dCosB = cos(dYRotationRadians);
302 double dSinB = sin(dYRotationRadians);
303 // Find the cosine and sine for the Z-axis rotation matrix.
304 double dCosC = cos(dZRotationRadians);
305 double dSinC = sin(dZRotationRadians);
306
307 // Calculate the 3D rotation matrix using matrix multiplication with proper Euler angles Z, Y, X. A = (Rz * Ry * Rx).
308 // First row of A matrix.
309 double dAXX = dCosC * dCosB;
310 double dAXY = dCosC * dSinB * dSinA - dSinC * dCosA;
311 double dAXZ = dCosC * dSinB * dCosA + dSinC * dSinA;
312 // Second row of A matrix.
313 double dAYX = dSinC * dCosB;
314 double dAYY = dSinC * dSinB * dSinA + dCosC * dCosA;
315 double dAYZ = dSinC * dSinB * dCosA - dCosC * dSinA;
316 // Third row of A matrix.
317 double dAZX = -dSinB;
318 double dAZY = dCosB * dSinA;
319 double dAZZ = dCosB * dCosA;
320
321 // Loop through each point in the given point cloud.
322 for (CoordinatePoint<T>& stPoint : vPointCloud)
323 {
324 // Rotate the points in X, Y, Z order using the rotation matrix A.
325 T tX = static_cast<T>((dAXX * stPoint.tX) + (dAXY * stPoint.tY) + (dAXZ * stPoint.tZ));
326 T tY = static_cast<T>((dAYX * stPoint.tX) + (dAYY * stPoint.tY) + (dAYZ * stPoint.tZ));
327 T tZ = static_cast<T>((dAZX * stPoint.tX) + (dAZY * stPoint.tY) + (dAZZ * stPoint.tZ));
328 // Update point cloud.
329 stPoint.tX = tX;
330 stPoint.tY = tY;
331 stPoint.tZ = tZ;
332 }
333 }
__device__ __forceinline__ float1 cos(const uchar1 &a)
__device__ __forceinline__ float4 sin(const uchar4 &a)
This struct represents a point in a 3D coordinate system.
Definition NumberOperations.hpp:42
Here is the call graph for this function:
Here is the caller graph for this function: