cobboard: prepare state machine
[aversive.git] / projects / microb2010 / 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_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))
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 /*
46  *
47  *
48  *
49  *
50  *     +------------------------------------+
51  *     |                                    |
52  *     |                                    |
53  *     |                                    |
54  *     |                                    | 
55  *  y  |                                    |
56  *     |                                    |  
57  *     |------                        ------| 
58  *     |     |                        |     | 
59  *     |     |                        |     | 
60  *     +-----+------------------------+-----+
61  *                       x
62  */
63
64 /* useful traj flags */
65 #define TRAJ_SUCCESS(f) (f & (END_TRAJ|END_NEAR))
66 #define TRAJ_FLAGS_STD (END_TRAJ|END_BLOCKING|END_NEAR|END_OBSTACLE|END_INTR|END_TIMER)
67 #define TRAJ_FLAGS_NO_TIMER (END_TRAJ|END_BLOCKING|END_NEAR|END_OBSTACLE|END_INTR)
68 #define TRAJ_FLAGS_NO_NEAR (END_TRAJ|END_BLOCKING|END_OBSTACLE|END_INTR|END_TIMER)
69 #define TRAJ_FLAGS_NO_NEAR_NO_TIMER (END_TRAJ|END_BLOCKING|END_OBSTACLE|END_INTR)
70 #define TRAJ_FLAGS_SMALL_DIST (END_TRAJ|END_BLOCKING|END_INTR)
71
72 /* default speeds */
73 #define SPEED_DIST_FAST 2500
74 #define SPEED_ANGLE_FAST 2000
75 #define SPEED_DIST_SLOW 1000
76 #define SPEED_ANGLE_SLOW 1000
77 #define SPEED_DIST_VERY_SLOW 400
78 #define SPEED_ANGLE_VERY_SLOW 400
79
80 /* strat infos structures */
81
82 struct bbox {
83         int32_t x1;
84         int32_t y1;
85         int32_t x2;
86         int32_t y2;
87 };
88
89 struct conf {
90 #define STRAT_CONF_XXX   0x01
91         uint8_t flags;
92 };
93
94 /* all infos related to strat */
95 struct strat_infos {
96         uint8_t dump_enabled;
97         struct conf conf;
98         struct bbox area_bbox;
99 };
100 extern struct strat_infos strat_infos;
101
102 /* in strat.c */
103 void strat_dump_infos(const char *caller); /* show current known state
104                                               of area */
105 void strat_dump_conf(void);
106 void strat_reset_infos(void); /* reset current known state */
107 void strat_preinit(void);
108 void strat_init(void);
109 void strat_exit(void);
110 void strat_dump_flags(void);
111 void strat_goto_near(int16_t x, int16_t y, uint16_t dist);
112 uint8_t strat_main(void);
113 void strat_event(void *dummy);
114
115 #endif