1 #define MAIN_(x) A_CAST_2(x, _pid_neuro)
5 #include "a/pid_neuro.h"
7 static A_INLINE a_float
input(a_float
const x
)
9 #if defined(LIBA_MATH_H)
10 return a_float_sin(4 * A_FLOAT_PI
* x
);
16 int MAIN(int argc
, char *argv
[]) // NOLINT(misc-definitions-in-headers)
18 main_init(argc
, argv
, 1);
20 a_float num
[] = {A_FLOAT_C(6.59492796e-05), A_FLOAT_C(6.54019884e-05)};
21 a_float den
[] = {A_FLOAT_C(-1.97530991), A_FLOAT_C(0.97530991)};
24 a_float tf_input
[A_LEN(num
)];
25 a_float tf_output
[A_LEN(den
)];
26 a_tf_init(&tf
, A_LEN(num
), num
, tf_input
, A_LEN(den
), den
, tf_output
);
29 ctx
.pid
.kp
= A_FLOAT_C(4.0);
30 ctx
.pid
.ki
= A_FLOAT_C(0.04);
31 ctx
.pid
.kd
= A_FLOAT_C(1.0);
32 ctx
.pid
.outmax
= +A_FLOAT_MAX
;
33 ctx
.pid
.outmin
= -A_FLOAT_MAX
;
34 ctx
.k
= A_FLOAT_C(4000.0);
35 ctx
.wp
= A_FLOAT_C(0.1);
36 ctx
.wi
= A_FLOAT_C(0.1);
37 ctx
.wd
= A_FLOAT_C(0.1);
38 a_pid_neuro_init(&ctx
);
39 for (unsigned int i
= 0; i
< 100; ++i
)
41 a_float
const in
= input(A_FLOAT_C(0.001) * a_float_c(i
));
42 a_tf_iter(&tf
, a_pid_neuro_inc(&ctx
, in
, *tf
.output
));
43 debug(A_FLOAT_PRI("+", "f,") A_FLOAT_PRI("+", "f,") A_FLOAT_PRI("+", "f,") A_FLOAT_PRI("+", "f\n"),
44 A_FLOAT_C(0.001) * a_float_c(i
), in
, *tf
.output
, ctx
.pid
.err
);
46 a_pid_neuro_zero(&ctx
);
49 #if defined(__cplusplus) && (__cplusplus > 201100L)
50 A_ASSERT_BUILD(std::is_pod
<a_pid_neuro
>::value
);
51 #endif /* __cplusplus */