2 * Copyright Droids Corporation (2010)
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: actuator.c,v 1.4 2009-04-24 19:30:41 zer0 Exp $
23 #include <aversive/pgmspace.h>
24 #include <aversive/wait.h>
25 #include <aversive/error.h>
30 #include <encoders_spi.h>
33 #include <scheduler.h>
34 #include <clock_time.h>
38 #include <control_system_manager.h>
39 #include <blocking_detection_manager.h>
46 #define SHOVEL_DOWN 100
47 #define SHOVEL_MID 4500
48 #define SHOVEL_UP 11000
49 #define SHOVEL_KICKSTAND 12800
51 static int32_t shovel_k1 = 1000;
52 static int32_t shovel_k2 = 20;
53 static uint8_t shovel_current_limit = 1;
55 /* init spickle position at beginning */
56 static void shovel_autopos(void)
58 printf_P(PSTR("shovel autopos..."));
59 pwm_ng_set(SHOVEL_PWM, -500);
61 pwm_ng_set(LEFT_SPICKLE_PWM, 0);
62 encoders_spi_set_value(SHOVEL_ENCODER, 0);
63 printf_P(PSTR("ok\r\n"));
66 static uint8_t shovel_is_at_pos(int32_t pos)
69 diff = pos - encoders_spi_get_value(SHOVEL_ENCODER);
77 void shovel_set_current_limit_coefs(int32_t k1, int32_t k2)
83 uint8_t shovel_get_current_limit_coefs(int32_t *k1, int32_t *k2)
87 return shovel_current_limit;
90 void shovel_current_limit_enable(uint8_t enable)
92 shovel_current_limit = enable;
95 /* Set CS command for shovel. Called by CS manager. */
96 void shovel_set(void *mot, int32_t cmd)
98 static int32_t oldpos;
99 int32_t pos, maxcmd, speed;
101 pos = encoders_spi_get_value(SHOVEL_ENCODER);
102 if (shovel_current_limit) {
103 speed = pos - oldpos;
104 if (speed > 0 && cmd < 0)
106 else if (speed < 0 && cmd > 0)
110 maxcmd = shovel_k1 + shovel_k2 * speed;
114 else if (cmd < -maxcmd)
118 pwm_ng_set(mot, cmd);
122 void shovel_down(void)
124 quadramp_set_1st_order_vars(&cobboard.shovel.qr, 2500, 2500);
125 quadramp_set_2nd_order_vars(&cobboard.shovel.qr, 50, 80);
126 cs_set_consign(&cobboard.shovel.cs, SHOVEL_DOWN);
129 void shovel_mid(void)
131 quadramp_set_1st_order_vars(&cobboard.shovel.qr, 2500, 2500);
132 quadramp_set_2nd_order_vars(&cobboard.shovel.qr, 80, 80);
133 cs_set_consign(&cobboard.shovel.cs, SHOVEL_MID);
138 if (state_get_cob_count() <= 1)
139 quadramp_set_1st_order_vars(&cobboard.shovel.qr, 1000, 2500);
141 quadramp_set_1st_order_vars(&cobboard.shovel.qr, 2000, 2500);
142 quadramp_set_2nd_order_vars(&cobboard.shovel.qr, 80, 15);
143 cs_set_consign(&cobboard.shovel.cs, SHOVEL_UP);
146 void shovel_kickstand(void)
148 quadramp_set_1st_order_vars(&cobboard.shovel.qr, 200, 200);
149 quadramp_set_2nd_order_vars(&cobboard.shovel.qr, 10, 10);
150 cs_set_consign(&cobboard.shovel.cs, SHOVEL_KICKSTAND);
153 uint8_t shovel_is_up(void)
155 return shovel_is_at_pos(SHOVEL_UP);
158 uint8_t shovel_is_down(void)
160 return shovel_is_at_pos(SHOVEL_DOWN);
163 void shovel_init(void)
166 cobboard.shovel.on = 1;