Browse Source

tests add ctlmath and use float FLT_EPSILON

sbg
Daniel Agar 7 years ago
parent
commit
735c5544ae
  1. 1
      platforms/posix/cmake/sitl_tests.cmake
  2. 27
      src/modules/mc_pos_control/mc_pos_control_tests/test_controlmath.cpp

1
platforms/posix/cmake/sitl_tests.cmake

@ -9,6 +9,7 @@ set(tests
commander commander
controllib controllib
conv conv
ctlmath
dataman dataman
file2 file2
float float

27
src/modules/mc_pos_control/mc_pos_control_tests/test_controlmath.cpp

@ -1,8 +1,7 @@
#include <unit_test.h> #include <unit_test.h>
#include "../Utility/ControlMath.hpp" #include "../Utility/ControlMath.hpp"
#include <mathlib/mathlib.h> #include <mathlib/mathlib.h>
#include <cfloat>
static const float EPS = 0.00000001f;
class ControlMathTest : public UnitTest class ControlMathTest : public UnitTest
{ {
@ -29,20 +28,20 @@ bool ControlMathTest::testThrAttMapping()
matrix::Vector3f thr{0.0f, 0.0f, -1.0f}; matrix::Vector3f thr{0.0f, 0.0f, -1.0f};
float yaw = 0.0f; float yaw = 0.0f;
vehicle_attitude_setpoint_s att = ControlMath::thrustToAttitude(thr, yaw); vehicle_attitude_setpoint_s att = ControlMath::thrustToAttitude(thr, yaw);
ut_compare("", att.roll_body, EPS); ut_assert_true(att.roll_body < FLT_EPSILON);
ut_assert_true(att.pitch_body < EPS); ut_assert_true(att.pitch_body < FLT_EPSILON);
ut_assert_true(att.yaw_body < EPS); ut_assert_true(att.yaw_body < FLT_EPSILON);
ut_assert_true(att.thrust - 1.0f < EPS); ut_assert_true(att.thrust - 1.0f < FLT_EPSILON);
/* expected: same as before but with 90 yaw /* expected: same as before but with 90 yaw
* reason: only yaw changed * reason: only yaw changed
*/ */
yaw = M_PI_2_F; yaw = M_PI_2_F;
att = ControlMath::thrustToAttitude(thr, yaw); att = ControlMath::thrustToAttitude(thr, yaw);
ut_assert_true(att.roll_body < EPS); ut_assert_true(att.roll_body < FLT_EPSILON);
ut_assert_true(att.pitch_body < EPS); ut_assert_true(att.pitch_body < FLT_EPSILON);
ut_assert_true(att.yaw_body - M_PI_2_F < EPS); ut_assert_true(att.yaw_body - M_PI_2_F < FLT_EPSILON);
ut_assert_true(att.thrust - 1.0f < EPS); ut_assert_true(att.thrust - 1.0f < FLT_EPSILON);
/* expected: same as before but roll 180 /* expected: same as before but roll 180
* reason: thrust points straight down and order Euler * reason: thrust points straight down and order Euler
@ -50,10 +49,10 @@ bool ControlMathTest::testThrAttMapping()
*/ */
thr = matrix::Vector3f(0.0f, 0.0f, 1.0f); thr = matrix::Vector3f(0.0f, 0.0f, 1.0f);
att = ControlMath::thrustToAttitude(thr, yaw); att = ControlMath::thrustToAttitude(thr, yaw);
ut_assert_true(fabsf(att.roll_body) - M_PI_F < EPS); ut_assert_true(fabsf(att.roll_body) - M_PI_F < FLT_EPSILON);
ut_assert_true(fabsf(att.pitch_body) < EPS); ut_assert_true(fabsf(att.pitch_body) < FLT_EPSILON);
ut_assert_true(att.yaw_body - M_PI_2_F < EPS); ut_assert_true(att.yaw_body - M_PI_2_F < FLT_EPSILON);
ut_assert_true(att.thrust - 1.0f < EPS); ut_assert_true(att.thrust - 1.0f < FLT_EPSILON);
/* TODO: find a good way to test it */ /* TODO: find a good way to test it */

Loading…
Cancel
Save