vt100: include pgmspace.h as we use PROGMEM macro
[aversive.git] / modules / devices / control_system / control_system_manager / 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.4.2 2007-05-23 17:18:13 zer0 Exp $
19  *
20  */
21
22 #include <stdio.h>
23
24 #include <uart.h>
25 #include <aversive/wait.h>
26 #include <pid.h>
27 #include <quadramp.h>
28 #include <control_system_manager.h>
29
30 #ifdef HOST_VERSION
31 #include <hostsim.h>
32 #endif
33
34 #define MAX_SPEED 10000
35 static int32_t motor_speed=0;
36 static int32_t motor_pos=0;
37
38 /* try to simulate a motor (quick and dirty and wrong) */
39 void motor_set(void * dummy, int32_t in)
40 {
41     motor_speed = motor_speed - motor_speed/8 ;
42     motor_speed += in/8;
43 }
44
45 int32_t motor_get_pos(void * dummy)
46 {
47     motor_pos += motor_speed;
48     return motor_pos;
49 }
50     
51 int main(void)
52 {
53     struct cs my_cs;
54     struct pid_filter my_pid;
55     struct quadramp_filter my_qr;
56     uint16_t i ;
57
58     uart_init();
59
60     pid_init(&my_pid);
61     pid_set_gains(&my_pid, 40, 1, 3);
62     pid_set_maximums(&my_pid, 0, 5000, 4095); 
63     pid_set_out_shift(&my_pid, 10);
64   
65     quadramp_init(&my_qr);
66     quadramp_set_1st_order_vars(&my_qr, 1000, 1000); /* set speed */
67     quadramp_set_2nd_order_vars(&my_qr, 100, 100); /* set accel */
68   
69     cs_init(&my_cs);
70     cs_set_consign_filter(&my_cs, quadramp_do_filter, &my_qr);   
71     cs_set_correct_filter(&my_cs, pid_do_filter, &my_pid); 
72     cs_set_process_in(&my_cs, motor_set, NULL);
73     cs_set_process_out(&my_cs, motor_get_pos, NULL);
74     cs_set_consign(&my_cs, 0);
75   
76     for ( i=0 ; i<10 ; i++) {
77         wait_ms(10);
78         cs_manage(&my_cs);
79     }
80         
81     cs_set_consign(&my_cs, 100000);   
82     
83     while(1) {
84         wait_ms(10);
85         cs_manage(&my_cs);
86     }
87
88     return 0;
89 }
90
91