vt100: include pgmspace.h as we use PROGMEM macro
[aversive.git] / mainboard / strat.h
1 /*  
2  *  Copyright Droids Corporation, Microb Technology, Eirbot (2008)
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.h,v 1.7 2009-11-08 17:24:33 zer0 Exp $
19  *
20  */
21
22 #ifndef _STRAT_H_
23 #define _STRAT_H_
24
25 /* convert coords according to our color */
26 #define COLOR_Y(y)     ((mainboard.our_color==I2C_COLOR_YELLOW)? (y) : (AREA_Y-(y)))
27 #define COLOR_A(a)     ((mainboard.our_color==I2C_COLOR_YELLOW)? (a) : (-a))
28 #define COLOR_SIGN(x)  ((mainboard.our_color==I2C_COLOR_YELLOW)? (x) : (-x))
29 #define COLOR_INVERT(x) ((mainboard.our_color==I2C_COLOR_YELLOW)? (x) : (!x))
30
31 /* area */
32 #define AREA_X 3000
33 #define AREA_Y 2100
34
35 #define START_X 200
36 #define START_Y COLOR_Y(200)
37 #define START_A COLOR_A(45)
38
39 #define CENTER_X 1500
40 #define CENTER_Y 1050
41
42 #define CORNER_X 3000
43 #define CORNER_Y COLOR_Y(2100)
44
45 /* XXX these offset are not related to corn, but to waypoints */
46 #define OFFSET_CORN_X 150
47 #define OFFSET_CORN_Y 222
48 #define STEP_CORN_X 225
49 #define STEP_CORN_Y 250
50
51 #define CORN_NB 18
52 #define TOMATO_NB 14
53
54 #define WAYPOINTS_NBX 13
55 #define WAYPOINTS_NBY 8
56
57 /*
58  * Corn position and lines, valid for YELLOW.
59  *
60  *           vertical lines
61  *            O     1     2     3     4     5
62  * 2100 +-----|-----|-----|-----|-----|-----|-----+
63  *      |        c5          c9         c14       |
64  *      |  c2          c7         c11         c17 |   diag
65  *      |        c4          c8         c13       |   lines
66  *     0/  c1          c6         c10         c16 \0
67  *  y   |        c3                     c12       |
68  *     1/  c0                                 c15 \1
69  *      |-----+                             +-----|
70  *     2/     |                             |     \2
71  *      | Yellow                           Blue   |
72  *   0  +-----+-----------------------------+-----+
73  *     0                  x                      3000
74  *
75  * Ball (tomato) and i,j coords (for waypoints)
76  *
77  * 2100 +--0--1--2--3--4--5--6--7--8--9-10-11-12--+
78  *      7              t5          t9             |
79  *      6        t3          t7         t11       |
80  *      5  t1          t4          t8         t13 |
81  *      4        t2          t6         t10       |
82  *  y   3  t0                                 t12 |
83  *      2                                         |
84  *      1-----+                             +-----|
85  *      0     |                             |     |
86  *      | Yellow                           Blue   |
87  *   0  +-----+-----------------------------+-----+
88  *     0                  x                      3000
89  *
90  *
91  * Corn position and lines, valid for BLUE.
92  *
93  *           vertical lines
94  *            5     4     3     2     1     0
95  *    0 +-----|-----|-----|-----|-----|-----|-----+
96  *      |        c14         c9         c5        |
97  *      |  c17         c11        c7          c2  |   diag
98  *      |        c13         c8         c4        |   lines
99  *     0/  c16         c10        c6          c1  \0
100  *  y   |        c12                    c3        |
101  *     1/  c15                                c0  \1
102  *      |-----+                             +-----|
103  *     2/     |                             |     \2
104  *      | Yellow                           Blue   |
105  * 2100 +-----+-----------------------------+-----+
106  *    3000                x                       0
107  *
108  * Ball (tomato) and i,j coords (for waypoints)
109  *
110  *    0 +-12-11-10--9--8--7--6--5--4--3--2--1--0--+
111  *      7              t9          t5             |
112  *      6       t11          t7         t3        |
113  *      5 t13          t8          t4         t1  |
114  *      4       t10          t6         t2        |
115  *  y   3 t12                                 t0  |
116  *      2                                         |
117  *      1-----+                             +-----|
118  *      0     |                             |     |
119  *      | Yellow                           Blue   |
120  * 2100 +-----+-----------------------------+-----+
121  *   3000                 x                       0
122  *
123  */
124
125 /* useful traj flags */
126 #define TRAJ_SUCCESS(f) (f & (END_TRAJ|END_NEAR))
127 #define TRAJ_FLAGS_STD (END_TRAJ|END_BLOCKING|END_NEAR|END_OBSTACLE|END_INTR|END_TIMER)
128 #define TRAJ_FLAGS_NO_TIMER (END_TRAJ|END_BLOCKING|END_NEAR|END_OBSTACLE|END_INTR)
129 #define TRAJ_FLAGS_NO_NEAR (END_TRAJ|END_BLOCKING|END_OBSTACLE|END_INTR|END_TIMER)
130 #define TRAJ_FLAGS_NO_NEAR_NO_TIMER (END_TRAJ|END_BLOCKING|END_OBSTACLE|END_INTR)
131 #define TRAJ_FLAGS_SMALL_DIST (END_TRAJ|END_BLOCKING|END_INTR)
132
133 /* default acc */
134 #define ACC_DIST  15.
135 #define ACC_ANGLE 15.
136
137 /* default speeds */
138 #define SPEED_DIST_FAST 2500.
139 #define SPEED_ANGLE_FAST 2000.
140 #define SPEED_DIST_SLOW 1000.
141 #define SPEED_ANGLE_SLOW 1000.
142 #define SPEED_DIST_VERY_SLOW 400.
143 #define SPEED_ANGLE_VERY_SLOW 400.
144
145 /* strat infos structures */
146 struct strat_conf {
147         uint8_t dump_enabled;
148
149 #define STRAT_CONF_XXX   0x01
150         uint8_t flags;
151 };
152
153 extern struct strat_conf strat_conf;
154
155 /* in strat.c */
156 void strat_conf_dump(const char *caller);
157 void strat_reset_infos(void); /* reset current known state */
158 void strat_preinit(void);
159 void strat_init(void);
160 void strat_exit(void);
161 void strat_dump_flags(void);
162 void strat_goto_near(int16_t x, int16_t y, uint16_t dist);
163 uint8_t strat_main(void);
164 void strat_event(void *dummy);
165
166 #endif