DUNE: Uniform Navigational Environment  2017.01.0
DUNE::Math Namespace Reference

Detailed Description

Math routines and classes.

Namespaces

 Random
 

Classes

class  Angles
 
class  Derivative
 
struct  LinIntParam
 
struct  LineSegParam
 
class  Matrix
 
class  MovingAverage
 
class  MultiMovingAverage
 
struct  FuncWrapper
 
class  Optimization
 
class  tvector
 
class  QPSolver
 

Functions

uint32_t computeNextPowerOfTwo (uint32_t val)
 
template<typename Type >
Type average (Type *a, uint32_t size)
 
template<typename Type >
Type norm (const Type &a, const Type &b)
 
template<typename Type >
void insertionSort (Type *a, uint16_t size)
 
template<typename Type >
Type medianOrdered (Type *a, uint16_t size)
 
template<typename Type >
Type median (Type *a, uint16_t size)
 
template<typename Type >
Type linearInterpolation (const LinIntParam< Type > &p)
 
template<typename Type >
Type piecewiseLI (const std::vector< Type > &x_vec, const std::vector< Type > &t_vec, Type t)
 
template<typename Type >
bool lineSegmentIntersect (const LineSegParam< Type > &p, Type *coord_x, Type *coord_y)
 
template<typename Ta , typename Tb , typename Tc >
Ta trimValue (Ta v, Tb min, Tc max)
 
template<typename Ta , typename Tb , typename Tc >
bool trimValueMod (Ta &value, Tb min, Tc max)
 
char getSignalChar (fp64_t v)
 
int getSignal (float v)
 
double round (double value)
 
long int roundToInteger (double value)
 
uint8_t fromBCD (uint8_t value)
 
uint8_t toBCD (uint8_t value)
 
template<typename T >
gcd (T a, T b)
 
template<typename T >
bool isNaN (const T &var)
 
Matrix operator+ (const Matrix &m1, const Matrix &m2)
 
Matrix operator- (const Matrix &m1, const Matrix &m2)
 
Matrix operator* (const Matrix &m1, const Matrix &m2)
 
Matrix operator& (const Matrix &m1, const Matrix &m2)
 
Matrix operator/ (const Matrix &a, const Matrix &b)
 
Matrix operator* (double x, const Matrix &a)
 
Matrix operator* (const Matrix &a, double x)
 
Matrix operator/ (const Matrix &a, double x)
 
std::ostream & operator<< (std::ostream &os, const Matrix &a)
 
std::istream & operator>> (std::istream &is, Matrix &a)
 
Matrix transpose (const Matrix &a)
 
Matrix inverse_pp (const Matrix &a)
 
Matrix inverse_pp (const Matrix &a, const Matrix &b)
 
Matrix inverse (const Matrix &a)
 
Matrix inverse (const Matrix &a, const Matrix &b)
 
Matrix skew (double data[3])
 
Matrix skew (const Matrix &a)
 
Matrix inverse_lup (const Matrix &a)
 
Matrix abs (const Matrix &a)
 
double max (const Matrix &a)
 
double min (const Matrix &a)
 
double sum (const Matrix &a)
 
double squaresum (const Matrix &a)
 

Variables

class DUNE_DLL_SYM Angles
 
class DUNE_DLL_SYM Matrix
 
class DUNE_DLL_SYM Optimization
 
class DUNE_DLL_SYM QPSolver
 

Function Documentation

Matrix DUNE::Math::abs ( const Matrix &  a)
Parameters
[in]amatrix
Returns
matrix with absolute values

References DUNE::Math::Matrix::isEmpty().

Referenced by Sensors::Imagenex881A::Task::setAbsorption().

template<typename Type >
Type DUNE::Math::average ( Type *  a,
uint32_t  size 
)

Computes the average value of a fixed size array.

Parameters
aarray with values.
sizesize of the array.
Returns
average value of the array.
uint32_t DUNE::Math::computeNextPowerOfTwo ( uint32_t  val)
inline

Compute the next power of two of a value.

Parameters
valvalue.
Returns
next power of two.

