1 #define MAIN(x) pid_fuzzy##x
6 #include "a/pid_fuzzy.h"
8 static A_INLINE a_float
input(a_float
const x
)
10 #if defined(LIBA_MATH_H)
11 return a_float_sin(4 * A_FLOAT_PI
* x
);
22 static a_float
const m3e
[] = {
28 static a_float
const m3ec
[] = {
33 #define X A_FLOAT_C(5.0)
34 static a_float
const m3kp
[] = {
39 #define X A_FLOAT_C(0.01)
40 static a_float
const m3ki
[] = {
45 #define X A_FLOAT_C(0.1)
46 static a_float
const m3kd
[] = {
67 #define X A_FLOAT_C(1.0) / 2
68 static a_float
const m7e
[] = {
75 A_MF_TRI
, PM
, PL
, PL
};
77 #define X A_FLOAT_C(1.0) / 2
78 static a_float
const m7ec
[] = {
85 A_MF_TRI
, PM
, PL
, PL
};
87 #define X A_FLOAT_C(500.0) / 6
88 static a_float
const m7kp
[] = {
89 NL
, NL
, NM
, NM
, NS
, ZO
, ZO
,
90 NL
, NL
, NM
, NS
, NS
, ZO
, PS
,
91 NM
, NM
, NM
, NS
, ZO
, PS
, PS
,
92 NM
, NM
, NS
, ZO
, PS
, PM
, PM
,
93 NS
, NS
, ZO
, PS
, PS
, PM
, PM
,
94 NS
, ZO
, PS
, PM
, PM
, PM
, PL
,
95 ZO
, ZO
, PM
, PM
, PM
, PL
, PL
};
97 #define X A_FLOAT_C(10.0) / 3
98 static a_float
const m7ki
[] = {
99 PL
, PL
, PM
, PM
, PS
, ZO
, ZO
,
100 PL
, PL
, PM
, PS
, PS
, ZO
, ZO
,
101 PL
, PM
, PS
, PS
, ZO
, NS
, NS
,
102 PM
, PM
, PS
, ZO
, NS
, NM
, NM
,
103 PM
, PS
, ZO
, NS
, NS
, NM
, NL
,
104 ZO
, ZO
, NS
, NS
, NM
, NL
, NL
,
105 ZO
, ZO
, NS
, NM
, NM
, NL
, NL
};
107 #define X A_FLOAT_C(5000.0) / 3
108 static a_float
const m7kd
[] = {
109 NS
, PS
, PL
, PL
, PL
, PM
, NS
,
110 NS
, PS
, PL
, PM
, PM
, PS
, ZO
,
111 ZO
, PS
, PM
, PM
, PS
, PS
, ZO
,
112 ZO
, PS
, PS
, PS
, PS
, PS
, ZO
,
113 ZO
, ZO
, ZO
, ZO
, ZO
, ZO
, ZO
,
114 NL
, NS
, NS
, NS
, NS
, NS
, NL
,
115 NL
, NM
, NM
, NM
, NS
, NS
, NL
};
118 int main(int argc
, char *argv
[]) // NOLINT(misc-definitions-in-headers)
120 main_init(argc
, argv
, 1);
122 a_float num
[] = {A_FLOAT_C(6.59492796e-05), A_FLOAT_C(6.54019884e-05)};
123 a_float den
[] = {A_FLOAT_C(-1.97530991), A_FLOAT_C(0.97530991)};
126 a_float pos_input
[A_LEN(num
)];
127 a_float pos_output
[A_LEN(den
)];
128 a_tf_init(&pos_tf
, A_LEN(num
), num
, pos_input
, A_LEN(den
), den
, pos_output
);
130 a_float inc_input
[A_LEN(num
)];
131 a_float inc_output
[A_LEN(den
)];
132 a_tf_init(&inc_tf
, A_LEN(num
), num
, inc_input
, A_LEN(den
), den
, inc_output
);
135 pos_pid
.pid
.summax
= +10;
136 pos_pid
.pid
.summin
= -10;
137 pos_pid
.pid
.outmax
= +10;
138 pos_pid
.pid
.outmin
= -10;
151 pos_pid
.op
= a_pid_fuzzy_op(A_PID_FUZZY_EQU
);
152 a_pid_fuzzy_init(&pos_pid
);
153 a_byte pos_block
[A_PID_FUZZY_BLOCK(2)];
154 a_pid_fuzzy_set_block(&pos_pid
, pos_block
, 2);
156 inc_pid
.pid
.outmax
= +10;
157 inc_pid
.pid
.outmin
= -10;
170 inc_pid
.op
= a_pid_fuzzy_op(A_PID_FUZZY_EQU
);
171 a_pid_fuzzy_init(&inc_pid
);
172 a_byte inc_block
[A_PID_FUZZY_BLOCK(2)];
173 a_pid_fuzzy_set_block(&inc_pid
, inc_block
, 2);
175 a_pid_fuzzy_kpid(&pos_pid
, 600, A_FLOAT_C(20.0), A_FLOAT_C(6000.0));
176 a_pid_fuzzy_kpid(&inc_pid
, 600, A_FLOAT_C(20.0), A_FLOAT_C(6000.0));
177 for (unsigned int i
= 0; i
< 200; ++i
)
179 a_float in
= input(A_FLOAT_C(0.001) * a_float_c(i
));
180 a_tf_iter(&pos_tf
, a_pid_fuzzy_pos(&pos_pid
, in
, *pos_tf
.output
));
181 a_tf_iter(&inc_tf
, a_pid_fuzzy_inc(&inc_pid
, in
, *inc_tf
.output
));
182 debug(A_FLOAT_PRI("+", "f,") A_FLOAT_PRI("+", "f,") A_FLOAT_PRI("+", "f,") A_FLOAT_PRI("+", "f\n"),
183 A_FLOAT_C(0.001) * a_float_c(i
), in
, *pos_tf
.output
, *inc_tf
.output
);
185 a_pid_fuzzy_zero(&pos_pid
);
186 a_pid_fuzzy_zero(&inc_pid
);
190 #if defined(__cplusplus) && (__cplusplus > 201100L)
191 A_ASSERT_BUILD(std::is_pod
<a_pid_fuzzy
>::value
);
192 #endif /* __cplusplus */