2 * Copyright Droids Corporation, Microb Technology, Eirbot (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.h,v 1.7 2009-11-08 17:24:33 zer0 Exp $
25 /* convert coords according to our color */
26 #define COLOR_Y(y) ((mainboard.our_color==I2C_COLOR_RED)? (y) : (AREA_Y-(y)))
27 #define COLOR_A(a) ((mainboard.our_color==I2C_COLOR_RED)? (a) : (-a))
28 #define COLOR_SIGN(x) ((mainboard.our_color==I2C_COLOR_RED)? (x) : (-x))
29 #define COLOR_INVERT(x) ((mainboard.our_color==I2C_COLOR_RED)? (x) : (!x))
36 #define START_Y COLOR_Y(200)
37 #define START_A COLOR_A(45)
43 #define CORNER_Y COLOR_Y(2100)
50 * +---C1--------------------------C1---+
57 * |------ 9 10 11 . ------|
60 * +-----+--L1--L2-------L2--L1---+-----+
70 #define COL0_Y COLOR_Y(1175)
72 #define COL1_Y COLOR_Y(1175)
74 #define COL2_Y COLOR_Y(1175)
77 #define COL3_Y COLOR_Y(975)
79 #define COL4_Y COLOR_Y(975)
81 #define COL5_Y COLOR_Y(975)
84 #define COL6_Y COLOR_Y(775)
86 #define COL7_Y COLOR_Y(775)
88 #define COL8_Y COLOR_Y(775)
91 #define COL9_Y COLOR_Y(575)
93 #define COL10_Y COLOR_Y(575)
95 #define COL11_Y COLOR_Y(575)
97 /* distance to go backward before pickup in dispenser */
98 #define DIST_BACK_DISPENSER 35
100 /* diag of the pentagon (pentacle ?) */
101 #define DISC_PENTA_DIAG 530
103 #define COL_DISP_MAX_TRIES 5
104 #define LIN_DISP_MAX_TRIES 3
106 /* useful traj flags */
107 #define TRAJ_SUCCESS(f) (f & (END_TRAJ|END_NEAR))
108 #define TRAJ_FLAGS_STD (END_TRAJ|END_BLOCKING|END_NEAR|END_OBSTACLE|END_INTR|END_TIMER)
109 #define TRAJ_FLAGS_NO_TIMER (END_TRAJ|END_BLOCKING|END_NEAR|END_OBSTACLE|END_INTR)
110 #define TRAJ_FLAGS_NO_NEAR (END_TRAJ|END_BLOCKING|END_OBSTACLE|END_INTR|END_TIMER)
111 #define TRAJ_FLAGS_NO_NEAR_NO_TIMER (END_TRAJ|END_BLOCKING|END_OBSTACLE|END_INTR)
112 #define TRAJ_FLAGS_SMALL_DIST (END_TRAJ|END_BLOCKING|END_INTR)
115 #define SPEED_DIST_FAST 2500
116 #define SPEED_ANGLE_FAST 2000
117 #define SPEED_DIST_SLOW 1000
118 #define SPEED_ANGLE_SLOW 1000
119 #define SPEED_DIST_VERY_SLOW 400
120 #define SPEED_ANGLE_VERY_SLOW 400
122 /* strat infos structures */
132 #define STRAT_CONF_ONLY_ONE_ON_DISC 0x01
133 #define STRAT_CONF_BYPASS_STATIC2 0x02
134 #define STRAT_CONF_TAKE_ONE_LINTEL 0x04
135 #define STRAT_CONF_SKIP_WHEN_CHECK_FAILS 0x08
136 #define STRAT_CONF_STORE_STATIC2 0x10
137 #define STRAT_CONF_BIG_3_TEMPLE 0x20
138 #define STRAT_CONF_EARLY_SCAN 0x40
139 #define STRAT_CONF_PUSH_OPP_COLS 0x80
141 uint8_t scan_opp_min_time;
142 uint8_t delay_between_opp_scan;
143 uint8_t scan_our_min_time;
144 uint8_t delay_between_our_scan;
145 uint8_t wait_opponent;
146 uint8_t lintel_min_time;
147 int16_t scan_opp_angle;
150 struct static_columns {
151 #define STATIC_COL_LINE0_DONE 0x01
152 #define STATIC_COL_LINE1_DONE 0x02
153 #define STATIC_COL_LINE2_DONE 0x04
155 uint8_t configuration;
158 struct column_dispenser {
160 uint8_t last_try_time;
162 int16_t checkpoint_x;
163 int16_t checkpoint_y;
172 struct lintel_dispenser {
174 uint8_t last_try_time;
180 #define TEMPLE_F_VALID 0x01 /* structure is valid */
181 #define TEMPLE_F_MONOCOL 0x02 /* temple has only one col */
182 #define TEMPLE_F_ON_DISC 0x04 /* temple is on disc (else it's on other zone) */
183 #define TEMPLE_F_OPPONENT 0x08 /* temple was originally built by opponent */
184 #define TEMPLE_F_LINTEL 0x10 /* lintel on top (don't put another lintel) */
187 /* position of the robot when we built it */
192 /* position of the robot checkpoint */
193 int16_t checkpoint_x;
194 int16_t checkpoint_y;
196 /* position and level of each col */
205 #define TEMPLE_DISABLE_TIME 5
206 uint8_t last_try_time;
208 struct build_zone *zone;
212 #define ZONE_F_VALID 0x01 /* zone is valid */
213 #define ZONE_F_DISC 0x02 /* specific disc zone */
214 #define ZONE_F_ZONE1 0x04 /* specific zone 1 */
215 #define ZONE_F_ZONE0 0x08 /* specific zone 0 */
216 #define ZONE_F_BUSY 0x10 /* this zone is busy */
219 int16_t checkpoint_x;
220 int16_t checkpoint_y;
222 #define ZONE_DISABLE_TIME 5
223 uint8_t last_try_time;
230 /* all infos related to strat */
232 uint8_t dump_enabled;
234 struct bbox area_bbox;
235 uint8_t taken_lintel;
236 uint8_t col_in_boobs;
237 uint8_t lazy_pickup_done;
238 uint8_t i2c_loaded_skipped;
239 struct static_columns s_cols;
240 struct column_dispenser c1;
241 struct column_dispenser c2;
242 struct column_dispenser c3;
243 struct lintel_dispenser l1;
244 struct lintel_dispenser l2;
245 struct build_zone zone_list[MAX_ZONE];
246 struct temple temple_list[MAX_TEMPLE];
248 extern struct strat_infos strat_infos;
251 void strat_dump_infos(const char *caller); /* show current known state
253 void strat_dump_temple(struct temple *temple);
254 void strat_dump_conf(void);
255 void strat_reset_infos(void); /* reset current known state */
256 void strat_preinit(void);
257 void strat_init(void);
258 void strat_exit(void);
259 void strat_dump_flags(void);
260 void strat_goto_near(int16_t x, int16_t y, uint16_t dist);
261 uint8_t strat_main(void);
262 void strat_event(void *dummy);
264 /* in strat_static_columns.c */
265 uint8_t strat_static_columns(uint8_t configuration);
266 uint8_t strat_static_columns_pass2(void);
268 /* in strat_lintel.c */
269 uint8_t strat_goto_lintel_disp(struct lintel_dispenser *disp);
270 uint8_t strat_pickup_lintels(void);
272 /* in strat_column_disp.c */
273 uint8_t strat_eject_col(int16_t eject_a, int16_t pickup_a);
274 uint8_t strat_pickup_columns(void);
275 uint8_t strat_goto_col_disp(struct column_dispenser **disp);
277 /* in strat_building.c */
278 uint8_t strat_goto_disc(int8_t level);
279 uint8_t strat_goto_build_zone(struct build_zone *build_zone, uint8_t level);
280 uint8_t strat_build_new_temple(struct build_zone *build_zone);
281 uint8_t strat_goto_temple(struct temple *temple);
282 uint8_t strat_grow_temple(struct temple *temple);
283 uint8_t strat_grow_temple_column(struct temple *temple);
284 struct temple *strat_get_best_temple(void);
285 struct temple *strat_get_our_temple_on_disc(uint8_t valid);
286 struct build_zone *strat_get_best_zone(void);
287 struct temple *strat_get_free_temple(void);
289 /* in strat_scan.c */
290 struct scan_disc_result;
291 void scanner_dump_state(void);
292 int8_t strat_scan_get_checkpoint(uint8_t mode, int16_t *ckpt_rel_x,
293 int16_t *ckpt_rel_y, int16_t *back_mm);
294 uint8_t strat_scan_disc(int16_t angle, uint8_t mode,
295 struct scan_disc_result *result);
296 uint8_t strat_goto_disc_angle(int16_t a_deg, int8_t level);
297 int16_t strat_get_temple_angle(struct temple *temple);
298 int16_t strat_temple_angle_to_scan_angle(int16_t temple_angle);
299 uint8_t strat_build_on_opponent_temple(void);
300 uint8_t strat_check_temple_and_build(void);