Referenced by DUNE::Math::Matrix::expmts(), DUNE::Utils::ByteBuffer::grow(), and DUNE::Utils::RawFifo::RawFifo().

uint8_t DUNE::Math::fromBCD ( uint8_t  value)
inline

Convert a number in Binary Coded Decimal (BCD) format to decimal.

Parameters
valueBCD encoded value.
Returns
decimal representation of value.
template<typename T >
T DUNE::Math::gcd ( a,
b 
)
int DUNE::Math::getSignal ( float  v)
inline

Computes the signal of a number.

Parameters
vnumber.
Returns
1 or -1. If the number is 0.0 1 is returned.
char DUNE::Math::getSignalChar ( fp64_t  v)
inline

Computes the character representing the signal of a number.

Parameters
vnumber.
Returns
ASCII character representing the number signal. Space ' ' is returned in the case of the number beeing 0.0.
template<typename Type >
void DUNE::Math::insertionSort ( Type *  a,
uint16_t  size 
)

Insertion Sort algorithm.

insertionSort algorithm implementation for zero based vectors better for lists with 8 to 20 elements This method sorts a vector in the ascending order using insertion sort algorithm

Referenced by median().

Matrix DUNE::Math::inverse ( const Matrix &  a)

The inverse is calculated using Gauss elimination with total pivoting.

If Matrix 'a' is singular (with current precision) a zero Matrix with the same dimension of 'a' is returned and the variable 'dMatrix::inversionerror' is set to 1. Otherwise it is set to 0.

Parameters
[in]amatrix to be inverted.
Returns
inverted matrix

References DUNE::Math::Matrix::isEmpty(), and DUNE::Math::Matrix::upper_triangular_tp().

Referenced by Control::AUV::Attitude::Task::onEstimatedState(), and DUNE::Control::AUVModel::stepInv().

Matrix DUNE::Math::inverse ( const Matrix &  a,
const Matrix &  b 
)

The system is solved using Gauss elimination with total pivoting.

If Matrix 'a' is singular (with current precision) a zero Matrix with the same dimension of 'b' is returned and the variable 'dMatrix::inversionerror' is set to 1. Otherwise it is set to 0.

Parameters
[in]amatrix
[in]bmatrix
Returns
resultant matrix

References DUNE::Math::Matrix::isEmpty(), and DUNE::Math::Matrix::upper_triangular_tp().

Matrix DUNE::Math::inverse_lup ( const Matrix &  a)
Parameters
[in]areference to matrix to be inverted
Returns
inverted matrix

References DUNE::Math::Matrix::isEmpty(), and DUNE::Math::Matrix::lup().

Matrix DUNE::Math::inverse_pp ( const Matrix &  a)

The inverse is calculated using Gauss elimination with partial pivoting.

If Matrix is singular (with current precision) a zero Matrix with the same dimension is returned and the variable. 'dMatrix::inversionerror' is set to 1. Otherwise is is set to 0.

Parameters
[in]areference to matrix to be inverted
Returns
inverted matrix

References DUNE::Math::Matrix::isEmpty(), and DUNE::Math::Matrix::upper_triangular_pp().

Matrix DUNE::Math::inverse_pp ( const Matrix &  a,
const Matrix &  b 
)

The system is solved using Gauss elimination with partial pivoting.

If Matrix 'a' is singular (with current precision) a zero Matrix with the same dimension of 'b' is returned and the variable. 'dMatrix::inversionerror' is set to 1. Otherwise it is set to 0.

Parameters
[in]amatrix
[in]bmatrix
Returns
resultant matrix

References DUNE::Math::Matrix::isEmpty(), and DUNE::Math::Matrix::upper_triangular_pp().

template<typename T >
bool DUNE::Math::isNaN ( const T &  var)

Test if a floating point variable holds a value that is not a number.

Returns
true if variable is not a number, false otherwise.

Referenced by DUNE::Simulation::UAVSimulation::commandAirspeed(), DUNE::Simulation::UAVSimulation::commandAlt(), DUNE::Simulation::UAVSimulation::commandBank(), DUNE::Simulation::UAVSimulation::commandFPA(), and DUNE::Simulation::UAVSimulation::commandPitch().

