test
[aversive.git] / projects / microb2010 / tests / test_board2008 / strat_base.h
1 /*  
2  *  Copyright Droids Corporation, Microb Technology (2009)
3  * 
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.
8  *
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.
13  *
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
17  *
18  *  Revision : $Id: strat_base.h,v 1.3 2009-05-02 10:08:09 zer0 Exp $
19  *
20  */
21
22 /* return values for strats and sub trajs */
23 #define END_TRAJ       1 /* traj successful */
24 #define END_BLOCKING   2 /* blocking during traj */
25 #define END_NEAR       4 /* we are near destination */
26 #define END_OBSTACLE   8 /* There is an obstacle in front of us */
27 #define END_ERROR     16 /* Cannot do the command */
28 #define END_INTR      32 /* interrupted by user */
29 #define END_TIMER     64 /* we don't a lot of time */
30 #define END_RESERVED 128 /* reserved */
31
32 /* default speeds */
33 #define SPEED_DIST_FAST 2500
34 #define SPEED_ANGLE_FAST 2000
35 #define SPEED_DIST_SLOW 1000
36 #define SPEED_ANGLE_SLOW 1000
37 #define SPEED_DIST_VERY_SLOW 400
38 #define SPEED_ANGLE_VERY_SLOW 400
39
40 /* useful traj flags */
41 #define TRAJ_SUCCESS(f) (f & (END_TRAJ|END_NEAR))
42 #define TRAJ_FLAGS_STD (END_TRAJ|END_BLOCKING|END_NEAR|END_OBSTACLE|END_INTR|END_TIMER)
43 #define TRAJ_FLAGS_NO_TIMER (END_TRAJ|END_BLOCKING|END_NEAR|END_OBSTACLE|END_INTR)
44 #define TRAJ_FLAGS_NO_NEAR (END_TRAJ|END_BLOCKING|END_OBSTACLE|END_INTR|END_TIMER)
45 #define TRAJ_FLAGS_NO_NEAR_NO_TIMER (END_TRAJ|END_BLOCKING|END_OBSTACLE|END_INTR)
46 #define TRAJ_FLAGS_SMALL_DIST (END_TRAJ|END_BLOCKING|END_INTR)
47
48 /* area */
49 #define AREA_X 3000
50 #define AREA_Y 2100
51
52 #define START_X 200
53 #define START_Y 200
54 #define START_A 45
55
56 #define CENTER_X 1500
57 #define CENTER_Y 1050
58
59 #define CORNER_X 3000
60 #define CORNER_Y 2100
61
62 /* only valid after a END_OBSTACLE */
63 struct opponent_obstacle {
64         int16_t x;
65         int16_t y;
66         int16_t a;
67         int16_t d;
68 };
69 extern struct opponent_obstacle opponent_obstacle;
70
71 /* stop as fast as possible, without ramp */
72 void strat_hardstop(void);
73
74 #define DO_NOT_SET_POS -1000
75 /* Reset position. If arg == DO_NOT_SET_POS, don't update value for
76  * it. */
77 void strat_reset_pos(int16_t x, int16_t y, int16_t a);
78
79 /* decrease gain on angle PID, and go forward until we reach the
80  * border. */
81 uint8_t strat_calib(int16_t d, uint8_t flags);
82
83 /* launch start procedure */
84 void strat_start(void);
85
86 /* go to an x,y point without checking for obstacle or blocking. It
87  * should be used for very small dist only. Return END_TRAJ if we
88  * reach destination, or END_BLOCKING if the robot blocked more than 3
89  * times. */
90 uint8_t strat_goto_xy_force(int16_t x, int16_t y);
91
92 /* escape from disc polygon or another zone */
93 struct build_zone;
94 uint8_t strat_escape(struct build_zone *zone, uint8_t flags);
95
96 /* return true if we have to brake due to an obstacle */
97 uint8_t strat_obstacle(void);
98
99 /* set/get user strat speed */
100 void strat_set_speed(uint16_t d, uint16_t a);
101 void strat_get_speed(uint16_t *d, uint16_t *a);
102
103 /* when user type ctrl-c we can interrupt traj */
104 void interrupt_traj(void);
105 void interrupt_traj_reset(void);
106
107 /* limit speed when we are close of opponent */
108 void strat_limit_speed_enable(void);
109 void strat_limit_speed_disable(void);
110 void strat_limit_speed(void);
111
112 /* get name of traj error with its number */
113 const char *get_err(uint8_t err);
114
115 /* test trajectory end condition */
116 uint8_t test_traj_end(uint8_t why);
117
118 /* loop until test_traj_end() is true */
119 #define wait_traj_end(why) __wait_traj_end_debug(why, __LINE__)
120 uint8_t __wait_traj_end_debug(uint8_t why, uint16_t line);