2 from a.pid_fuzzy cimport *
6 CAP_ALGEBRA = A_PID_FUZZY_CAP_ALGEBRA
7 CAP_BOUNDED = A_PID_FUZZY_CAP_BOUNDED
9 CUP_ALGEBRA = A_PID_FUZZY_CUP_ALGEBRA
10 CUP_BOUNDED = A_PID_FUZZY_CUP_BOUNDED
13 cdef readonly array me
14 cdef readonly array mec
15 cdef readonly array mkp
16 cdef readonly array mki
17 cdef readonly array mkd
19 self.ctx.pid.summax = +A_FLOAT_INF
20 self.ctx.pid.summin = -A_FLOAT_INF
21 self.ctx.pid.outmax = +A_FLOAT_INF
22 self.ctx.pid.outmin = -A_FLOAT_INF
23 self.ctx.kp = self.ctx.pid.kp = 1
24 self.ctx.op = a_fuzzy_equ
25 a_pid_fuzzy_init(&self.ctx)
26 def op(self, unsigned int op):
27 a_pid_fuzzy_set_op(&self.ctx, op)
29 def rule(self, me, mec, mkp, mki, mkd):
30 self.me = array_num((_2 for _1 in me for _2 in _1))
31 self.mec = array_num((_2 for _1 in mec for _2 in _1))
32 self.mkp = array_num((_2 for _1 in mkp for _2 in _1))
33 self.mki = array_num((_2 for _1 in mki for _2 in _1))
34 self.mkd = array_num((_2 for _1 in mkd for _2 in _1))
35 a_pid_fuzzy_rule(&self.ctx, <unsigned int>len(me),
36 <a_float *>self.me.data.as_voidptr,
37 <a_float *>self.mec.data.as_voidptr,
38 <a_float *>self.mkp.data.as_voidptr,
39 <a_float *>self.mki.data.as_voidptr,
40 <a_float *>self.mkd.data.as_voidptr)
42 def set_block(self, unsigned int num):
43 cdef void *ptr = a_pid_fuzzy_block(&self.ctx)
44 ptr = PyMem_Realloc(ptr, A_PID_FUZZY_BLOCK(num))
45 a_pid_fuzzy_set_block(&self.ctx, ptr, num)
47 def kpid(self, a_float kp, a_float ki, a_float kd):
48 a_pid_fuzzy_kpid(&self.ctx, kp, ki, kd)
50 def run(self, a_float set, a_float fdb):
51 return a_pid_fuzzy_run(&self.ctx, set, fdb)
52 def pos(self, a_float set, a_float fdb):
53 return a_pid_fuzzy_pos(&self.ctx, set, fdb)
54 def inc(self, a_float set, a_float fdb):
55 return a_pid_fuzzy_inc(&self.ctx, set, fdb)
56 def __dealloc__(self):
57 PyMem_Free(a_pid_fuzzy_block(&self.ctx))
59 a_pid_fuzzy_zero(&self.ctx)
64 def __set__(self, a_float kp):
70 def __set__(self, a_float ki):
76 def __set__(self, a_float kd):
81 return self.ctx.pid.summax
82 def __set__(self, a_float summax):
83 self.ctx.pid.summax = summax
86 return self.ctx.pid.summin
87 def __set__(self, a_float summin):
88 self.ctx.pid.summin = summin
91 return self.ctx.pid.sum
94 return self.ctx.pid.outmax
95 def __set__(self, a_float outmax):
96 self.ctx.pid.outmax = outmax
99 return self.ctx.pid.outmin
100 def __set__(self, a_float outmin):
101 self.ctx.pid.outmin = outmin
104 return self.ctx.pid.out
107 return self.ctx.pid.fdb
110 return self.ctx.pid.err
113 return self.ctx.order
116 return self.ctx.block
117 def __set__(self, unsigned int block):
118 self.set_block(block)