Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alberto Ruiz Garcia
Firmware
Commits
d94778dd
Commit
d94778dd
authored
6 years ago
by
Dennis Mannhart
Committed by
Dennis Mannhart
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
test_controlmath: replace FLT_EPSILON with 10^-6
parent
888d8500
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/systemcmds/tests/test_controlmath.cpp
+21
-19
21 additions, 19 deletions
src/systemcmds/tests/test_controlmath.cpp
with
21 additions
and
19 deletions
src/systemcmds/tests/test_controlmath.cpp
+
21
−
19
View file @
d94778dd
...
...
@@ -3,6 +3,8 @@
#include
<mathlib/mathlib.h>
#include
<cfloat>
#define SIGMA_SINGLE_OP 0.000001f
class
ControlMathTest
:
public
UnitTest
{
public:
...
...
@@ -32,20 +34,20 @@ bool ControlMathTest::testThrAttMapping()
matrix
::
Vector3f
thr
{
0.0
f
,
0.0
f
,
-
1.0
f
};
float
yaw
=
0.0
f
;
vehicle_attitude_setpoint_s
att
=
ControlMath
::
thrustToAttitude
(
thr
,
yaw
);
ut_assert_true
(
att
.
roll_body
<
FLT_EPSILON
);
ut_assert_true
(
att
.
pitch_body
<
FLT_EPSILON
);
ut_assert_true
(
att
.
yaw_body
<
FLT_EPSILON
);
ut_assert_true
(
att
.
thrust
-
1.0
f
<
FLT_EPSILON
);
ut_assert_true
(
att
.
roll_body
<
SIGMA_SINGLE_OP
);
ut_assert_true
(
att
.
pitch_body
<
SIGMA_SINGLE_OP
);
ut_assert_true
(
att
.
yaw_body
<
SIGMA_SINGLE_OP
);
ut_assert_true
(
att
.
thrust
-
1.0
f
<
SIGMA_SINGLE_OP
);
/* expected: same as before but with 90 yaw
* reason: only yaw changed
*/
yaw
=
M_PI_2_F
;
att
=
ControlMath
::
thrustToAttitude
(
thr
,
yaw
);
ut_assert_true
(
att
.
roll_body
<
FLT_EPSILON
);
ut_assert_true
(
att
.
pitch_body
<
FLT_EPSILON
);
ut_assert_true
(
att
.
yaw_body
-
M_PI_2_F
<
FLT_EPSILON
);
ut_assert_true
(
att
.
thrust
-
1.0
f
<
FLT_EPSILON
);
ut_assert_true
(
att
.
roll_body
<
SIGMA_SINGLE_OP
);
ut_assert_true
(
att
.
pitch_body
<
SIGMA_SINGLE_OP
);
ut_assert_true
(
att
.
yaw_body
-
M_PI_2_F
<
SIGMA_SINGLE_OP
);
ut_assert_true
(
att
.
thrust
-
1.0
f
<
SIGMA_SINGLE_OP
);
/* expected: same as before but roll 180
* reason: thrust points straight down and order Euler
...
...
@@ -53,10 +55,10 @@ bool ControlMathTest::testThrAttMapping()
*/
thr
=
matrix
::
Vector3f
(
0.0
f
,
0.0
f
,
1.0
f
);
att
=
ControlMath
::
thrustToAttitude
(
thr
,
yaw
);
ut_assert_true
(
fabsf
(
att
.
roll_body
)
-
M_PI_F
<
FLT_EPSILON
);
ut_assert_true
(
fabsf
(
att
.
pitch_body
)
<
FLT_EPSILON
);
ut_assert_true
(
att
.
yaw_body
-
M_PI_2_F
<
FLT_EPSILON
);
ut_assert_true
(
att
.
thrust
-
1.0
f
<
FLT_EPSILON
);
ut_assert_true
(
fabsf
(
att
.
roll_body
)
-
M_PI_F
<
SIGMA_SINGLE_OP
);
ut_assert_true
(
fabsf
(
att
.
pitch_body
)
<
SIGMA_SINGLE_OP
);
ut_assert_true
(
att
.
yaw_body
-
M_PI_2_F
<
SIGMA_SINGLE_OP
);
ut_assert_true
(
att
.
thrust
-
1.0
f
<
SIGMA_SINGLE_OP
);
/* TODO: find a good way to test it */
...
...
@@ -75,29 +77,29 @@ bool ControlMathTest::testPrioritizeVector()
// the static keywork is a workaround for an internal bug of GCC
// "internal compiler error: in trunc_int_for_mode, at explow.c:55"
matrix
::
Vector2f
v_r
=
ControlMath
::
constrainXY
(
v0
,
v1
,
max
);
ut_assert_true
(
fabsf
(
v_r
(
0
))
-
max
<
FLT_EPSILON
&&
v_r
(
0
)
>
0.0
f
);
ut_assert_true
(
fabsf
(
v_r
(
1
)
-
0.0
f
)
<
FLT_EPSILON
);
ut_assert_true
(
fabsf
(
v_r
(
0
))
-
max
<
SIGMA_SINGLE_OP
&&
v_r
(
0
)
>
0.0
f
);
ut_assert_true
(
fabsf
(
v_r
(
1
)
-
0.0
f
)
<
SIGMA_SINGLE_OP
);
// v1 exceeds max but v0 is zero
v0
.
zero
();
v_r
=
ControlMath
::
constrainXY
(
v0
,
v1
,
max
);
ut_assert_true
(
fabsf
(
v_r
(
1
))
-
max
<
FLT_EPSILON
&&
v_r
(
1
)
<
0.0
f
);
ut_assert_true
(
fabsf
(
v_r
(
0
)
-
0.0
f
)
<
FLT_EPSILON
);
ut_assert_true
(
fabsf
(
v_r
(
1
))
-
max
<
SIGMA_SINGLE_OP
&&
v_r
(
1
)
<
0.0
f
);
ut_assert_true
(
fabsf
(
v_r
(
0
)
-
0.0
f
)
<
SIGMA_SINGLE_OP
);
// v0 and v1 are below max
v0
=
matrix
::
Vector2f
(
0.5
f
,
0.5
f
);
v1
(
0
)
=
v0
(
1
);
v1
(
1
)
=
-
v0
(
0
);
v_r
=
ControlMath
::
constrainXY
(
v0
,
v1
,
max
);
float
diff
=
matrix
::
Vector2f
(
v_r
-
(
v0
+
v1
)).
length
();
ut_assert_true
(
diff
<
FLT_EPSILON
);
ut_assert_true
(
diff
<
SIGMA_SINGLE_OP
);
// v0 and v1 exceed max and are perpendicular
v0
=
matrix
::
Vector2f
(
4.0
f
,
0.0
f
);
v1
=
matrix
::
Vector2f
(
0.0
f
,
-
4.0
f
);
v_r
=
ControlMath
::
constrainXY
(
v0
,
v1
,
max
);
ut_assert_true
(
v_r
(
0
)
-
v0
(
0
)
<
FLT_EPSILON
&&
v_r
(
0
)
>
0.0
f
);
ut_assert_true
(
v_r
(
0
)
-
v0
(
0
)
<
SIGMA_SINGLE_OP
&&
v_r
(
0
)
>
0.0
f
);
float
remaining
=
sqrtf
(
max
*
max
-
(
v0
(
0
)
*
v0
(
0
)));
ut_assert_true
(
fabsf
(
v_r
(
1
))
-
remaining
<
FLT_EPSILON
&&
v_r
(
1
)
<
FLT_EPSILON
);
ut_assert_true
(
fabsf
(
v_r
(
1
))
-
remaining
<
SIGMA_SINGLE_OP
&&
v_r
(
1
)
<
SIGMA_SINGLE_OP
);
//TODO: add more tests with vectors not perpendicular
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment