mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-30 18:06:39 +08:00
define M_PI if not defined in math.h
This commit is contained in:
@@ -143,7 +143,9 @@ __END_DECLS
|
|||||||
|
|
||||||
/* The M_PI, as stated above, is not C standard. If you need it and
|
/* The M_PI, as stated above, is not C standard. If you need it and
|
||||||
* it isn't in your math.h file then you can use this instead. */
|
* it isn't in your math.h file then you can use this instead. */
|
||||||
#define M_PI_PRECISE 3.141592653589793238462643383279502884
|
#ifndef M_PI
|
||||||
|
#define M_PI 3.141592653589793238462643383279502884
|
||||||
|
#endif
|
||||||
|
|
||||||
#define M_DEG_TO_RAD 0.017453292519943295
|
#define M_DEG_TO_RAD 0.017453292519943295
|
||||||
#define M_RAD_TO_DEG 57.295779513082323
|
#define M_RAD_TO_DEG 57.295779513082323
|
||||||
|
|||||||
@@ -85,11 +85,11 @@ public:
|
|||||||
{
|
{
|
||||||
theta() = std::asin(-dcm(2, 0));
|
theta() = std::asin(-dcm(2, 0));
|
||||||
|
|
||||||
if ((std::fabs(theta() - Type(M_PI_PRECISE / 2))) < Type(1.0e-3)) {
|
if ((std::fabs(theta() - Type(M_PI / 2))) < Type(1.0e-3)) {
|
||||||
phi() = 0;
|
phi() = 0;
|
||||||
psi() = std::atan2(dcm(1, 2), dcm(0, 2));
|
psi() = std::atan2(dcm(1, 2), dcm(0, 2));
|
||||||
|
|
||||||
} else if ((std::fabs(theta() + Type(M_PI_PRECISE / 2))) < Type(1.0e-3)) {
|
} else if ((std::fabs(theta() + Type(M_PI / 2))) < Type(1.0e-3)) {
|
||||||
phi() = 0;
|
phi() = 0;
|
||||||
psi() = std::atan2(-dcm(1, 2), -dcm(0, 2));
|
psi() = std::atan2(-dcm(1, 2), -dcm(0, 2));
|
||||||
|
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ Integer wrap(Integer x, Integer low, Integer high)
|
|||||||
template<typename Type>
|
template<typename Type>
|
||||||
Type wrap_pi(Type x)
|
Type wrap_pi(Type x)
|
||||||
{
|
{
|
||||||
return wrap(x, Type(-M_PI_PRECISE), Type(M_PI_PRECISE));
|
return wrap(x, Type(-M_PI), Type(M_PI));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -106,7 +106,7 @@ Type wrap_pi(Type x)
|
|||||||
template<typename Type>
|
template<typename Type>
|
||||||
Type wrap_2pi(Type x)
|
Type wrap_2pi(Type x)
|
||||||
{
|
{
|
||||||
return wrap(x, Type(0), Type((2 * M_PI_PRECISE)));
|
return wrap(x, Type(0), Type((2 * M_PI)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -134,7 +134,7 @@ Type unwrap(const Type last_x, const Type new_x, const Type low, const Type high
|
|||||||
template<typename Type>
|
template<typename Type>
|
||||||
Type unwrap_pi(const Type last_angle, const Type new_angle)
|
Type unwrap_pi(const Type last_angle, const Type new_angle)
|
||||||
{
|
{
|
||||||
return unwrap(last_angle, new_angle, Type(-M_PI_PRECISE), Type(M_PI_PRECISE));
|
return unwrap(last_angle, new_angle, Type(-M_PI), Type(M_PI));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -200,8 +200,8 @@ TEST(MatrixAttitudeTest, Attitude)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// constants
|
// constants
|
||||||
double deg2rad = M_PI_PRECISE / 180.0;
|
double deg2rad = M_PI / 180.0;
|
||||||
double rad2deg = 180.0 / M_PI_PRECISE;
|
double rad2deg = 180.0 / M_PI;
|
||||||
|
|
||||||
// euler dcm round trip check
|
// euler dcm round trip check
|
||||||
for (double roll = -90; roll <= 90; roll += 90) {
|
for (double roll = -90; roll <= 90; roll += 90) {
|
||||||
|
|||||||
@@ -81,20 +81,20 @@ TEST(MatrixHelperTest, Helper)
|
|||||||
|
|
||||||
// wrap pi
|
// wrap pi
|
||||||
EXPECT_FLOAT_EQ(wrap_pi(0.), 0.);
|
EXPECT_FLOAT_EQ(wrap_pi(0.), 0.);
|
||||||
EXPECT_FLOAT_EQ(wrap_pi(4.), (4. - (2 * M_PI_PRECISE)));
|
EXPECT_FLOAT_EQ(wrap_pi(4.), (4. - (2 * M_PI)));
|
||||||
EXPECT_FLOAT_EQ(wrap_pi(-4.), (-4. + (2 * M_PI_PRECISE)));
|
EXPECT_FLOAT_EQ(wrap_pi(-4.), (-4. + (2 * M_PI)));
|
||||||
EXPECT_FLOAT_EQ(wrap_pi(3.), 3.);
|
EXPECT_FLOAT_EQ(wrap_pi(3.), 3.);
|
||||||
EXPECT_FLOAT_EQ(wrap_pi(100.), (100. - 32. * M_PI_PRECISE));
|
EXPECT_FLOAT_EQ(wrap_pi(100.), (100. - 32. * M_PI));
|
||||||
EXPECT_FLOAT_EQ(wrap_pi(-100.), (-100. + 32. * M_PI_PRECISE));
|
EXPECT_FLOAT_EQ(wrap_pi(-100.), (-100. + 32. * M_PI));
|
||||||
EXPECT_FLOAT_EQ(wrap_pi(-101.), (-101. + 32. * M_PI_PRECISE));
|
EXPECT_FLOAT_EQ(wrap_pi(-101.), (-101. + 32. * M_PI));
|
||||||
EXPECT_FALSE(std::isfinite(wrap_pi(NAN)));
|
EXPECT_FALSE(std::isfinite(wrap_pi(NAN)));
|
||||||
|
|
||||||
// wrap 2pi
|
// wrap 2pi
|
||||||
EXPECT_FLOAT_EQ(wrap_2pi(0.), 0.);
|
EXPECT_FLOAT_EQ(wrap_2pi(0.), 0.);
|
||||||
EXPECT_FLOAT_EQ(wrap_2pi(-4.), (-4. + 2. * M_PI_PRECISE));
|
EXPECT_FLOAT_EQ(wrap_2pi(-4.), (-4. + 2. * M_PI));
|
||||||
EXPECT_FLOAT_EQ(wrap_2pi(3.), (3.));
|
EXPECT_FLOAT_EQ(wrap_2pi(3.), (3.));
|
||||||
EXPECT_FLOAT_EQ(wrap_2pi(200.), (200. - 31. * (2 * M_PI_PRECISE)));
|
EXPECT_FLOAT_EQ(wrap_2pi(200.), (200. - 31. * (2 * M_PI)));
|
||||||
EXPECT_FLOAT_EQ(wrap_2pi(-201.), (-201. + 32. * (2 * M_PI_PRECISE)));
|
EXPECT_FLOAT_EQ(wrap_2pi(-201.), (-201. + 32. * (2 * M_PI)));
|
||||||
EXPECT_FALSE(std::isfinite(wrap_2pi(NAN)));
|
EXPECT_FALSE(std::isfinite(wrap_2pi(NAN)));
|
||||||
|
|
||||||
// Equality checks
|
// Equality checks
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ TEST(MatrixUnwrapTest, UnwrapFloats)
|
|||||||
|
|
||||||
TEST(MatrixUnwrapTest, UnwrapDoubles)
|
TEST(MatrixUnwrapTest, UnwrapDoubles)
|
||||||
{
|
{
|
||||||
const double M_TWO_PI = M_PI_PRECISE * 2;
|
const double M_TWO_PI = M_PI * 2;
|
||||||
|
|
||||||
double unwrapped_angles[6] = {0.0, 0.25, 0.5, 0.75, 1.0, 1.25};
|
double unwrapped_angles[6] = {0.0, 0.25, 0.5, 0.75, 1.0, 1.25};
|
||||||
double wrapped_angles[6] = {0.0, 0.25, 0.5, -0.25, 0.0, 0.25};
|
double wrapped_angles[6] = {0.0, 0.25, 0.5, -0.25, 0.0, 0.25};
|
||||||
|
|||||||
Reference in New Issue
Block a user