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"
60 #include "strat_base.h"
61 #include "strat_corn.h"
62 #include "strat_utils.h"
66 #define COL_DISP_MARGIN 400 /* stop 40 cm in front of dispenser */
67 #define COL_SCAN_PRE_MARGIN 250
69 struct strat_infos strat_infos = {
80 /*************************************************************/
84 /*************************************************************/
86 void strat_set_bounding_box(void)
88 if (get_color() == I2C_COLOR_YELLOW) {
89 strat_infos.area_bbox.x1 = 300;
90 strat_infos.area_bbox.y1 = 200;
91 strat_infos.area_bbox.x2 = 2720; /* needed for c1 */
92 strat_infos.area_bbox.y2 = 1800;
95 strat_infos.area_bbox.x1 = 200;
96 strat_infos.area_bbox.y1 = 300;
97 strat_infos.area_bbox.x2 = 2720; /* needed for c1 */
98 strat_infos.area_bbox.y2 = 1900;
101 polygon_set_boundingbox(strat_infos.area_bbox.x1,
102 strat_infos.area_bbox.y1,
103 strat_infos.area_bbox.x2,
104 strat_infos.area_bbox.y2);
107 /* called before each strat, and before the start switch */
108 void strat_preinit(void)
111 interrupt_traj_reset();
112 mainboard.flags = DO_ENCODERS | DO_CS | DO_RS |
113 DO_POS | DO_BD | DO_POWER;
115 i2c_cobboard_mode_init();
117 strat_dump_infos(__FUNCTION__);
120 void strat_dump_conf(void)
122 if (!strat_infos.dump_enabled)
125 printf_P(PSTR("-- conf --\r\n"));
129 /* display current information about the state of the game */
130 void strat_dump_infos(const char *caller)
132 if (!strat_infos.dump_enabled)
135 printf_P(PSTR("%s() dump strat infos:\r\n"), caller);
138 /* init current area state before a match. Dump update user conf
140 void strat_reset_infos(void)
142 init_corn_table(-1, -1);
145 /* call it just before launching the strat */
146 void strat_init(void)
148 /* XXX init rollers, .. */
152 /* we consider that the color is correctly set */
154 strat_set_speed(SPEED_DIST_FAST, SPEED_ANGLE_FAST);
156 interrupt_traj_reset();
158 /* used in strat_base for END_TIMER */
159 mainboard.flags = DO_ENCODERS | DO_CS | DO_RS |
160 DO_POS | DO_BD | DO_TIMER | DO_POWER;
164 /* call it after each strat */
165 void strat_exit(void)
169 mainboard.flags &= ~(DO_TIMER);
174 mainboard.flags &= ~(DO_CS);
175 pwm_ng_set(LEFT_PWM, 0);
176 pwm_ng_set(RIGHT_PWM, 0);
180 /* called periodically */
181 void strat_event(void *dummy)
184 /* pack or deploy spickle */
185 if (strat_infos.status.flags & STRAT_STATUS_LHARVEST) {
186 if (sensor_get(S_LCOB_PRESENT)) {
187 if (sensor_get(S_LCOB_WHITE))
188 i2c_ballboard_set_mode();
194 /* limit speed when opponent is close */
198 static uint8_t strat_beginning(void)
203 /* dump state (every 5 s max) */
204 #define DUMP_RATE_LIMIT(dump, last_print) \
206 if (time_get_s() - last_print > 5) { \
208 last_print = time_get_s(); \
213 uint8_t strat_main(void)
218 err = strat_beginning();