aboutsummaryrefslogtreecommitdiff
path: root/src/systemcmds/tests
diff options
context:
space:
mode:
authorRoman Bapst <romanbapst@yahoo.de>2015-03-05 16:47:27 +0100
committertumbili <bapstr@ethz.ch>2015-03-06 15:56:54 +0100
commitaf56e58540565006a24758d03d0e2bb4b187c7fa (patch)
tree9b439b977c1d2064c4307492fd8a9bd5b96b4379 /src/systemcmds/tests
parent9d4b4ab0492c4fb2f42ee1e6940c8f85c473f2ad (diff)
downloadpx4-firmware-af56e58540565006a24758d03d0e2bb4b187c7fa.tar.gz
px4-firmware-af56e58540565006a24758d03d0e2bb4b187c7fa.tar.bz2
px4-firmware-af56e58540565006a24758d03d0e2bb4b187c7fa.zip
added quaternion rotation method test
Diffstat (limited to 'src/systemcmds/tests')
-rw-r--r--src/systemcmds/tests/test_mathlib.cpp73
1 files changed, 72 insertions, 1 deletions
diff --git a/src/systemcmds/tests/test_mathlib.cpp b/src/systemcmds/tests/test_mathlib.cpp
index 682514cb7..a66cebd2f 100644
--- a/src/systemcmds/tests/test_mathlib.cpp
+++ b/src/systemcmds/tests/test_mathlib.cpp
@@ -282,5 +282,76 @@ int test_mathlib(int argc, char *argv[])
}
+ {
+ // test quaternion method "rotate" (rotate vector by quaternion)
+ Vector<3> vector = {1.0f,1.0f,1.0f};
+ Vector<3> vector_q;
+ Vector<3> vector_r;
+ Quaternion q;
+ Matrix<3,3> R;
+ float diff = 0.1f;
+ float tol = 0.00001f;
+
+ 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.0001f;
+ q.from_euler(M_PI_2_F,0.0f,0.0f);
+ vector_q = q.rotate(vector);
+ Vector<3> vector_true = {1.00f,-1.00f,1.00f};
+ 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.3f,0.2f,0.1f);
+ 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.5f,-0.2f,0.5f);
+ 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.0f);
+ 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