Hummingbird Flight Software
Flight software for the Hummingbird FCU quadcopter flight controller. Designed to run on the Teensy 4.1. Developed with VSCode+PlatformIO.
Functions
math_functs.cpp File Reference
#include <Arduino.h>
#include "maths/math_functs.h"

Functions

float InvSqrtf (float num)
 Extra math functions such as fast square root, 'safe' trig. More...
 
template<typename T >
RangeConstrain (const T val, const T lower, const T upper)
 Templates to constrain a value to a certain range. More...
 
template int RangeConstrain< int > (int val, int lower, int upper)
 
template uint16_t RangeConstrain< uint16_t > (uint16_t val, uint16_t lower, uint16_t upper)
 
template float RangeConstrain< float > (const float val, const float lower, const float upper)
 
template<typename T >
float sqrtf_safe (const T val)
 Compute safe square root of a value. More...
 
template float sqrtf_safe< int > (const int val)
 
template float sqrtf_safe< uint16_t > (const uint16_t val)
 
template float sqrtf_safe< float > (const float val)
 
template<typename T >
float asinf_safe (const T val)
 Take the arcsine of a number with safety checks. More...
 
template float asinf_safe< int > (const int val)
 
template float asinf_safe< uint16_t > (const uint16_t val)
 
template float asinf_safe< float > (const float val)
 

Function Documentation

◆ asinf_safe()

template<typename T >
float asinf_safe ( const T  val)

Take the arcsine of a number with safety checks.

Return float

Parameters
valValue to take the arcsine of
Returns
(float) Computed arcsine.

◆ asinf_safe< float >()

template float asinf_safe< float > ( const float  val)

◆ asinf_safe< int >()

template float asinf_safe< int > ( const int  val)

◆ asinf_safe< uint16_t >()

template float asinf_safe< uint16_t > ( const uint16_t  val)

◆ InvSqrtf()

float InvSqrtf ( float  num)

Extra math functions such as fast square root, 'safe' trig.

functions, etc. norm = a * InvSqrtf(a); Fast inverse square root algorithm. Use when normalizing vectors! See: https://en.wikipedia.org/wiki/Fast_inverse_square_root

Parameters
numNumber to square-root.
Returns
Inverse of square root.

◆ RangeConstrain()

template<typename T >
T RangeConstrain ( const T  val,
const T  lower,
const T  upper 
)

Templates to constrain a value to a certain range.

Works for floats, uint16, etc. If value is out of specified bounds, constrain it to be within the bounds.

Parameters
valInput value to constrain
lowerLower bound
upperUpper bound

◆ RangeConstrain< float >()

template float RangeConstrain< float > ( const float  val,
const float  lower,
const float  upper 
)

◆ RangeConstrain< int >()

template int RangeConstrain< int > ( int  val,
int  lower,
int  upper 
)

◆ RangeConstrain< uint16_t >()

template uint16_t RangeConstrain< uint16_t > ( uint16_t  val,
uint16_t  lower,
uint16_t  upper 
)

◆ sqrtf_safe()

template<typename T >
float sqrtf_safe ( const T  val)

Compute safe square root of a value.

Checks for NaN's

Parameters
valValue to take square root of.
Returns
Square root of result.

◆ sqrtf_safe< float >()

template float sqrtf_safe< float > ( const float  val)

◆ sqrtf_safe< int >()

template float sqrtf_safe< int > ( const int  val)

◆ sqrtf_safe< uint16_t >()

template float sqrtf_safe< uint16_t > ( const uint16_t  val)