2016-02-25 13:13:02 -04:00
|
|
|
#pragma once
|
|
|
|
|
2016-03-31 18:43:36 -03:00
|
|
|
#include <cmath>
|
2016-02-25 13:13:02 -04:00
|
|
|
|
2022-02-28 21:19:10 -04:00
|
|
|
#include <AP_HAL/AP_HAL_Boards.h>
|
2016-02-25 13:13:02 -04:00
|
|
|
|
2017-01-31 04:18:20 -04:00
|
|
|
#ifdef M_PI
|
|
|
|
# undef M_PI
|
2016-02-25 13:13:02 -04:00
|
|
|
#endif
|
2023-06-21 19:39:44 -03:00
|
|
|
#define M_PI (3.141592653589793238462643383279502884)
|
2017-01-31 04:18:20 -04:00
|
|
|
|
|
|
|
#ifdef M_PI_2
|
|
|
|
# undef M_PI_2
|
|
|
|
#endif
|
|
|
|
#define M_PI_2 (M_PI / 2)
|
|
|
|
|
|
|
|
#define M_GOLDEN 1.6180339f
|
2016-02-25 13:13:02 -04:00
|
|
|
|
|
|
|
#define M_2PI (M_PI * 2)
|
|
|
|
|
|
|
|
// MATH_CHECK_INDEXES modifies some objects (e.g. SoloGimbalEKF) to
|
|
|
|
// include more debug information. It is also used by some functions
|
|
|
|
// to add extra code for debugging purposes. If you wish to activate
|
|
|
|
// this, do it here or as part of the top-level Makefile -
|
|
|
|
// e.g. Tools/Replay/Makefile
|
|
|
|
#ifndef MATH_CHECK_INDEXES
|
|
|
|
#define MATH_CHECK_INDEXES 0
|
|
|
|
#endif
|
2016-02-25 20:08:07 -04:00
|
|
|
|
2016-02-25 13:13:02 -04:00
|
|
|
#define DEG_TO_RAD (M_PI / 180.0f)
|
|
|
|
#define RAD_TO_DEG (180.0f / M_PI)
|
2016-02-25 20:08:07 -04:00
|
|
|
|
2017-12-03 15:44:47 -04:00
|
|
|
// Centi-degrees to radians
|
|
|
|
#define DEGX100 5729.57795f
|
|
|
|
|
2016-02-25 13:13:02 -04:00
|
|
|
// GPS Specific double precision conversions
|
|
|
|
// The precision here does matter when using the wsg* functions for converting
|
|
|
|
// between LLH and ECEF coordinates.
|
2018-05-03 22:19:31 -03:00
|
|
|
#ifdef ALLOW_DOUBLE_MATH_FUNCTIONS
|
2017-01-31 13:22:00 -04:00
|
|
|
static const double DEG_TO_RAD_DOUBLE = asin(1) / 90;
|
|
|
|
static const double RAD_TO_DEG_DOUBLE = 1 / DEG_TO_RAD_DOUBLE;
|
2018-05-03 22:19:31 -03:00
|
|
|
#endif
|
2016-02-25 20:08:07 -04:00
|
|
|
|
2016-02-25 13:13:02 -04:00
|
|
|
#define RadiansToCentiDegrees(x) (static_cast<float>(x) * RAD_TO_DEG * static_cast<float>(100))
|
2016-02-25 20:08:07 -04:00
|
|
|
|
2016-02-25 13:13:02 -04:00
|
|
|
// acceleration due to gravity in m/s/s
|
|
|
|
#define GRAVITY_MSS 9.80665f
|
2016-02-25 20:08:07 -04:00
|
|
|
|
2016-02-25 13:13:02 -04:00
|
|
|
// radius of earth in meters
|
|
|
|
#define RADIUS_OF_EARTH 6378100
|
2016-02-25 20:08:07 -04:00
|
|
|
|
2017-12-03 15:44:47 -04:00
|
|
|
// convert a longitude or latitude point to meters or centimeters.
|
2016-02-25 13:13:02 -04:00
|
|
|
// Note: this does not include the longitude scaling which is dependent upon location
|
2021-06-29 03:18:14 -03:00
|
|
|
#define LATLON_TO_M 0.011131884502145034
|
|
|
|
#define LATLON_TO_M_INV 89.83204953368922
|
|
|
|
#define LATLON_TO_CM 1.1131884502145034
|
2016-02-25 20:08:07 -04:00
|
|
|
|
2016-02-25 13:13:02 -04:00
|
|
|
// Semi-major axis of the Earth, in meters.
|
2017-01-31 13:22:00 -04:00
|
|
|
static const double WGS84_A = 6378137.0;
|
|
|
|
|
2016-02-25 13:13:02 -04:00
|
|
|
//Inverse flattening of the Earth
|
2017-01-31 13:22:00 -04:00
|
|
|
static const double WGS84_IF = 298.257223563;
|
|
|
|
|
2016-02-25 13:13:02 -04:00
|
|
|
// The flattening of the Earth
|
2017-01-31 13:22:00 -04:00
|
|
|
static const double WGS84_F = ((double)1.0 / WGS84_IF);
|
|
|
|
|
2016-02-25 13:13:02 -04:00
|
|
|
// Semi-minor axis of the Earth in meters
|
2017-01-31 13:22:00 -04:00
|
|
|
static const double WGS84_B = (WGS84_A * (1 - WGS84_F));
|
|
|
|
|
2016-02-25 13:13:02 -04:00
|
|
|
// Eccentricity of the Earth
|
2018-05-03 22:19:31 -03:00
|
|
|
#ifdef ALLOW_DOUBLE_MATH_FUNCTIONS
|
2017-01-31 13:22:00 -04:00
|
|
|
static const double WGS84_E = (sqrt(2 * WGS84_F - WGS84_F * WGS84_F));
|
2018-05-03 22:19:31 -03:00
|
|
|
#endif
|
2016-02-25 20:08:07 -04:00
|
|
|
|
2022-01-12 04:12:56 -04:00
|
|
|
#define C_TO_KELVIN(temp) (temp + 273.15f)
|
|
|
|
#define KELVIN_TO_C(temp) (temp - 273.15f)
|
|
|
|
#define F_TO_KELVIN(temp) C_TO_KELVIN(((temp - 32) * 5/9))
|
2017-11-03 06:10:47 -03:00
|
|
|
|
2019-03-21 20:38:38 -03:00
|
|
|
#define M_PER_SEC_TO_KNOTS 1.94384449f
|
2019-05-28 18:08:14 -03:00
|
|
|
#define KNOTS_TO_M_PER_SEC (1/M_PER_SEC_TO_KNOTS)
|
|
|
|
|
|
|
|
#define KM_PER_HOUR_TO_M_PER_SEC 0.27777778f
|
2019-03-21 20:38:38 -03:00
|
|
|
|
2017-11-03 06:10:47 -03:00
|
|
|
// Gas Constant is from Aerodynamics for Engineering Students, Third Edition, E.L.Houghton and N.B.Carruthers
|
|
|
|
#define ISA_GAS_CONSTANT 287.26f
|
|
|
|
#define ISA_LAPSE_RATE 0.0065f
|
|
|
|
|
2018-05-10 23:25:02 -03:00
|
|
|
// Standard Sea Level values
|
|
|
|
// Ref: https://en.wikipedia.org/wiki/Standard_sea_level
|
|
|
|
#define SSL_AIR_DENSITY 1.225f // kg/m^3
|
|
|
|
#define SSL_AIR_PRESSURE 101325.01576f // Pascal
|
|
|
|
#define SSL_AIR_TEMPERATURE 288.15f // K
|
|
|
|
|
2018-07-11 23:04:11 -03:00
|
|
|
#define INCH_OF_H2O_TO_PASCAL 248.84f
|
|
|
|
|
2017-05-05 07:09:29 -03:00
|
|
|
/*
|
|
|
|
use AP_ prefix to prevent conflict with OS headers, such as NuttX
|
|
|
|
clock.h
|
|
|
|
*/
|
|
|
|
#define AP_NSEC_PER_SEC 1000000000ULL
|
|
|
|
#define AP_NSEC_PER_USEC 1000ULL
|
|
|
|
#define AP_USEC_PER_SEC 1000000ULL
|
|
|
|
#define AP_USEC_PER_MSEC 1000ULL
|
|
|
|
#define AP_MSEC_PER_SEC 1000ULL
|
2021-11-18 18:23:27 -04:00
|
|
|
#define AP_SEC_PER_HOUR (3600ULL)
|
|
|
|
#define AP_MSEC_PER_HOUR (AP_SEC_PER_HOUR * AP_MSEC_PER_SEC)
|
2017-05-05 07:09:29 -03:00
|
|
|
#define AP_SEC_PER_WEEK (7ULL * 86400ULL)
|
|
|
|
#define AP_MSEC_PER_WEEK (AP_SEC_PER_WEEK * AP_MSEC_PER_SEC)
|
2017-11-12 23:35:01 -04:00
|
|
|
|
|
|
|
// speed and distance conversions
|
|
|
|
#define KNOTS_TO_METERS_PER_SECOND 0.51444
|
|
|
|
#define FEET_TO_METERS 0.3048
|
|
|
|
|
2020-11-18 07:21:34 -04:00
|
|
|
// Convert amps milliseconds to milliamp hours
|
|
|
|
// Amp.millisec to milliAmp.hour = 1/1E3(ms->s) * 1/3600(s->hr) * 1000(A->mA)
|
|
|
|
#define AMS_TO_MAH 0.000277777778f
|
2021-12-16 22:35:07 -04:00
|
|
|
|
|
|
|
// Amps microseconds to milliamp hours
|
|
|
|
#define AUS_TO_MAH 0.0000002778f
|
2022-03-30 00:07:15 -03:00
|
|
|
|
|
|
|
// kg/m^3 to g/cm^3
|
|
|
|
#define KG_PER_M3_TO_G_PER_CM3(x) (0.001 * x)
|