6 #include <tf2/LinearMath/Quaternion.h>
7 #include <tf2/LinearMath/Matrix3x3.h>
9 #define _USE_MATH_DEFINES
18 int main(
int argc,
char *argv[])
20 double roll, pitch, yaw;
26 printf(
"Quaternion example program\n");
31 myQuaternion.
setRPY(roll, pitch, yaw);
33 char quatOrder[] =
"xyzw";
34 for (
int i = 0; i < 4; i++)
36 printf(
"%c-Quat[%d]: %8.6lf\n", quatOrder[i], i, myQuaternion[i]);
40 for (
int i = 0; i < 4; i++)
42 printf(
"%c-Quat[%d]: %8.6lf\n", quatOrder[i], i, myQuaternion[i]);
46 const char *axisDescr[] = {
"roll",
"pitch",
"yaw"};
50 m.
getRPY(roll, pitch, yaw);
53 printf(
"Rotationsmatrix\n");
55 for (
int i = 0; i < 3; i++)
57 for (
int j = 0; j < 3; j++)
60 printf(
"%10.3lf", m[i][j]);
74 for (
int i = 0; i < 3; i++)
75 for (
int j = 0; j < 3; j++)
86 rotz[0][0] = cos(yaw);
87 rotz[1][1] = cos(yaw);
88 rotz[0][1] = -sin(yaw);
89 rotz[1][0] = sin(yaw);
91 roty[0][0] = cos(pitch);
92 roty[2][2] = cos(pitch);
93 roty[0][2] = sin(pitch);
94 roty[2][0] = -sin(pitch);
96 rotx[1][1] = cos(roll);
97 rotx[2][2] = cos(roll);
98 rotx[1][2] = -sin(roll);
99 rotx[2][1] = sin(roll);
101 rot = rotz * roty * rotx;
103 const char* reflArr[] = {
"rotz",
"roty",
"rotx",
"rot_result"};
104 for (
int loop = 0; loop < 4; loop++)
122 printf(
"\nName: %s\n==========================\n", reflArr[loop]);
123 for (
int i = 0; i < 3; i++)
125 for (
int j = 0; j < 3; j++)
128 printf(
"%10.3lf", (*rotptr)[i][j]);