2 * Copyright Droids, Microb Technology (2009)
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: strat.c,v 1.6 2009-11-08 17:24:33 zer0 Exp $
20 * Olivier MATZ <zer0@droids-corp.org>
28 #include <aversive/pgmspace.h>
29 #include <aversive/queue.h>
30 #include <aversive/wait.h>
31 #include <aversive/error.h>
36 #include <clock_time.h>
41 #include <control_system_manager.h>
42 #include <trajectory_manager.h>
43 #include <vect_base.h>
46 #include <obstacle_avoidance.h>
47 #include <blocking_detection_manager.h>
48 #include <robot_system.h>
49 #include <position_manager.h>
51 #include <diagnostic.h>
56 #include "../common/i2c_commands.h"
57 #include "i2c_protocol.h"
61 #include "strat_base.h"
62 #include "strat_corn.h"
63 #include "strat_utils.h"
67 #define COL_DISP_MARGIN 400 /* stop 40 cm in front of dispenser */
68 #define COL_SCAN_PRE_MARGIN 250
70 struct strat_conf strat_conf;
72 /*************************************************************/
76 /*************************************************************/
78 /* called before each strat, and before the start switch */
79 void strat_preinit(void)
82 interrupt_traj_reset();
83 mainboard.flags = DO_ENCODERS | DO_CS | DO_RS |
84 DO_POS | DO_BD | DO_POWER;
86 //i2c_cobboard_mode_init();
87 strat_conf_dump(__FUNCTION__);
88 strat_db_dump(__FUNCTION__);
91 void strat_conf_dump(const char *caller)
93 if (!strat_conf.dump_enabled)
96 printf_P(PSTR("-- conf --\r\n"));
100 /* call it just before launching the strat */
101 void strat_init(void)
103 /* XXX init rollers, .. */
107 /* we consider that the color is correctly set */
109 strat_set_speed(SPEED_DIST_FAST, SPEED_ANGLE_FAST);
111 interrupt_traj_reset();
113 i2c_cobboard_mode_harvest(I2C_LEFT_SIDE);
114 i2c_cobboard_mode_harvest(I2C_RIGHT_SIDE);
115 i2c_ballboard_set_mode(I2C_BALLBOARD_MODE_HARVEST);
117 /* used in strat_base for END_TIMER */
118 mainboard.flags = DO_ENCODERS | DO_CS | DO_RS |
119 DO_POS | DO_BD | DO_TIMER | DO_POWER;
123 /* call it after each strat */
124 void strat_exit(void)
130 mainboard.flags &= ~(DO_TIMER);
136 mainboard.flags &= ~(DO_CS);
138 pwm_ng_set(LEFT_PWM, 0);
139 pwm_ng_set(RIGHT_PWM, 0);
143 /* called periodically */
144 void strat_event(void *dummy)
147 /* pack or deploy spickle */
148 if (strat_infos.status.flags & STRAT_STATUS_LHARVEST) {
149 if (sensor_get(S_LCOB_PRESENT)) {
150 if (sensor_get(S_LCOB_WHITE))
151 i2c_ballboard_set_mode();
157 /* limit speed when opponent is close */
161 static uint8_t strat_beginning(void)
165 strat_set_speed(250, SPEED_ANGLE_FAST);
168 err = line2line(LINE_UP, 0, LINE_R_DOWN, 2);
169 if (!TRAJ_SUCCESS(err)) {
170 trajectory_hardstop(&mainboard.traj);
176 err = line2line(LINE_R_DOWN, 2, LINE_R_UP, 2);
177 if (!TRAJ_SUCCESS(err)) {
178 trajectory_hardstop(&mainboard.traj);
184 err = line2line(LINE_R_UP, 2, LINE_UP, 5);
185 if (!TRAJ_SUCCESS(err)) {
186 trajectory_hardstop(&mainboard.traj);
191 trajectory_hardstop(&mainboard.traj);
194 trajectory_a_abs(&mainboard.traj, COLOR_A(90));
195 i2c_ballboard_set_mode(I2C_BALLBOARD_MODE_EJECT);
199 trajectory_goto_xy_abs(&mainboard.traj, 2625, COLOR_Y(1847));
200 err = wait_traj_end(END_INTR|END_TRAJ);
201 i2c_cobboard_mode_pack(I2C_LEFT_SIDE);
202 i2c_cobboard_mode_pack(I2C_RIGHT_SIDE);
203 trajectory_a_rel(&mainboard.traj, COLOR_A(180));
204 err = wait_traj_end(END_INTR|END_TRAJ);
207 trajectory_d_rel(&mainboard.traj, -100);
208 err = wait_traj_end(END_INTR|END_TRAJ);
209 i2c_cobboard_mode_eject();
212 trajectory_hardstop(&mainboard.traj);
216 /* dump state (every 5 s max) */
217 #define DUMP_RATE_LIMIT(dump, last_print) \
219 if (time_get_s() - last_print > 5) { \
221 last_print = time_get_s(); \
226 uint8_t strat_main(void)
231 err = strat_beginning();