2 * Copyright Droids, Microb Technology (2008)
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_static_columns.c,v 1.5 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>
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>
54 #include "../common/i2c_commands.h"
57 #include "strat_base.h"
58 #include "strat_utils.h"
59 #include "strat_avoid.h"
61 #include "i2c_protocol.h"
63 #define ERROUT(e) do { \
71 * must be called from start area.
72 * get 4 static columns and build a temple on the disc
74 uint8_t strat_static_columns(uint8_t configuration)
77 uint8_t col1_present = 0, col4_present = 0;
78 uint16_t old_spdd, old_spda;
80 DEBUG(E_USER_STRAT, "%s(%d)", __FUNCTION__, configuration);
82 strat_get_speed(&old_spdd, &old_spda);
84 /* calibrate scanner */
85 i2c_sensorboard_scanner_calib();
87 i2c_mechboard_mode_harvest();
89 /* go straight. total distance is less than 5 meters */
90 strat_set_speed(1000, 1000);
91 trajectory_d_rel(&mainboard.traj, BIG_DIST);
93 /* when y > 50, break */
94 err = WAIT_COND_OR_TRAJ_END(y_is_more_than(500), TRAJ_FLAGS_STD);
95 if (TRAJ_SUCCESS(err)) /* we should not reach end */
100 /* turn to 90° abs while going forward */
101 DEBUG(E_USER_STRAT, "turn now");
102 strat_set_speed(1000, 350);
103 trajectory_only_a_abs(&mainboard.traj, COLOR_A(90));
105 /* when y > 100, check the presence of column 4 */
106 err = WAIT_COND_OR_TRAJ_END(y_is_more_than(1000), TRAJ_FLAGS_STD);
107 if (TRAJ_SUCCESS(err)) /* we should not reach end */
111 if (get_color() == I2C_COLOR_RED && sensor_get(S_COLUMN_RIGHT))
113 if (get_color() == I2C_COLOR_GREEN && sensor_get(S_COLUMN_LEFT))
116 /* when y > 120, check the presence of column 1 */
117 err = WAIT_COND_OR_TRAJ_END(y_is_more_than(1200), TRAJ_FLAGS_STD);
118 if (TRAJ_SUCCESS(err)) /* we should not reach end */
122 if (get_color() == I2C_COLOR_RED && sensor_get(S_COLUMN_RIGHT))
124 if (get_color() == I2C_COLOR_GREEN && sensor_get(S_COLUMN_LEFT))
127 /* when y > 130, break */
128 err = WAIT_COND_OR_TRAJ_END(y_is_more_than(1300), TRAJ_FLAGS_STD);
129 if (TRAJ_SUCCESS(err)) /* we should not reach end */
134 strat_infos.s_cols.flags |= STATIC_COL_LINE0_DONE;
136 DEBUG(E_USER_STRAT, "col4=%d col1=%d", col4_present, col1_present);
137 DEBUG(E_USER_STRAT, "have %d cols", get_column_count());
139 if (configuration == 0) {
140 if (get_column_count() > 2) {
142 if (col4_present || col1_present) {
143 strat_infos.s_cols.flags |=
144 STATIC_COL_LINE2_DONE;
147 strat_infos.s_cols.flags |=
148 STATIC_COL_LINE1_DONE;
152 /* only 2 colums on the first line */
154 /* all other colums are on line 1 */
155 if (col4_present && col1_present) {
157 strat_infos.s_cols.flags |=
158 STATIC_COL_LINE2_DONE;
161 /* only 2 columns on line 1, so there are also
163 else if (col4_present || col1_present) {
165 strat_infos.s_cols.flags |=
166 STATIC_COL_LINE2_DONE;
169 /* all other columns are on line 2 */
172 strat_infos.s_cols.flags |=
173 STATIC_COL_LINE1_DONE;
178 strat_infos.s_cols.configuration = configuration;
179 DEBUG(E_USER_STRAT, "use configuration %d", configuration);
181 if (configuration == 1) {
182 /* we already got 4 columns, go to the disc directly */
184 strat_set_speed(1500, 900);
185 trajectory_only_a_abs(&mainboard.traj, COLOR_A(0));
186 err = WAIT_COND_OR_TRAJ_END(x_is_more_than(1100), TRAJ_FLAGS_STD);
188 if (TRAJ_SUCCESS(err)) /* we should not reach end */
193 else if (configuration == 2 /* go from line 0 to line 1 */) {
194 strat_set_speed(800, 1000);
195 /* relative is needed here */
196 trajectory_only_a_rel(&mainboard.traj, COLOR_A(-180));
197 err = WAIT_COND_OR_TRAJ_END(!y_is_more_than(1300), TRAJ_FLAGS_STD);
198 if (TRAJ_SUCCESS(err)) /* we should not reach end */
202 strat_set_speed(1000, 600);
203 err = WAIT_COND_OR_TRAJ_END(!y_is_more_than(1100),
205 if (TRAJ_SUCCESS(err)) /* we should not reach end */
210 else if (configuration == 3 /* go from line 0 to line 2 and there is 4 columns
212 strat_set_speed(1000, 600);
213 /* relative is needed here */
214 trajectory_only_a_rel(&mainboard.traj, COLOR_A(-180));
215 err = WAIT_COND_OR_TRAJ_END(!y_is_more_than(1110), TRAJ_FLAGS_STD);
216 if (TRAJ_SUCCESS(err)) /* we should not reach end */
221 else if (configuration == 4 /* go from line 0 to line 2 and there is 2 columns
223 strat_set_speed(1000, 600);
224 /* relative is needed here */
225 trajectory_only_a_rel(&mainboard.traj, COLOR_A(-180));
226 err = WAIT_COND_OR_TRAJ_END(!y_is_more_than(600), TRAJ_FLAGS_STD);
227 if (TRAJ_SUCCESS(err)) /* we should not reach end */
233 trajectory_stop(&mainboard.traj);
239 strat_set_speed(old_spdd, old_spda);
245 * must be called after the first temple building
247 uint8_t strat_static_columns_pass2(void)
249 uint16_t old_spdd, old_spda;
250 uint8_t side, err, next_mode;
252 DEBUG(E_USER_STRAT, "%s()", __FUNCTION__);
254 strat_get_speed(&old_spdd, &old_spda);
256 if (get_color() == I2C_COLOR_RED)
257 side = I2C_RIGHT_SIDE;
259 side = I2C_LEFT_SIDE;
261 if (strat_infos.conf.flags & STRAT_CONF_STORE_STATIC2)
262 next_mode = I2C_MECHBOARD_MODE_STORE;
264 next_mode = I2C_MECHBOARD_MODE_HARVEST;
266 switch (strat_infos.s_cols.configuration) {
268 /* configuration 1: 4 cols on line 0 */
270 if (strat_infos.s_cols.flags & STATIC_COL_LINE1_DONE) {
273 strat_set_speed(2000, 700);
274 trajectory_d_a_rel(&mainboard.traj, -450, COLOR_A(35));
275 err = wait_traj_end(TRAJ_FLAGS_NO_NEAR);
276 if (!TRAJ_SUCCESS(err))
279 i2c_mechboard_mode_prepare_pickup_next(side,
282 strat_set_speed(SPEED_DIST_SLOW, SPEED_ANGLE_FAST);
283 trajectory_goto_forward_xy_abs(&mainboard.traj,
286 err = WAIT_COND_OR_TRAJ_END(get_column_count() == 2,
288 if (!TRAJ_SUCCESS(err))
293 strat_set_speed(2000, 700);
294 trajectory_d_a_rel(&mainboard.traj, -650, COLOR_A(55));
295 err = wait_traj_end(TRAJ_FLAGS_NO_NEAR);
296 if (!TRAJ_SUCCESS(err))
299 i2c_mechboard_mode_prepare_pickup_next(side,
302 strat_set_speed(SPEED_DIST_SLOW, SPEED_ANGLE_FAST);
304 err = goto_and_avoid_forward(LINE1_X,
308 if (!TRAJ_SUCCESS(err))
315 /* configuration 2: 2 cols on line 0,
316 all other colums are on line 1 */
319 strat_set_speed(2000, 700);
320 trajectory_d_a_rel(&mainboard.traj, -410, COLOR_A(-20));
321 err = wait_traj_end(TRAJ_FLAGS_NO_NEAR);
322 if (!TRAJ_SUCCESS(err))
325 i2c_mechboard_mode_prepare_pickup_next(side,
328 strat_set_speed(SPEED_DIST_SLOW, SPEED_ANGLE_FAST);
330 err = goto_and_avoid_forward(COL10_X, COLOR_Y(400),
333 if (!TRAJ_SUCCESS(err))
339 /* configuration 3: 2 cols on line 0,
340 all other colums are on line 2 */
343 strat_set_speed(2000, 700);
344 trajectory_d_a_rel(&mainboard.traj, -150, COLOR_A(-30));
345 err = wait_traj_end(TRAJ_FLAGS_NO_NEAR);
346 if (!TRAJ_SUCCESS(err))
349 i2c_mechboard_mode_prepare_pickup_next(side,
352 strat_set_speed(SPEED_DIST_SLOW, SPEED_ANGLE_FAST);
354 trajectory_goto_forward_xy_abs(&mainboard.traj,
357 err = wait_traj_end(TRAJ_FLAGS_NO_NEAR);
358 if (!TRAJ_SUCCESS(err))
364 /* configuration 4: 2 cols on line 0,
365 2 on line 1, 2 on line 2 */
368 strat_set_speed(600, 2000);
369 trajectory_d_a_rel(&mainboard.traj, -BIG_DIST,
371 err = WAIT_COND_OR_TRAJ_END(y_is_more_than(900),
373 if (TRAJ_SUCCESS(err)) /* we should not reach end */
378 DEBUG(E_USER_STRAT, "%s():%d", __FUNCTION__, __LINE__);
379 i2c_mechboard_mode_prepare_pickup_next(side,
382 strat_set_speed(2000, 2000);
383 trajectory_d_rel(&mainboard.traj, -BIG_DIST);
384 err = WAIT_COND_OR_TRAJ_END(y_is_more_than(1100),
386 if (TRAJ_SUCCESS(err)) /* we should not reach end */
391 DEBUG(E_USER_STRAT, "%s():%d", __FUNCTION__, __LINE__);
392 trajectory_d_a_rel(&mainboard.traj, -600, COLOR_A(40));
393 err = wait_traj_end(TRAJ_FLAGS_NO_NEAR);
394 if (!TRAJ_SUCCESS(err))
397 DEBUG(E_USER_STRAT, "%s():%d", __FUNCTION__, __LINE__);
398 strat_set_speed(SPEED_DIST_SLOW, SPEED_ANGLE_FAST);
399 err = goto_and_avoid_forward(LINE1_X,
410 /* should not reach this point */
414 strat_set_speed(old_spdd, old_spda);