4
4
5
5
using namespace hako ::drone_physics;
6
6
7
+ #undef NDEBUG // force assert to work even if release bulid.
8
+
7
9
const double PI = M_PI;
8
10
9
11
void test_frame_all_unit_vectors_with_angle0 () {
@@ -45,18 +47,18 @@ void test_frame_matrix_is_unitary() {
45
47
for (int i = -180 ; i < 180 ; i+=30 ) {
46
48
VelocityType v2 = ground_vector_from_body (v1, EulerType{i * (PI/180 ), 0 , 0 });
47
49
double len = length_squared (v2);
48
- assert (fabs (len - 1.0 ) < 0.0001 );
50
+ assert (std::abs (len - 1.0 ) < 0.0001 );
49
51
}
50
52
for (int i = 0 ; i < 90 ; i+=30 ) {
51
53
VelocityType v2 = ground_vector_from_body (v1, EulerType{0 , i * (PI/180 ), 0 });
52
54
double len = length_squared (v2);
53
- assert (fabs (len - 1.0 ) < 0.0001 );
55
+ assert (std::abs (len - 1.0 ) < 0.0001 );
54
56
}
55
57
56
58
for (int i = -180 ; i < 360 ; i+=30 ) {
57
59
VelocityType v2 = ground_vector_from_body (v1, EulerType{0 , 0 , i * (PI/180 )});
58
60
double len = length_squared (v2);
59
- assert (fabs (len - 1.0 ) < 0.0001 );
61
+ assert (std::abs (len - 1.0 ) < 0.0001 );
60
62
}
61
63
62
64
// conbinations
@@ -67,16 +69,16 @@ void test_frame_matrix_is_unitary() {
67
69
for (int k = -180 ; k < 180 ; k+=30 ) {
68
70
VelocityType V = ground_vector_from_body (v1, EulerType{i * (PI/180 ), j * (PI/180 ), k * (PI/180 )});
69
71
double len = length_squared (V);
70
- assert (fabs (len - 1.0 ) < 0.0001 );
72
+ assert (std::abs (len - 1.0 ) < 0.0001 );
71
73
72
74
// bug #89 indicated that need testing (0,1,0) and (0,0,1) vectors.
73
75
V = ground_vector_from_body (u1, EulerType{i * (PI/180 ), j * (PI/180 ), k * (PI/180 )});
74
76
len = length_squared (V);
75
- assert (fabs (len - 1.0 ) < 0.0001 );
77
+ assert (std::abs (len - 1.0 ) < 0.0001 );
76
78
77
79
V = ground_vector_from_body (w1, EulerType{i * (PI/180 ), j * (PI/180 ), k * (PI/180 )});
78
80
len = length_squared (V);
79
- assert (fabs (len - 1.0 ) < 0.0001 );
81
+ assert (std::abs (len - 1.0 ) < 0.0001 );
80
82
81
83
}
82
84
}
@@ -329,7 +331,7 @@ void test_ground_angular_acceleration()
329
331
void test_rotor_omega_acceleration () {
330
332
double Kr = 2896 , Tr = 4.5e-2 , duty_rate = 1 , omega = 0 ;
331
333
double a = rotor_omega_acceleration (Kr, Tr, omega, duty_rate);
332
- assert (std::fabs (a - (Kr * duty_rate - omega) / Tr) < 0.0001 );
334
+ assert (std::abs (a - (Kr * duty_rate - omega) / Tr) < 0.0001 );
333
335
334
336
std::ofstream ofs;
335
337
ofs.open (" omega_times_series.csv" , std::ios::out);
@@ -349,7 +351,7 @@ void test_rotor_omega_acceleration() {
349
351
double a = rotor_omega_acceleration (Kr, Tr, omega_a, duty_rate);
350
352
double b = rotor_omega_acceleration (Vbat, R, Cq, J, K, D, omega_b, duty_rate);
351
353
352
- assert (std::fabs (a - (Kr * duty_rate - omega_a) / Tr) < 0.0001 );
354
+ assert (std::abs (a - (Kr * duty_rate - omega_a) / Tr) < 0.0001 );
353
355
omega_a += a*time;
354
356
omega_b += b*time;
355
357
@@ -358,7 +360,7 @@ void test_rotor_omega_acceleration() {
358
360
* if duty_rate is a constant, the solution is
359
361
* Omega = Kr * (1 - exp(-t/Tr) * (duty rate))
360
362
*/
361
- // assert(std::fabs (omega_a - Kr*(1 - std::exp(-time/Tr)*duty_rate) < 10));
363
+ // assert(std::std::abs (omega_a - Kr*(1 - std::exp(-time/Tr)*duty_rate) < 10));
362
364
ofs << time << " ," << a*time << " ," << omega_a << " , " << b*time << " , " << omega_b << std::endl;
363
365
}
364
366
ofs.close ();
0 commit comments