rearrange fields and export the read-only variable `sum`
[liba.git] / python / src / a / pid_fuzzy.pxi
blobe4a7a630d7895821bb3ddff73f68fc0fe95e022f
1 from a cimport *
2 from a.pid_fuzzy cimport *
4 cdef class pid_fuzzy:
5     CAP = A_PID_FUZZY_CAP
6     CAP_ALGEBRA = A_PID_FUZZY_CAP_ALGEBRA
7     CAP_BOUNDED = A_PID_FUZZY_CAP_BOUNDED
8     CUP = A_PID_FUZZY_CUP
9     CUP_ALGEBRA = A_PID_FUZZY_CUP_ALGEBRA
10     CUP_BOUNDED = A_PID_FUZZY_CUP_BOUNDED
11     EQU = A_PID_FUZZY_EQU
12     cdef a_pid_fuzzy ctx
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
18     def __init__(self):
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)
28         return self
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)
41         return self
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)
46         return self
47     def kpid(self, a_float kp, a_float ki, a_float kd):
48         a_pid_fuzzy_kpid(&self.ctx, kp, ki, kd)
49         return self
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))
58     def zero(self):
59         a_pid_fuzzy_zero(&self.ctx)
60         return self
61     property kp:
62         def __get__(self):
63             return self.ctx.kp
64         def __set__(self, a_float kp):
65             self.ctx.pid.kp = kp
66             self.ctx.kp = kp
67     property ki:
68         def __get__(self):
69             return self.ctx.ki
70         def __set__(self, a_float ki):
71             self.ctx.pid.ki = ki
72             self.ctx.ki = ki
73     property kd:
74         def __get__(self):
75             return self.ctx.kd
76         def __set__(self, a_float kd):
77             self.ctx.pid.kd = kd
78             self.ctx.kd = kd
79     property summax:
80         def __get__(self):
81             return self.ctx.pid.summax
82         def __set__(self, a_float summax):
83             self.ctx.pid.summax = summax
84     property summin:
85         def __get__(self):
86             return self.ctx.pid.summin
87         def __set__(self, a_float summin):
88             self.ctx.pid.summin = summin
89     property sum:
90         def __get__(self):
91             return self.ctx.pid.sum
92     property outmax:
93         def __get__(self):
94             return self.ctx.pid.outmax
95         def __set__(self, a_float outmax):
96             self.ctx.pid.outmax = outmax
97     property outmin:
98         def __get__(self):
99             return self.ctx.pid.outmin
100         def __set__(self, a_float outmin):
101             self.ctx.pid.outmin = outmin
102     property out:
103         def __get__(self):
104             return self.ctx.pid.out
105     property fdb:
106         def __get__(self):
107             return self.ctx.pid.fdb
108     property err:
109         def __get__(self):
110             return self.ctx.pid.err
111     property order:
112         def __get__(self):
113             return self.ctx.order
114     property block:
115         def __get__(self):
116             return self.ctx.block
117         def __set__(self, unsigned int block):
118             self.set_block(block)