00001 /* 00002 * Copyright Droids Corporation, Microb Technology, Eirbot (2006) 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Revision : $Id: pid.h,v 1.8 2008-05-14 13:27:12 zer0 Exp $ 00019 * 00020 */ 00021 00022 #ifndef _PID_H_ 00023 #define _PID_H_ 00024 00025 #include <aversive.h> 00026 #include <stdlib.h> 00027 00028 #include <pid_config.h> 00029 00030 00032 struct pid_filter 00033 { 00034 int16_t gain_P; 00035 int16_t gain_I; 00036 int16_t gain_D; 00038 uint8_t out_shift; 00040 uint8_t derivate_nb_samples; 00041 uint8_t index; 00042 int32_t prev_samples[PID_DERIVATE_FILTER_MAX_SIZE]; 00044 int32_t max_in; 00045 int32_t max_I; 00046 int32_t max_out; 00048 int32_t integral; 00049 int32_t prev_D; 00050 int32_t prev_out; 00051 }; 00052 00054 void pid_init(struct pid_filter *p); 00055 00057 void pid_reset(struct pid_filter *p); 00058 00059 /* Use these functions to change one parameter on pid_filter structure */ 00060 void pid_set_gains(struct pid_filter *p, int16_t gp, int16_t gi, int16_t gd) ; 00061 void pid_set_maximums(struct pid_filter *p, int32_t max_in, int32_t max_I, int32_t max_out); 00062 void pid_set_out_shift(struct pid_filter *p, uint8_t out_shift); 00063 int8_t pid_set_derivate_filter(struct pid_filter *p, uint8_t nb_samples); 00064 00065 /* accessors of all parameter of pid structure*/ 00066 int16_t pid_get_gain_P(struct pid_filter *p); 00067 int16_t pid_get_gain_I(struct pid_filter *p); 00068 int16_t pid_get_gain_D(struct pid_filter *p); 00069 int32_t pid_get_max_in(struct pid_filter *p); 00070 int32_t pid_get_max_I(struct pid_filter *p); 00071 int32_t pid_get_max_out(struct pid_filter *p); 00072 uint8_t pid_get_out_shift(struct pid_filter *p); 00073 uint8_t pid_get_derivate_filter(struct pid_filter *p); 00074 00076 int32_t pid_get_value_I(struct pid_filter *p); 00077 00079 int32_t pid_get_value_in(struct pid_filter *p); 00080 00082 int32_t pid_get_value_D(struct pid_filter *p); 00083 00085 int32_t pid_get_value_out(struct pid_filter *p); 00086 00088 int32_t pid_do_filter(void *p, int32_t in); 00089 00090 00091 #endif