3 from a.pid_fuzzy cimport *
7 CAP_ALGEBRA = A_PID_FUZZY_CAP_ALGEBRA
8 CAP_BOUNDED = A_PID_FUZZY_CAP_BOUNDED
10 CUP_ALGEBRA = A_PID_FUZZY_CUP_ALGEBRA
11 CUP_BOUNDED = A_PID_FUZZY_CUP_BOUNDED
14 cdef readonly array me
15 cdef readonly array mec
16 cdef readonly array mkp
17 cdef readonly array mki
18 cdef readonly array mkd
20 self.ctx.pid.summax = +A_FLOAT_INF
21 self.ctx.pid.summin = -A_FLOAT_INF
22 self.ctx.pid.outmax = +A_FLOAT_INF
23 self.ctx.pid.outmin = -A_FLOAT_INF
24 self.ctx.kp = self.ctx.pid.kp = 1
25 self.ctx.op = a_fuzzy_equ
26 a_pid_fuzzy_init(&self.ctx)
27 def op(self, op: int):
28 a_pid_fuzzy_set_op(&self.ctx, op)
30 def rule(self, me, mec, mkp, mki, mkd):
31 self.me = array_num((_2 for _1 in me for _2 in _1))
32 self.mec = array_num((_2 for _1 in mec for _2 in _1))
33 self.mkp = array_num((_2 for _1 in mkp for _2 in _1))
34 self.mki = array_num((_2 for _1 in mki for _2 in _1))
35 self.mkd = array_num((_2 for _1 in mkd for _2 in _1))
36 a_pid_fuzzy_rule(&self.ctx, <unsigned int>len(me),
37 <a_float *>self.me.data.as_voidptr,
38 <a_float *>self.mec.data.as_voidptr,
39 <a_float *>self.mkp.data.as_voidptr,
40 <a_float *>self.mki.data.as_voidptr,
41 <a_float *>self.mkd.data.as_voidptr)
43 def set_block(self, num: int):
44 cdef void *ptr = a_pid_fuzzy_block(&self.ctx);
45 ptr = PyMem_Realloc(ptr, A_PID_FUZZY_BLOCK(num))
46 a_pid_fuzzy_set_block(&self.ctx, ptr, num)
48 def kpid(self, kp: a_float, ki: a_float, kd: a_float):
49 a_pid_fuzzy_kpid(&self.ctx, kp, ki, kd)
51 def run(self, set: a_float, fdb: a_float) -> a_float:
52 return a_pid_fuzzy_run(&self.ctx, set, fdb)
53 def pos(self, set: a_float, fdb: a_float) -> a_float:
54 return a_pid_fuzzy_pos(&self.ctx, set, fdb)
55 def inc(self, set: a_float, fdb: a_float) -> a_float:
56 return a_pid_fuzzy_inc(&self.ctx, set, fdb)
57 def __dealloc__(self):
58 PyMem_Free(a_pid_fuzzy_block(&self.ctx))
60 a_pid_fuzzy_zero(&self.ctx)
63 def __get__(self) -> int:
65 def __set__(self, block: int):
68 def __get__(self) -> a_float:
70 def __set__(self, kp: a_float):
74 def __get__(self) -> a_float:
76 def __set__(self, ki: a_float):
80 def __get__(self) -> a_float:
82 def __set__(self, kd: a_float):
86 def __get__(self) -> a_float:
87 return self.ctx.pid.summax
88 def __set__(self, summax: a_float):
89 self.ctx.pid.summax = summax
91 def __get__(self) -> a_float:
92 return self.ctx.pid.summin
93 def __set__(self, summin: a_float):
94 self.ctx.pid.summin = summin
96 def __get__(self) -> a_float:
97 return self.ctx.pid.outmax
98 def __set__(self, outmax: a_float):
99 self.ctx.pid.outmax = outmax
101 def __get__(self) -> a_float:
102 return self.ctx.pid.outmin
103 def __set__(self, outmin: a_float):
104 self.ctx.pid.outmin = outmin
106 def __get__(self) -> a_float:
107 return self.ctx.pid.out.f
109 def __get__(self) -> a_float:
110 return self.ctx.pid.fdb.f
112 def __get__(self) -> a_float:
113 return self.ctx.pid.err.f
115 def __get__(self) -> int:
116 return self.ctx.order