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 #define LED_TOGGLE(port, bit) do { \
23 if (port & _BV(bit)) \
52 #define LED1_ON() sbi(PORTJ, 2)
53 #define LED1_OFF() cbi(PORTJ, 2)
54 #define LED1_TOGGLE() LED_TOGGLE(PORTJ, 2)
56 #define LED2_ON() sbi(PORTL, 7)
57 #define LED2_OFF() cbi(PORTL, 7)
58 #define LED2_TOGGLE() LED_TOGGLE(PORTL, 7)
60 #define LED3_ON() sbi(PORTJ, 3)
61 #define LED3_OFF() cbi(PORTJ, 3)
62 #define LED3_TOGGLE() LED_TOGGLE(PORTJ, 3)
64 #define LED4_ON() sbi(PORTL, 6)
65 #define LED4_OFF() cbi(PORTL, 6)
66 #define LED4_TOGGLE() LED_TOGGLE(PORTL, 6)
68 #define BRAKE_DDR() do { DDRJ |= 0xF0; } while(0)
69 #define BRAKE_ON() do { PORTJ |= 0xF0; } while(0)
70 #define BRAKE_OFF() do { PORTJ &= 0x0F; } while(0)
73 /* only 90 seconds, don't forget it :) */
76 /* decrease track to decrease angle */
77 #define EXT_TRACK_MM 304.61875
78 #define VIRTUAL_TRACK_MM EXT_TRACK_MM
80 #define ROBOT_HALF_LENGTH_FRONT 130
81 #define ROBOT_HALF_LENGTH_REAR 120
82 #define ROBOT_WIDTH 320
84 /* it is a 1024 imps -> 4096 because we see 1/4 period
85 * and diameter: 55mm -> perimeter 134mm
86 * dist_imp_mm = 4096/134 x 10 -> 304 */
87 /* increase it to go further */
88 #define IMP_ENCODERS 1024
89 #define WHEEL_DIAMETER_MM 42.9
90 #define WHEEL_PERIM_MM (WHEEL_DIAMETER_MM * M_PI)
92 #define DIST_IMP_MM (((IMP_ENCODERS*4) / WHEEL_PERIM_MM) * IMP_COEF)
94 #define RIGHT_ENCODER ((void *)0)
95 #define LEFT_ENCODER ((void *)1)
96 #define LEFT_COBROLLER_ENCODER ((void *)2)
97 #define RIGHT_COBROLLER_ENCODER ((void *)3)
99 #define RIGHT_PWM ((void *)&gen.pwm1_4A)
100 #define LEFT_PWM ((void *)&gen.pwm2_4B)
101 #define LEFT_COBROLLER_PWM ((void *)&gen.pwm3_1A)
102 #define RIGHT_COBROLLER_PWM ((void *)&gen.pwm4_1B)
104 #define SUPPORT_BALLS_R_SERVO ((void *)&gen.servo2)
105 #define SUPPORT_BALLS_L_SERVO ((void *)&gen.servo3)
109 #define E_USER_STRAT 194
110 #define E_USER_I2C_PROTO 195
111 #define E_USER_SENSOR 196
112 #define E_USER_CS 197
115 #define TIME_PRIO 160
118 #define STRAT_PRIO 30
119 #define I2C_POLL_PRIO 20
120 #define EEPROM_TIME_PRIO 10
122 #define CS_PERIOD 5000L /* in microsecond */
123 #define CS_HZ (1000000. / CS_PERIOD)
127 /* generic to all boards */
129 /* command line interface */
131 char prompt[RDLINE_PROMPT_SIZE];
134 struct pwm_ng pwm1_4A;
135 struct pwm_ng pwm2_4B;
136 struct pwm_ng pwm3_1A;
137 struct pwm_ng pwm4_1B;
140 struct pwm_ng servo1;
141 struct pwm_ng servo2;
142 struct pwm_ng servo3;
143 struct pwm_ng servo4;
149 uint8_t logs[NB_LOGS+1];
157 struct pid_filter pid;
158 struct quadramp_filter qr;
159 struct blocking_detection bd;
162 /* mainboard specific */
164 #define DO_ENCODERS 1
171 uint8_t flags; /* misc flags */
173 /* control systems */
174 struct cs_block angle;
175 struct cs_block distance;
176 struct cs_block left_cobroller;
177 struct cs_block right_cobroller;
179 /* x,y positionning */
180 struct robot_system rs;
181 struct robot_position pos;
182 struct trajectory traj;
186 volatile int16_t speed_a; /* current angle speed */
187 volatile int16_t speed_d; /* current dist speed */
188 int32_t pwm_l; /* current left pwm */
189 int32_t pwm_r; /* current right pwm */
192 /* state of cobboard, synchronized through i2c */
196 int16_t left_cobroller_speed;
197 int16_t right_cobroller_speed;
201 /* state of ballboard, synchronized through i2c */
208 extern struct genboard gen;
209 extern struct mainboard mainboard;
210 extern struct cobboard cobboard;
211 extern struct ballboard ballboard;
213 /* start the bootloader */
214 void bootloader(void);
216 #define WAIT_COND_OR_TIMEOUT(cond, timeout) \
218 microseconds __us = time_get_us2(); \
221 if (time_get_us2() - __us > (timeout)*1000L) {\
227 DEBUG(E_USER_STRAT, "cond is true at line %d",\
230 DEBUG(E_USER_STRAT, "timeout at line %d", \