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
5b2643fc
Commit
5b2643fc
authored
10 years ago
by
Lorenz Meier
Browse files
Options
Downloads
Plain Diff
Merge pull request #1888 from PX4/quat_rot_math_test
added quaternion rotation method test
parents
600628b5
af56e585
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_mathlib.cpp
+72
-1
72 additions, 1 deletion
src/systemcmds/tests/test_mathlib.cpp
with
72 additions
and
1 deletion
src/systemcmds/tests/test_mathlib.cpp
+
72
−
1
View file @
5b2643fc
...
...
@@ -282,5 +282,76 @@ int test_mathlib(int argc, char *argv[])
}
{
// test quaternion method "rotate" (rotate vector by quaternion)
Vector
<
3
>
vector
=
{
1.0
f
,
1.0
f
,
1.0
f
};
Vector
<
3
>
vector_q
;
Vector
<
3
>
vector_r
;
Quaternion
q
;
Matrix
<
3
,
3
>
R
;
float
diff
=
0.1
f
;
float
tol
=
0.00001
f
;
warnx
(
"Quaternion vector rotation method test."
);
for
(
float
roll
=
-
M_PI_F
;
roll
<=
M_PI_F
;
roll
+=
diff
)
{
for
(
float
pitch
=
-
M_PI_2_F
;
pitch
<=
M_PI_2_F
;
pitch
+=
diff
)
{
for
(
float
yaw
=
-
M_PI_F
;
yaw
<=
M_PI_F
;
yaw
+=
diff
)
{
R
.
from_euler
(
roll
,
pitch
,
yaw
);
q
.
from_euler
(
roll
,
pitch
,
yaw
);
vector_r
=
R
*
vector
;
vector_q
=
q
.
rotate
(
vector
);
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
if
(
fabsf
(
vector_r
(
i
)
-
vector_q
(
i
))
>
tol
)
{
warnx
(
"Quaternion method 'rotate' outside tolerance"
);
rc
=
1
;
}
}
}
}
}
// test some values calculated with matlab
tol
=
0.0001
f
;
q
.
from_euler
(
M_PI_2_F
,
0.0
f
,
0.0
f
);
vector_q
=
q
.
rotate
(
vector
);
Vector
<
3
>
vector_true
=
{
1.00
f
,
-
1.00
f
,
1.00
f
};
for
(
unsigned
i
=
0
;
i
<
3
;
i
++
)
{
if
(
fabsf
(
vector_true
(
i
)
-
vector_q
(
i
))
>
tol
)
{
warnx
(
"Quaternion method 'rotate' outside tolerance"
);
rc
=
1
;
}
}
q
.
from_euler
(
0.3
f
,
0.2
f
,
0.1
f
);
vector_q
=
q
.
rotate
(
vector
);
vector_true
=
{
1.1566
,
0.7792
,
1.0273
};
for
(
unsigned
i
=
0
;
i
<
3
;
i
++
)
{
if
(
fabsf
(
vector_true
(
i
)
-
vector_q
(
i
))
>
tol
)
{
warnx
(
"Quaternion method 'rotate' outside tolerance"
);
rc
=
1
;
}
}
q
.
from_euler
(
-
1.5
f
,
-
0.2
f
,
0.5
f
);
vector_q
=
q
.
rotate
(
vector
);
vector_true
=
{
0.5095
,
1.4956
,
-
0.7096
};
for
(
unsigned
i
=
0
;
i
<
3
;
i
++
)
{
if
(
fabsf
(
vector_true
(
i
)
-
vector_q
(
i
))
>
tol
)
{
warnx
(
"Quaternion method 'rotate' outside tolerance"
);
rc
=
1
;
}
}
q
.
from_euler
(
M_PI_2_F
,
-
M_PI_2_F
,
-
M_PI_F
/
3.0
f
);
vector_q
=
q
.
rotate
(
vector
);
vector_true
=
{
-
1.3660
,
0.3660
,
1.0000
};
for
(
unsigned
i
=
0
;
i
<
3
;
i
++
)
{
if
(
fabsf
(
vector_true
(
i
)
-
vector_q
(
i
))
>
tol
)
{
warnx
(
"Quaternion method 'rotate' outside tolerance"
);
rc
=
1
;
}
}
}
return
rc
;
}
}
\ No newline at end of file
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