123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- #pragma once
- #include <cmath>
- #include <limits>
- #include <stdint.h>
- #include <type_traits>
- #include <AP_Common/AP_Common.h>
- #include <AP_Param/AP_Param.h>
- #include "definitions.h"
- #include "crc.h"
- #include "matrix3.h"
- #include "polygon.h"
- #include "quaternion.h"
- #include "rotations.h"
- #include "vector2.h"
- #include "vector3.h"
- #include "spline5.h"
- #include "location.h"
- #include "vector4.h"
- #include "matrix4.h"
- AP_PARAMDEFV(Vector3f, Vector3f, AP_PARAM_VECTOR3F);
- template <typename Arithmetic1, typename Arithmetic2>
- typename std::enable_if<std::is_integral<typename std::common_type<Arithmetic1, Arithmetic2>::type>::value ,bool>::type
- is_equal(const Arithmetic1 v_1, const Arithmetic2 v_2);
- template <typename Arithmetic1, typename Arithmetic2>
- typename std::enable_if<std::is_floating_point<typename std::common_type<Arithmetic1, Arithmetic2>::type>::value, bool>::type
- is_equal(const Arithmetic1 v_1, const Arithmetic2 v_2);
- template <typename T>
- inline bool is_zero(const T fVal1) {
- static_assert(std::is_floating_point<T>::value || std::is_base_of<T,AP_Float>::value,
- "Template parameter not of type float");
- return (fabsf(static_cast<float>(fVal1)) < FLT_EPSILON);
- }
- template <typename T>
- inline bool is_positive(const T fVal1) {
- static_assert(std::is_floating_point<T>::value || std::is_base_of<T,AP_Float>::value,
- "Template parameter not of type float");
- return (static_cast<float>(fVal1) >= FLT_EPSILON);
- }
- template <typename T>
- inline bool is_negative(const T fVal1) {
- static_assert(std::is_floating_point<T>::value || std::is_base_of<T,AP_Float>::value,
- "Template parameter not of type float");
- return (static_cast<float>(fVal1) <= (-1.0 * FLT_EPSILON));
- }
- template <typename T>
- float safe_asin(const T v);
- template <typename T>
- float safe_sqrt(const T v);
- bool inverse3x3(float m[], float invOut[]) WARN_IF_UNUSED;
- bool inverse4x4(float m[],float invOut[]) WARN_IF_UNUSED;
- float *mat_mul(float *A, float *B, uint8_t n);
- bool inverse(float x[], float y[], uint16_t dim) WARN_IF_UNUSED;
- template <typename T>
- float wrap_180(const T angle, float unit_mod = 1);
- template <typename T>
- auto wrap_180_cd(const T angle) -> decltype(wrap_180(angle, 100.f));
- template <typename T>
- float wrap_360(const T angle, float unit_mod = 1);
- template <typename T>
- auto wrap_360_cd(const T angle) -> decltype(wrap_360(angle, 100.f));
- template <typename T>
- float wrap_PI(const T radian);
- template <typename T>
- float wrap_2PI(const T radian);
- template <typename T>
- T constrain_value(const T amt, const T low, const T high);
- inline float constrain_float(const float amt, const float low, const float high)
- {
- return constrain_value(amt, low, high);
- }
- inline int16_t constrain_int16(const int16_t amt, const int16_t low, const int16_t high)
- {
- return constrain_value(amt, low, high);
- }
- inline int32_t constrain_int32(const int32_t amt, const int32_t low, const int32_t high)
- {
- return constrain_value(amt, low, high);
- }
- inline int64_t constrain_int64(const int64_t amt, const int64_t low, const int64_t high)
- {
- return constrain_value(amt, low, high);
- }
- static inline constexpr float radians(float deg)
- {
- return deg * DEG_TO_RAD;
- }
- static inline constexpr float degrees(float rad)
- {
- return rad * RAD_TO_DEG;
- }
- template<typename T>
- float sq(const T val)
- {
- float v = static_cast<float>(val);
- return v*v;
- }
- template<typename T, typename... Params>
- float sq(const T first, const Params... parameters)
- {
- return sq(first) + sq(parameters...);
- }
- template<typename T, typename U, typename... Params>
- float norm(const T first, const U second, const Params... parameters)
- {
- return sqrtf(sq(first, second, parameters...));
- }
- template<typename A, typename B>
- static inline auto MIN(const A &one, const B &two) -> decltype(one < two ? one : two)
- {
- return one < two ? one : two;
- }
- template<typename A, typename B>
- static inline auto MAX(const A &one, const B &two) -> decltype(one > two ? one : two)
- {
- return one > two ? one : two;
- }
- inline uint32_t hz_to_nsec(uint32_t freq)
- {
- return AP_NSEC_PER_SEC / freq;
- }
- inline uint32_t nsec_to_hz(uint32_t nsec)
- {
- return AP_NSEC_PER_SEC / nsec;
- }
- inline uint32_t usec_to_nsec(uint32_t usec)
- {
- return usec * AP_NSEC_PER_USEC;
- }
- inline uint32_t nsec_to_usec(uint32_t nsec)
- {
- return nsec / AP_NSEC_PER_USEC;
- }
- inline uint32_t hz_to_usec(uint32_t freq)
- {
- return AP_USEC_PER_SEC / freq;
- }
- inline uint32_t usec_to_hz(uint32_t usec)
- {
- return AP_USEC_PER_SEC / usec;
- }
- float linear_interpolate(float low_output, float high_output,
- float var_value,
- float var_low, float var_high);
- float expo_curve(float alpha, float input);
- float throttle_curve(float thr_mid, float alpha, float thr_in);
- uint16_t get_random16(void);
- float rand_float(void);
- Vector3f rand_vec3f(void);
- bool is_valid_octal(uint16_t octal) WARN_IF_UNUSED;
- bool rotation_equal(enum Rotation r1, enum Rotation r2) WARN_IF_UNUSED;
- #if CONFIG_HAL_BOARD == HAL_BOARD_SITL
- void fill_nanf(float *f, uint16_t count);
- #endif
|