template<typename Type >
Type DUNE::Math::median ( Type *  a,
uint16_t  size 
)

Computes the median value of a fixed size UNORDERED array.

Parameters
aarray with values.
sizesize of the array.
Returns
median value of the array.

References insertionSort(), and medianOrdered().

Referenced by Sensors::Imagenex852::Task::filterRange(), and DUNE::Math::Matrix::median().

template<typename Type >
Type DUNE::Math::medianOrdered ( Type *  a,
uint16_t  size 
)

Computes the median value of a fixed size ORDERED array.

Parameters
aarray with values.
sizesize of the array.
Returns
median value of the array.

References round().

Referenced by median().

template<typename Type >
Type DUNE::Math::norm ( const Type &  a,
const Type &  b 
)

Computes the norm between two points.

Parameters
afirst point.
bsecond point.
Returns
norm between two points.

Referenced by DUNE::Navigation::BasicNavigation::consume(), DUNE::Control::PathController::getEta(), Simulators::USBL::Task::getSensorData(), DUNE::Math::Matrix::toEulerAngles(), and DUNE::Maneuvers::StationKeep::updatePathControl().

Matrix DUNE::Math::operator& ( const Matrix &  m1,
const Matrix &  m2 
)
Parameters
[in]m1matrix to be multiplied (element-element).
[in]m2matrix to be multiplied (element-element).
Returns
resultant matrix.

References DUNE::Math::Matrix::isEmpty(), and DUNE::Math::Matrix::size().

Matrix DUNE::Math::operator* ( const Matrix &  m1,
const Matrix &  m2 
)

Note on optimization by Eduardo Marques - Sep 8 2010

Applied loop interchange to achieve memory stride 1 (better data locality) in iterations of the innermost loop, This makes for better cache behavior (i.e. less cache misses), particularly as matrix dimensions increase. For those interested, see papers or books by M J Wolfe.

Parameters
[in]m1matrix to be summed.
[in]m2matrix to be summed.
Returns
resultant matrix.

References DUNE::Math::Matrix::isEmpty().

Matrix DUNE::Math::operator* ( double  x,
const Matrix &  a 
)
Parameters
[in]xreal number.
[in]amatrix to be multiplied.
Returns
resultant matrix.
Matrix DUNE::Math::operator* ( const Matrix &  a,
double  x 
)
Parameters
[in]amatrix to be multiplied.
[in]xreal number.
Returns
resultant matrix.
Matrix DUNE::Math::operator+ ( const Matrix &  m1,
const Matrix &  m2 
)
Parameters
[in]m1matrix to be summed.
[in]m2matrix to be summed.
Returns
resultant matrix.

References DUNE::Math::Matrix::isEmpty(), and DUNE::Math::Matrix::size().

Matrix DUNE::Math::operator- ( const Matrix &  m1,
const Matrix &  m2 
)
Parameters
[in]m1matrix to be subtracted.
[in]m2matrix to subtract.
Returns
resultant matrix.

References DUNE::Math::Matrix::isEmpty(), and DUNE::Math::Matrix::size().

Matrix DUNE::Math::operator/ ( const Matrix &  a,
const Matrix &  b 
)
Parameters
[in]amatrix for element-element quocient.
[in]bmatrix for element-element quocient.
Returns
resultant matrix.

References DUNE::Math::Matrix::isEmpty(), and DUNE::Math::Matrix::size().

Matrix DUNE::Math::operator/ ( const Matrix &  a,
double  x 
)
Parameters
[in]amatrix to be divided.
[in]xreal number.
Returns
resultant matrix.
std::ostream& DUNE::Math::operator<< ( std::ostream &  os,
const Matrix &  a 
)

Each row of the Matrix is put on a different line.

Parameters
[in]osoutput stream.
[in]amatrix to be outputted.
std::istream& DUNE::Math::operator>> ( std::istream &  is,
Matrix &  a 
)

The Matrix is filled row by row.

Parameters
[in]isinput stream.
[in]amatrix to be filled.
Returns
resultant matrix.

References DUNE::Math::Matrix::Matrix(), and DUNE::Math::Matrix::vertCat().

template<typename Type >
Type DUNE::Math::piecewiseLI ( const std::vector< Type > &  x_vec,
const std::vector< Type > &  t_vec,
Type  t 
)

Interpolates a point for a piecewise linear function If outside of the function's domain, returns the interpolation using closest points.

Parameters
x_vecpiecewise linear function value for the values of t_vec
t_vecread line above. ASSUMED TO BE IN ASCENDING ORDER!
tvalue for which the function is to be interpolated
Returns
resuling value of the interpolation

References linearInterpolation().

Referenced by DUNE::Power::Model::computeMotionEnergy().

long int DUNE::Math::roundToInteger ( double  value)
inline

References round().

Matrix DUNE::Math::skew ( double  data[3])
Parameters
[in]dataarray with 3 elements
Returns
skewed matrix
Matrix DUNE::Math::skew ( const Matrix &  a)
Parameters
[in]arow or column vector with 3 elements
Returns
skewed matrix

References DUNE::Math::Matrix::isEmpty(), and DUNE::Math::Matrix::skew.

double DUNE::Math::squaresum ( const Matrix &  a)
Parameters
[in]amatrix
Returns
squared sum of the elements of matrix

References DUNE::Math::Matrix::isEmpty(), and DUNE::Math::Matrix::size().

uint8_t DUNE::Math::toBCD ( uint8_t  value)
inline

Convert a number in decimal format to Binary Coded Decimal (BCD) format.

Parameters
valuedecimal value.
Returns
BCD encoded value.
template<typename Ta , typename Tb , typename Tc >
Ta DUNE::Math::trimValue ( Ta  v,
Tb  min,
Tc  max 
)
inline

References max(), and min().

Referenced by Control::ROV::RemoteOperation::Task::actuateThruster(), Control::AUV::Allocator::Task::allocate(), Control::AUV::Allocator::Task::brake(), DUNE::Plans::Progress::compute(), DUNE::Control::PathController::consume(), Simulators::IMU::Task::consume(), Simulators::Servos::Task::consume(), Control::Path::Height::Task::consume(), Simulators::Docking::Task::consume(), Maneuver::VehicleFormation::Coordinator::Task::consume(), Maneuver::VehicleFormation::FormCollAvoid::Task::consume(), Control::AUV::Speed::Task::dispatchThrust(), Control::ASV::HeadingAndSpeed::Task::dispatchThrust(), Maneuver::VehicleFormation::FormCollAvoid::Task::formationControl(), Control::ROV::RemoteOperation::Task::forwardControl(), Control::UAV::Ardupilot::Task::map2PWM(), Control::AUV::LMI::Task::onEstimatedState(), Control::AUV::Attitude::Task::onEstimatedState(), Maneuver::VehicleFormation::SMC::Task::onPathCompletion(), Maneuver::VehicleFormation::SMC::Task::onUpdate(), Actuators::FLIRPTU::Task::rad2pos(), Actuators::Broom::Task::sanitizeRef(), Maneuver::VehicleFormation::Coordinator::Task::setLeaderState(), Maneuver::VehicleFormation::FormCollAvoid::Task::setLeaderState(), Actuators::Broom::Task::setRefCurrent(), Actuators::Broom::Task::setRefDcycle(), Sensors::Imagenex837B::Frame837::setRepRate(), DUNE::Control::DiscretePID::step(), Control::UAV::LOS::Task::step(), Maneuver::FollowTrajectory::Task::step(), Control::Path::LOSnSMC::Task::step(), Control::ROV::HorizontalPlane::Task::tal(), Actuators::FLIRPTU::Task::task(), Navigation::AUV::Navigation::Task::task(), DUNE::Monitors::ServoPositionMonitor< T >::updateAndTest(), and Simulators::Environment::Task::updateForwardDistance().

template<typename Ta , typename Tb , typename Tc >
bool DUNE::Math::trimValueMod ( Ta &  value,
Tb  min,
Tc  max 
)
inline

Variable Documentation

class DUNE_DLL_SYM DUNE::Math::Angles
class DUNE_DLL_SYM DUNE::Math::Optimization
class DUNE_DLL_SYM DUNE::Math::QPSolver