2 * Copyright Droids Corporation (2009)
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: main.h,v 1.10 2009-11-08 17:24:33 zer0 Exp $
22 /* was sensorboard in 2009 */
24 #define LED_TOGGLE(port, bit) do { \
25 if (port & _BV(bit)) \
54 #define LED1_ON() sbi(PORTJ, 2)
55 #define LED1_OFF() cbi(PORTJ, 2)
56 #define LED1_TOGGLE() LED_TOGGLE(PORTJ, 2)
58 #define LED2_ON() sbi(PORTJ, 3)
59 #define LED2_OFF() cbi(PORTJ, 3)
60 #define LED2_TOGGLE() LED_TOGGLE(PORTJ, 3)
62 #define LED3_ON() sbi(PORTL, 7)
63 #define LED3_OFF() cbi(PORTL, 7)
64 #define LED3_TOGGLE() LED_TOGGLE(PORTL, 7)
66 #define LED4_ON() sbi(PORTL, 6)
67 #define LED4_OFF() cbi(PORTL, 6)
68 #define LED4_TOGGLE() LED_TOGGLE(PORTL, 6)
70 #define BRAKE_DDR() do { DDRJ |= 0xF0; } while(0)
71 #define BRAKE_ON() do { PORTJ |= 0xF0; } while(0)
72 #define BRAKE_OFF() do { PORTJ &= 0x0F; } while(0)
75 /* only 90 seconds, don't forget it :) */
78 /* decrease track to decrease angle */
79 #define EXT_TRACK_MM 304.61875
80 #define VIRTUAL_TRACK_MM EXT_TRACK_MM
82 #define ROBOT_HALF_LENGTH_FRONT 130
83 #define ROBOT_HALF_LENGTH_REAR 120
84 #define ROBOT_WIDTH 320
87 #define ROBOT_ANGLE_FRONT 0.
89 #define ROBOT_ANGLE_FRONT 0.75 // 0.27
92 /* it is a 1024 imps -> 4096 because we see 1/4 period
93 * and diameter: 55mm -> perimeter 134mm
94 * dist_imp_mm = 4096/134 x 10 -> 304 */
95 /* increase it to go further */
96 #define IMP_ENCODERS 1000
97 #define WHEEL_DIAMETER_MM 42.9
98 #define WHEEL_PERIM_MM (WHEEL_DIAMETER_MM * M_PI)
100 #define DIST_IMP_MM (((IMP_ENCODERS*4) / WHEEL_PERIM_MM) * IMP_COEF)
102 #define RIGHT_ENCODER ((void *)0)
103 #define LEFT_ENCODER ((void *)1)
104 #define LEFT_COBROLLER_ENCODER ((void *)2)
105 #define RIGHT_COBROLLER_ENCODER ((void *)3)
107 #define RIGHT_PWM ((void *)&gen.pwm1_4A)
108 #define LEFT_PWM ((void *)&gen.pwm2_4B)
109 #define LEFT_COBROLLER_PWM ((void *)&gen.pwm3_1A)
110 #define RIGHT_COBROLLER_PWM ((void *)&gen.pwm4_1B)
112 #define SUPPORT_BALLS_R_SERVO ((void *)&gen.servo2)
113 #define SUPPORT_BALLS_L_SERVO ((void *)&gen.servo3)
117 #define E_USER_STRAT 194
118 #define E_USER_I2C_PROTO 195
119 #define E_USER_SENSOR 196
120 #define E_USER_CS 197
123 #define TIME_PRIO 160
126 #define STRAT_PRIO 30
127 #define I2C_POLL_PRIO 20
128 #define BEACON_PRIO 15
129 #define EEPROM_TIME_PRIO 10
131 #define CS_PERIOD ((5000L/SCHEDULER_UNIT)*SCHEDULER_UNIT) /* in microsecond */
132 #define CS_HZ (1000000. / CS_PERIOD)
136 /* generic to all boards */
138 /* command line interface */
140 char prompt[RDLINE_PROMPT_SIZE];
143 struct pwm_ng pwm1_4A;
144 struct pwm_ng pwm2_4B;
145 struct pwm_ng pwm3_1A;
146 struct pwm_ng pwm4_1B;
149 struct pwm_ng servo1;
150 struct pwm_ng servo2;
151 struct pwm_ng servo3;
152 struct pwm_ng servo4;
158 uint8_t logs[NB_LOGS+1];
166 struct pid_filter pid;
167 struct quadramp_filter qr;
168 struct blocking_detection bd;
171 /* mainboard specific */
173 #define DO_ENCODERS 1
180 #define DO_ERRBLOCKING 128
181 uint8_t flags; /* misc flags */
183 /* control systems */
184 struct cs_block angle;
185 struct cs_block distance;
186 struct cs_block left_cobroller;
187 struct cs_block right_cobroller;
189 /* x,y positionning */
190 struct robot_system rs;
191 struct robot_position pos;
192 struct trajectory traj;
196 volatile int16_t speed_a; /* current angle speed */
197 volatile int16_t speed_d; /* current dist speed */
198 int32_t pwm_l; /* current left pwm */
199 int32_t pwm_r; /* current right pwm */
202 /* state of cobboard, synchronized through i2c */
208 int16_t left_cobroller_speed;
209 int16_t right_cobroller_speed;
213 /* state of ballboard, synchronized through i2c */
215 volatile uint8_t mode;
226 extern struct genboard gen;
227 extern struct mainboard mainboard;
228 extern volatile struct cobboard cobboard;
229 extern volatile struct ballboard ballboard;
231 /* start the bootloader */
232 void bootloader(void);
234 #define WAIT_COND_OR_TIMEOUT(cond, timeout) \
236 microseconds __us = time_get_us2(); \
239 if (time_get_us2() - __us > (timeout)*1000L) {\
245 DEBUG(E_USER_STRAT, "cond is true at line %d",\
248 DEBUG(E_USER_STRAT, "timeout at line %d", \