ini
[aversive.git] / projects / microb2009 / mainboard / actuator.c
1 /*  
2  *  Copyright Droids Corporation (2009)
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: actuator.c,v 1.3 2009-05-02 10:08:09 zer0 Exp $
19  *
20  */
21
22 #include <aversive.h>
23 #include <aversive/pgmspace.h>
24 #include <aversive/wait.h>
25 #include <aversive/error.h>
26
27 #include <ax12.h>
28 #include <uart.h>
29 #include <spi.h>
30 #include <encoders_spi.h>
31 #include <pwm_ng.h>
32 #include <timer.h>
33 #include <scheduler.h>
34 #include <time.h>
35
36 #include <pid.h>
37 #include <quadramp.h>
38 #include <control_system_manager.h>
39 #include <trajectory_manager.h>
40 #include <vect_base.h>
41 #include <lines.h>
42 #include <polygon.h>
43 #include <obstacle_avoidance.h>
44 #include <blocking_detection_manager.h>
45 #include <robot_system.h>
46 #include <position_manager.h>
47
48 #include <rdline.h>
49
50 #include "main.h"
51
52 void pwm_set_and_save(void *pwm, int32_t val)
53 {
54         /* we need to do the saturation here, before saving the
55          * value */
56         if (val > 4095)
57                 val = 4095;
58         if (val < -4095)
59                 val = -4095;
60         
61         if (pwm == LEFT_PWM)
62                 mainboard.pwm_l = val;
63         else if (pwm == RIGHT_PWM)
64                 mainboard.pwm_r = val;
65         pwm_ng_set(pwm, val);
66 }
67
68 void pickup_wheels_on(void)
69 {
70         mainboard.enable_pickup_wheels = 1;
71 }
72
73 void pickup_wheels_off(void)
74 {
75         mainboard.enable_pickup_wheels = 0;
76 }
77