18 #define SHOW_POLES_BREAKDOWN 0 22 float diff = rad1 - rad2;
33 float roll,
float pitch,
float yaw,
34 float roll2,
float pitch2,
float yaw2)
39 hal.
console->
printf(
"%s NAN eulers roll=%f pitch=%f yaw=%f\n",
48 roll2 += fmodf(roll2 +
M_PI, 2 *
M_PI);
49 pitch2 += fmodf(pitch2 +
M_PI, 2 *
M_PI);
50 yaw2 += fmodf(yaw2 +
M_PI, 2 *
M_PI);
56 if (pitch >=
M_PI/2 ||
61 #if SHOW_POLES_BREAKDOWN 63 "%s breakdown eulers roll=%f/%f pitch=%f/%f yaw=%f/%f\n",
71 "%s incorrect eulers roll=%f/%f pitch=%f/%f yaw=%f/%f\n",
80 static void test_euler(
float roll,
float pitch,
float yaw)
83 float roll2, pitch2, yaw2;
87 check_result(
"test_euler", roll, pitch, yaw, roll2, pitch2, yaw2);
99 for (uint8_t i = 0; i <
N; i++)
100 for (uint8_t j = 0; j <
N; j++)
101 for (uint8_t k = 0; k <
N; k++)
111 float roll2, pitch2, yaw2;
115 check_result(
"test_quaternion1", roll, pitch, yaw, roll2, pitch2, yaw2);
119 check_result(
"test_quaternion2", roll, pitch, yaw, roll2, pitch2, yaw2);
124 check_result(
"test_quaternion3", roll, pitch, yaw, roll2, pitch2, yaw2);
128 check_result(
"test_quaternion4", roll, pitch, yaw, roll2, pitch2, yaw2);
155 for (uint8_t i = 0; i <
N; i++)
156 for (uint8_t j = 0; j <
N; j++)
157 for (uint8_t k = 0; k <
N; k++)
169 float roll2, pitch2, yaw2;
170 float roll3, pitch3, yaw3;
174 check_result(
"test_conversion1", roll, pitch, yaw, roll2, pitch2, yaw2);
180 m2.
to_euler(&roll3, &pitch3, &yaw3);
188 check_result(
"test_conversion2", roll, pitch, yaw, roll2, pitch2, yaw2);
189 check_result(
"test_conversion3", roll, pitch, yaw, roll3, pitch3, yaw3);
204 for (uint8_t i = 0; i <
N; i++)
205 for (uint8_t j = 0; j <
N; j++)
206 for (uint8_t k = 0; k <
N; k++)
226 hal.
console->
printf(
"%f %f %f\n", (
double)v2.
x, (
double)v2.
y, (
double)v2.
z);
228 hal.
console->
printf(
"%f %f %f\n\n", (
double)v2.
x, (
double)v2.
y, (
double)v2.
z);
232 hal.
console->
printf(
"%f %f %f\n", (
double)v2.
x, (
double)v2.
y, (
double)v2.
z);
234 hal.
console->
printf(
"%f %f %f\n\n", (
double)v2.
x, (
double)v2.
y, (
double)v2.
z);
238 hal.
console->
printf(
"%f %f %f\n", (
double)v2.
x, (
double)v2.
y, (
double)v2.
z);
240 hal.
console->
printf(
"%f %f %f\n", (
double)v2.
x, (
double)v2.
y, (
double)v2.
z);
260 for (uint16_t i = 0; i < 1000; i++) {
264 temp_matrix.
a.
y = -r.
z;
265 temp_matrix.
a.
z = r.
y;
266 temp_matrix.
b.
x = r.
z;
268 temp_matrix.
b.
z = -r.
x;
269 temp_matrix.
c.
x = -r.
y;
270 temp_matrix.
c.
y = r.
x;
272 temp_matrix = m1 * temp_matrix;
283 hal.
console->
printf(
"ERROR: i=%u err=%f\n", (
unsigned)i, (
double)err);
void to_euler(float &roll, float &pitch, float &yaw) const
void to_euler(float *roll, float *pitch, float *yaw) const
static float rad_diff(float rad1, float rad2)
void test_conversions(void)
static const float angles[]
Vector3< float > Vector3f
AP_HAL::UARTDriver * console
void test_matrix_eulers(void)
const AP_HAL::HAL & hal
-*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
void from_euler(float roll, float pitch, float yaw)
void from_euler(float roll, float pitch, float yaw)
static void test_conversion(float roll, float pitch, float yaw)
void from_rotation_matrix(const Matrix3f &m)
void test_quaternion_eulers(void)
uint16_t get_random16(void)
void test_frame_transforms(void)
virtual void printf(const char *,...) FMT_PRINTF(2
static void test_quaternion(float roll, float pitch, float yaw)
void rotation_matrix(Matrix3f &m) const
static void test_euler(float roll, float pitch, float yaw)
static void check_result(const char *msg, float roll, float pitch, float yaw, float roll2, float pitch2, float yaw2)
void test_matrix_rotate(void)
void rotate(const Vector3< T > &g)
static float rand_num(void)
void earth_to_body(Vector3f &v) const