From b360521d0ba3c4d25628e5705e1a5a7778e0543f Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Sat, 16 Oct 2021 17:10:20 +1100 Subject: [PATCH] SITL: permit double-precision maths in SITL even on embedded hardware --- libraries/SITL/SIM_Aircraft.cpp | 3 ++- libraries/SITL/SIM_BalanceBot.cpp | 2 ++ libraries/SITL/SIM_Blimp.cpp | 2 ++ libraries/SITL/SIM_GPS.cpp | 2 ++ libraries/SITL/SIM_MS5611.cpp | 2 ++ libraries/SITL/SIM_Plane.cpp | 2 ++ libraries/SITL/SIM_Submarine.h | 6 +++--- libraries/SITL/SITL.cpp | 2 ++ 8 files changed, 17 insertions(+), 4 deletions(-) diff --git a/libraries/SITL/SIM_Aircraft.cpp b/libraries/SITL/SIM_Aircraft.cpp index bcc95e8587..00f355a336 100644 --- a/libraries/SITL/SIM_Aircraft.cpp +++ b/libraries/SITL/SIM_Aircraft.cpp @@ -16,13 +16,14 @@ parent class for aircraft simulators */ +#define ALLOW_DOUBLE_MATH_FUNCTIONS + #include "SIM_Aircraft.h" #include #include #include - #if defined(__CYGWIN__) || defined(__CYGWIN64__) #include #include diff --git a/libraries/SITL/SIM_BalanceBot.cpp b/libraries/SITL/SIM_BalanceBot.cpp index 384be77f67..f3b11d0c90 100644 --- a/libraries/SITL/SIM_BalanceBot.cpp +++ b/libraries/SITL/SIM_BalanceBot.cpp @@ -16,6 +16,8 @@ Balance Bot simulator class */ +#define ALLOW_DOUBLE_MATH_FUNCTIONS + #include "SIM_BalanceBot.h" #include diff --git a/libraries/SITL/SIM_Blimp.cpp b/libraries/SITL/SIM_Blimp.cpp index ea129152b9..73e41d0eae 100644 --- a/libraries/SITL/SIM_Blimp.cpp +++ b/libraries/SITL/SIM_Blimp.cpp @@ -16,6 +16,8 @@ Blimp simulator class */ +#define ALLOW_DOUBLE_MATH_FUNCTIONS + #include "SIM_Blimp.h" #include diff --git a/libraries/SITL/SIM_GPS.cpp b/libraries/SITL/SIM_GPS.cpp index 9790ef49ec..5e45104178 100644 --- a/libraries/SITL/SIM_GPS.cpp +++ b/libraries/SITL/SIM_GPS.cpp @@ -12,6 +12,8 @@ #include +#define ALLOW_DOUBLE_MATH_FUNCTIONS + #include #include #include diff --git a/libraries/SITL/SIM_MS5611.cpp b/libraries/SITL/SIM_MS5611.cpp index a1957df17d..d269272598 100644 --- a/libraries/SITL/SIM_MS5611.cpp +++ b/libraries/SITL/SIM_MS5611.cpp @@ -1,3 +1,5 @@ +#define ALLOW_DOUBLE_MATH_FUNCTIONS + #include "SIM_MS5611.h" #include diff --git a/libraries/SITL/SIM_Plane.cpp b/libraries/SITL/SIM_Plane.cpp index c529f33814..f7b61f7df3 100644 --- a/libraries/SITL/SIM_Plane.cpp +++ b/libraries/SITL/SIM_Plane.cpp @@ -17,6 +17,8 @@ just enough to be able to debug control logic for new frame types */ +#define ALLOW_DOUBLE_MATH_FUNCTIONS + #include "SIM_Plane.h" #include diff --git a/libraries/SITL/SIM_Submarine.h b/libraries/SITL/SIM_Submarine.h index 42181e5a72..6c562cd496 100644 --- a/libraries/SITL/SIM_Submarine.h +++ b/libraries/SITL/SIM_Submarine.h @@ -67,12 +67,12 @@ protected: float thruster_mount_radius = 0.25; // distance in meters from thrusters to center of mass. Used to calculate torque. float equivalent_sphere_radius = 0.2; // volume = 4.pi.r³/3 - float volume = 4 * M_PI * pow(equivalent_sphere_radius, 3) / 3; + float volume = 4 * M_PI * powf(equivalent_sphere_radius, 3) / 3; float density = 500; float mass = volume * density; // 16.75 kg // Moment of Inertia (I)(kg.m²) approximated with a sphere with a 25 cm radius (r) and same density as water // I = 2.m.r²/5 - float moment_of_inertia = 2 * (mass * pow(equivalent_sphere_radius, 2) / 5); + float moment_of_inertia = 2 * (mass * powf(equivalent_sphere_radius, 2) / 5); // Frame drag coefficient const Vector3f linear_drag_coefficient = Vector3f(1.4, 1.8, 2.0); @@ -83,7 +83,7 @@ protected: // $ V = 4 * pi * r^3 / 3 $ // $ r ^2 = (V * 3 / 4) ^ (2/3) $ // A = area (m^3), r = sphere radius (m) - float equivalent_sphere_area = M_PI_4 * pow(volume * 3.0f / 4.0f, 2.0f / 3.0f); + float equivalent_sphere_area = M_PI_4 * powf(volume * 3.0f / 4.0f, 2.0f / 3.0f); } frame_property; diff --git a/libraries/SITL/SITL.cpp b/libraries/SITL/SITL.cpp index 03899443df..8007e4e4e1 100644 --- a/libraries/SITL/SITL.cpp +++ b/libraries/SITL/SITL.cpp @@ -17,6 +17,8 @@ SITL.cpp - software in the loop state */ +#define ALLOW_DOUBLE_MATH_FUNCTIONS + #include "SITL.h" #if AP_SIM_ENABLED