3 @brief fuzzy proportional integral derivative controller
6 #ifndef LIBA_PID_FUZZY_H
7 #define LIBA_PID_FUZZY_H
14 @addtogroup A_PID_FUZZY fuzzy proportional integral derivative controller
18 typedef struct a_pid_fuzzy a_pid_fuzzy
;
21 @brief enumeration for fuzzy PID controller operator
25 A_PID_FUZZY_EQU
, //!< sqrt(a,b)*sqrt(1-(1-a)*(1-b))
26 A_PID_FUZZY_CAP
, //!< min(a,b)
27 A_PID_FUZZY_CAP_ALGEBRA
, //!< a*b
28 A_PID_FUZZY_CAP_BOUNDED
, //!< max(a+b-1,0)
29 A_PID_FUZZY_CUP
, //!< max(a,b)
30 A_PID_FUZZY_CUP_ALGEBRA
, //!< a+b-a*b
31 A_PID_FUZZY_CUP_BOUNDED
//!< min(a+b,1)
34 #if defined(__cplusplus)
36 #endif /* __cplusplus */
39 @brief initialize for fuzzy PID controller
40 @param[in,out] ctx points to an instance of fuzzy PID controller
42 #define a_pid_fuzzy_init(ctx) a_pid_fuzzy_zero(ctx)
45 @brief get fuzzy relational operator for fuzzy PID controller
46 @param[in] op enumeration for fuzzy PID controller operator
47 @return fuzzy relational operator for fuzzy PID controller
49 A_EXTERN
a_float (*a_pid_fuzzy_op(unsigned int op
))(a_float
, a_float
);
52 @brief set fuzzy relational operator for fuzzy PID controller
53 @param[in,out] ctx points to an instance of fuzzy PID controller
54 @param[in] op enumeration for fuzzy PID controller operator
56 A_EXTERN
void a_pid_fuzzy_set_op(a_pid_fuzzy
*ctx
, unsigned int op
);
59 @brief set rule base for fuzzy PID controller
60 @param[in,out] ctx points to an instance of fuzzy PID controller
61 @param[in] order number of order in the square matrix
62 @param[in] me points to e's membership function parameter table
63 @param[in] mec points to ec's membership function parameter table
64 @param[in] mkp points to Kp's rule base table which must be a square matrix
65 @param[in] mki points to Ki's rule base table which must be a square matrix
66 @param[in] mkd points to Kd's rule base table which must be a square matrix
68 A_EXTERN
void a_pid_fuzzy_rule(a_pid_fuzzy
*ctx
, unsigned int order
, a_float
const *me
, a_float
const *mec
,
69 a_float
const *mkp
, a_float
const *mki
, a_float
const *mkd
);
72 @brief compute size of memory block for fuzzy PID controller
73 @param[in] n the maximum number triggered by the rule
75 #define A_PID_FUZZY_BLOCK(n) (sizeof(unsigned int) * (n) * 2 + sizeof(a_float) * (n) * (2 + (n)))
78 @brief set memory block for fuzzy PID controller
79 @param[in,out] ctx points to an instance of fuzzy PID controller
80 @param[in] ptr points to a buffer at least A_PID_FUZZY_BLOCK(num)
81 @param[in] num the maximum number triggered by the rule
83 A_EXTERN
void a_pid_fuzzy_set_block(a_pid_fuzzy
*ctx
, void *ptr
, a_size num
);
86 @brief get memory block for fuzzy PID controller
87 @param[in,out] ctx points to an instance of fuzzy PID controller
88 @return memory block for fuzzy PID controller
90 A_EXTERN
void *a_pid_fuzzy_block(a_pid_fuzzy
*ctx
);
93 @brief set proportional integral derivative constant for fuzzy PID controller
94 @param[in,out] ctx points to an instance of fuzzy PID controller
95 @param[in] kp proportional constant
96 @param[in] ki integral constant
97 @param[in] kd derivative constant
99 A_EXTERN
void a_pid_fuzzy_kpid(a_pid_fuzzy
*ctx
, a_float kp
, a_float ki
, a_float kd
);
102 @brief calculate for fuzzy PID controller
103 @param[in,out] ctx points to an instance of fuzzy PID controller
104 @param[in] set setpoint value
105 @param[in] fdb feedback value
106 @return setpoint value
108 A_EXTERN a_float
a_pid_fuzzy_run(a_pid_fuzzy
*ctx
, a_float set
, a_float fdb
);
111 @brief calculate for positional fuzzy PID controller
112 @param[in,out] ctx points to an instance of fuzzy PID controller
113 @param[in] set setpoint value
114 @param[in] fdb feedback value
117 A_EXTERN a_float
a_pid_fuzzy_pos(a_pid_fuzzy
*ctx
, a_float set
, a_float fdb
);
120 @brief calculate for incremental fuzzy PID controller
121 @param[in,out] ctx points to an instance of fuzzy PID controller
122 @param[in] set setpoint value
123 @param[in] fdb feedback value
126 A_EXTERN a_float
a_pid_fuzzy_inc(a_pid_fuzzy
*ctx
, a_float set
, a_float fdb
);
129 @brief zeroing for fuzzy PID controller
130 @param[in,out] ctx points to an instance of fuzzy PID controller
132 A_EXTERN
void a_pid_fuzzy_zero(a_pid_fuzzy
*ctx
);
134 #if defined(__cplusplus)
138 typedef struct a_pid_fuzzy pid_fuzzy
;
140 #endif /* __cplusplus */
143 @brief instance structure for fuzzy PID controller
147 a_pid pid
; //!< instance structure for PID controller
149 a_float
const *me
; //!< points to e's membership function parameter table
150 a_float
const *mec
; //!< points to ec's membership function parameter table
151 a_float
const *mkp
; //!< points to Kp's rule base, which must be a square matrix
152 a_float
const *mki
; //!< points to Ki's rule base, which must be a square matrix
153 a_float
const *mkd
; //!< points to Kd's rule base, which must be a square matrix
155 unsigned int *idx
; //!< the memory block for membership index, >= 2N
156 a_float
*val
; //!< the memory block for membership value and membership outer product of e and ec, >= (2+N)N
158 a_float (*op
)(a_float
, a_float
); //!< fuzzy relational operator
160 a_float kp
; //!< base proportional constant
161 a_float ki
; //!< base integral constant
162 a_float kd
; //!< base derivative constant
164 unsigned int order
; //!< number of order in the square matrix
165 unsigned int block
; //!< maximum number triggered by the rule
166 #if defined(__cplusplus)
167 A_INLINE
void init() { a_pid_fuzzy_init(this); }
168 A_INLINE
void set_op(unsigned int _op
)
170 a_pid_fuzzy_set_op(this, _op
);
172 A_INLINE
void set_block(void *ptr
, a_size num
)
174 a_pid_fuzzy_set_block(this, ptr
, num
);
176 A_INLINE
void rule(unsigned int _order
, a_float
const *_me
, a_float
const *_mec
,
177 a_float
const *_mkp
, a_float
const *_mki
, a_float
const *_mkd
)
179 a_pid_fuzzy_rule(this, _order
, _me
, _mec
, _mkp
, _mki
, _mkd
);
181 A_INLINE
void kpid(a_float _kp
, a_float _ki
, a_float _kd
)
183 a_pid_fuzzy_kpid(this, _kp
, _ki
, _kd
);
185 A_INLINE a_float
run(a_float set
, a_float fdb
)
187 return a_pid_fuzzy_run(this, set
, fdb
);
189 A_INLINE a_float
pos(a_float set
, a_float fdb
)
191 return a_pid_fuzzy_pos(this, set
, fdb
);
193 A_INLINE a_float
inc(a_float set
, a_float fdb
)
195 return a_pid_fuzzy_inc(this, set
, fdb
);
197 A_INLINE
void zero() { a_pid_fuzzy_zero(this); }
198 #endif /* __cplusplus */
201 /*! @} A_PID_FUZZY */
203 #endif /* a/pid_fuzzy.h */