rename a_pid_fuzzy_equ to a_fuzzy_equ
[liba.git] / python / src / a / pid_fuzzy.pxi
blobe4eca3c6e7713c1cc12f531c8efcd5bdb267557e
1 from a cimport *
2 from a.fuzzy cimport *
3 from a.pid_fuzzy cimport *
5 cdef class pid_fuzzy:
6     CAP = A_PID_FUZZY_CAP
7     CAP_ALGEBRA = A_PID_FUZZY_CAP_ALGEBRA
8     CAP_BOUNDED = A_PID_FUZZY_CAP_BOUNDED
9     CUP = A_PID_FUZZY_CUP
10     CUP_ALGEBRA = A_PID_FUZZY_CUP_ALGEBRA
11     CUP_BOUNDED = A_PID_FUZZY_CUP_BOUNDED
12     EQU = A_PID_FUZZY_EQU
13     cdef a_pid_fuzzy ctx
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
19     def __init__(self):
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)
29         return self
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)
42         return self
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)
47         return self
48     def kpid(self, kp: a_float, ki: a_float, kd: a_float):
49         a_pid_fuzzy_kpid(&self.ctx, kp, ki, kd)
50         return self
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))
59     def zero(self):
60         a_pid_fuzzy_zero(&self.ctx)
61         return self
62     property block:
63         def __get__(self) -> int:
64             return self.ctx.block
65         def __set__(self, block: int):
66             self.set_block(block)
67     property kp:
68         def __get__(self) -> a_float:
69             return self.ctx.kp
70         def __set__(self, kp: a_float):
71             self.ctx.pid.kp = kp
72             self.ctx.kp = kp
73     property ki:
74         def __get__(self) -> a_float:
75             return self.ctx.ki
76         def __set__(self, ki: a_float):
77             self.ctx.pid.ki = ki
78             self.ctx.ki = ki
79     property kd:
80         def __get__(self) -> a_float:
81             return self.ctx.kd
82         def __set__(self, kd: a_float):
83             self.ctx.pid.kd = kd
84             self.ctx.kd = kd
85     property summax:
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
90     property summin:
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
95     property outmax:
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
100     property outmin:
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
105     property out:
106         def __get__(self) -> a_float:
107             return self.ctx.pid.out.f
108     property fdb:
109         def __get__(self) -> a_float:
110             return self.ctx.pid.fdb.f
111     property err:
112         def __get__(self) -> a_float:
113             return self.ctx.pid.err.f
114     property order:
115         def __get__(self) -> int:
116             return self.ctx.order