ini
[aversive.git] / modules / devices / control_system / filters / pid / test / main.c
1 /*  
2  *  Copyright Droids Corporation, Microb Technology, Eirbot (2005)
3  * 
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.
8  *
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.
13  *
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
17  *
18  *  Revision : $Id: main.c,v 1.4.6.3 2007-12-05 18:08:40 zer0 Exp $
19  *
20  */
21
22 #include <stdio.h>
23
24 #include <pid.h>
25
26 int32_t tab[] = { 0, 1, 2, 5, 6, 0, 0, 1, 0, 0, -10, -8, -5, -1 };
27
28 int main(void)
29 {
30         struct pid_filter p;
31         int32_t val;
32         int i;
33
34         pid_init(&p);
35         pid_set_gains(&p, 1000, 30, 5000);
36         pid_set_maximums(&p, 0, 50000, 4095);
37         pid_set_out_shift(&p, 10);
38         pid_set_derivate_filter(&p, 4);
39
40         for (i=0; i < (sizeof(tab)/sizeof(int32_t)); i++) {
41                 val = pid_do_filter(&p, tab[i]);
42                 printf("in  = %" PRId32 "\n", tab[i]);
43                 printf("out = %" PRId32 "\n", val);
44                 printf("I   = %" PRId32 "\n", p.integral);
45                 printf("D   = %" PRId32 "\n\n", p.prev_D);
46         }
47
48         return 0;
49 }
50
51