update options for pip installation in README.md
[liba.git] / test / pid_neuro.h
blobad19a35191fe8641974431a54ea2b07ac384c27a
1 #define MAIN(x) pid_neuro##x
2 #include "test.h"
3 #include "a/tf.h"
4 // #include "a/math.h"
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);
11 #else
12 return (void)x, 1;
13 #endif
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)};
23 a_tf tf;
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);
28 a_pid_neuro ctx;
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);
47 a_tf_zero(&tf);
49 #if defined(__cplusplus) && (__cplusplus > 201100L)
50 A_ASSERT_BUILD(std::is_pod<a_pid_neuro>::value);
51 #endif /* __cplusplus */
53 return 0;