2 * Copyright Droids Corporation, Microb Technology, Eirbot (2006)
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Revision : $Id: pid.h,v 1.4.4.7 2008-05-09 08:24:33 zer0 Exp $
28 #include <pid_config.h>
31 /** this is the pid_filter structure*/
34 int16_t gain_P; /**< Gain of Proportionnal module */
35 int16_t gain_I; /**< Gain of Integral module */
36 int16_t gain_D; /**< Gain of Derivate module */
38 uint8_t out_shift; /**< big common divisor for output */
40 uint8_t derivate_nb_samples; /**< sample count for derivate filter */
41 uint8_t index; /**< index in circular buffer below */
42 int32_t prev_samples[PID_DERIVATE_FILTER_MAX_SIZE]; /**< previous in (circular buf) */
44 int32_t max_in; /**< In saturation levels */
45 int32_t max_I; /**< Integral saturation levels */
46 int32_t max_out; /**< Out saturation levels */
48 int32_t integral; /**< previous integral parameter */
49 int32_t prev_D; /**< previous derivate parameter */
50 int32_t prev_out; /**< previous out command (for debug only) */
54 void pid_init(struct pid_filter *p);
56 /** reset state (derivate and intergral state) */
57 void pid_reset(struct pid_filter *p);
59 /* Use these functions to change one parameter on pid_filter structure */
60 void pid_set_gains(struct pid_filter *p, int16_t gp, int16_t gi, int16_t gd) ;
61 void pid_set_maximums(struct pid_filter *p, int32_t max_in, int32_t max_I, int32_t max_out);
62 void pid_set_out_shift(struct pid_filter *p, uint8_t out_shift);
63 int8_t pid_set_derivate_filter(struct pid_filter *p, uint8_t nb_samples);
65 /* accessors of all parameter of pid structure*/
66 int16_t pid_get_gain_P(struct pid_filter *p);
67 int16_t pid_get_gain_I(struct pid_filter *p);
68 int16_t pid_get_gain_D(struct pid_filter *p);
69 int32_t pid_get_max_in(struct pid_filter *p);
70 int32_t pid_get_max_I(struct pid_filter *p);
71 int32_t pid_get_max_out(struct pid_filter *p);
72 uint8_t pid_get_out_shift(struct pid_filter *p);
73 uint8_t pid_get_derivate_filter(struct pid_filter *p);
75 /** get the sum of all nput samples since the filter initialisation */
76 int32_t pid_get_value_I(struct pid_filter *p);
78 /** get previous input value */
79 int32_t pid_get_value_in(struct pid_filter *p);
81 /** get previous derivate value (without gain) */
82 int32_t pid_get_value_D(struct pid_filter *p);
84 /** get previous output value */
85 int32_t pid_get_value_out(struct pid_filter *p);
88 int32_t pid_do_filter(void *p, int32_t in);