Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | mjames | 1 | #include "jtest.h" |
2 | #include "arr_desc.h" |
||
3 | #include "arm_math.h" |
||
4 | #include "ref.h" |
||
5 | #include "type_abbrev.h" |
||
6 | #include "test_templates.h" |
||
7 | #include "controller_test_data.h" |
||
8 | #include "controller_templates.h" |
||
9 | |||
10 | /** |
||
11 | * Define a JTEST_TEST_t for the function arm_pid_xxx function having |
||
12 | * suffix. |
||
13 | */ |
||
14 | #define ARM_PID_TEST(suffix,type) \ |
||
15 | JTEST_DEFINE_TEST(arm_pid_##suffix##_test, arm_pid_##suffix) \ |
||
16 | { \ |
||
17 | uint32_t i,j; \ |
||
18 | \ |
||
19 | arm_pid_instance_##suffix fut_pid_inst = { 0 }; \ |
||
20 | arm_pid_instance_##suffix ref_pid_inst = { 0 }; \ |
||
21 | \ |
||
22 | for(i=0;i<CONTROLLER_MAX_COEFFS_LEN/3;i++) \ |
||
23 | { \ |
||
24 | fut_pid_inst.Kp = controller_##suffix##_coeffs[i*3+0]; \ |
||
25 | fut_pid_inst.Ki = controller_##suffix##_coeffs[i*3+1]; \ |
||
26 | fut_pid_inst.Kd = controller_##suffix##_coeffs[i*3+2]; \ |
||
27 | ref_pid_inst.Kp = controller_##suffix##_coeffs[i*3+0]; \ |
||
28 | ref_pid_inst.Ki = controller_##suffix##_coeffs[i*3+1]; \ |
||
29 | ref_pid_inst.Kd = controller_##suffix##_coeffs[i*3+2]; \ |
||
30 | \ |
||
31 | arm_pid_init_##suffix(&fut_pid_inst, 1); \ |
||
32 | arm_pid_init_##suffix(&ref_pid_inst, 1); \ |
||
33 | \ |
||
34 | /* Display parameter values */ \ |
||
35 | JTEST_DUMP_STRF("Block Size: %d\n", \ |
||
36 | (int)CONTROLLER_MAX_LEN); \ |
||
37 | \ |
||
38 | /* Display cycle count and run test */ \ |
||
39 | JTEST_COUNT_CYCLES( \ |
||
40 | for(j=0;j<CONTROLLER_MAX_LEN;j++) \ |
||
41 | { \ |
||
42 | *((type*)controller_output_fut + j) = \ |
||
43 | arm_pid_##suffix(&fut_pid_inst, \ |
||
44 | controller_##suffix##_inputs[j]); \ |
||
45 | }); \ |
||
46 | \ |
||
47 | for(j=0;j<CONTROLLER_MAX_LEN;j++) \ |
||
48 | { \ |
||
49 | *((type*)controller_output_ref + j) = \ |
||
50 | ref_pid_##suffix(&ref_pid_inst, \ |
||
51 | controller_##suffix##_inputs[j]); \ |
||
52 | } \ |
||
53 | \ |
||
54 | /* Test correctness */ \ |
||
55 | CONTROLLER_SNR_COMPARE_INTERFACE( \ |
||
56 | CONTROLLER_MAX_LEN, \ |
||
57 | type); \ |
||
58 | } \ |
||
59 | \ |
||
60 | return JTEST_TEST_PASSED; \ |
||
61 | } |
||
62 | |||
63 | ARM_PID_TEST(f32,float32_t); |
||
64 | ARM_PID_TEST(q31,q31_t); |
||
65 | ARM_PID_TEST(q15,q15_t); |
||
66 | |||
67 | /*--------------------------------------------------------------------------------*/ |
||
68 | /* Collect all tests in a group */ |
||
69 | /*--------------------------------------------------------------------------------*/ |
||
70 | |||
71 | JTEST_DEFINE_GROUP(pid_tests) |
||
72 | { |
||
73 | /* |
||
74 | To skip a test, comment it out. |
||
75 | */ |
||
76 | JTEST_TEST_CALL(arm_pid_f32_test); |
||
77 | JTEST_TEST_CALL(arm_pid_q31_test); |
||
78 | JTEST_TEST_CALL(arm_pid_q15_test); |
||
79 | } |