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)) \
29 #define LED1_ON() sbi(PORTJ, 2)
30 #define LED1_OFF() cbi(PORTJ, 2)
31 #define LED1_TOGGLE() LED_TOGGLE(PORTJ, 2)
33 #define LED2_ON() sbi(PORTL, 7)
34 #define LED2_OFF() cbi(PORTL, 7)
35 #define LED2_TOGGLE() LED_TOGGLE(PORTL, 7)
37 #define LED3_ON() sbi(PORTJ, 3)
38 #define LED3_OFF() cbi(PORTJ, 3)
39 #define LED3_TOGGLE() LED_TOGGLE(PORTJ, 3)
41 #define LED4_ON() sbi(PORTL, 6)
42 #define LED4_OFF() cbi(PORTL, 6)
43 #define LED4_TOGGLE() LED_TOGGLE(PORTL, 6)
45 #define BRAKE_DDR() do { DDRJ |= 0xF0; } while(0)
46 #define BRAKE_ON() do { PORTJ |= 0xF0; } while(0)
47 #define BRAKE_OFF() do { PORTJ &= 0x0F; } while(0)
49 /* only 90 seconds, don't forget it :) */
52 /* decrease track to decrease angle */
53 #define EXT_TRACK_MM 302.0188
54 #define VIRTUAL_TRACK_MM EXT_TRACK_MM
56 #define ROBOT_LENGTH 320
57 #define ROBOT_WIDTH 320
59 /* it is a 2048 imps -> 8192 because we see 1/4 period
60 * and diameter: 55mm -> perimeter 173mm
62 /* increase it to go further */
63 #define IMP_ENCODERS 2048
64 #define WHEEL_DIAMETER_MM 55.0
65 #define WHEEL_PERIM_MM (WHEEL_DIAMETER_MM * M_PI)
67 #define DIST_IMP_MM (((IMP_ENCODERS*4) / WHEEL_PERIM_MM) * IMP_COEF)
69 #define RIGHT_ENCODER ((void *)0)
70 #define LEFT_ENCODER ((void *)1)
71 #define LEFT_COBROLLER_ENCODER ((void *)2)
72 #define RIGHT_COBROLLER_ENCODER ((void *)3)
74 #define RIGHT_PWM ((void *)&gen.pwm1_4A)
75 #define LEFT_PWM ((void *)&gen.pwm2_4B)
76 #define LEFT_COBROLLER_PWM ((void *)&gen.pwm3_1A)
77 #define RIGHT_COBROLLER_PWM ((void *)&gen.pwm4_1B)
79 #define SUPPORT_BALLS_R_SERVO ((void *)&gen.servo2)
80 #define SUPPORT_BALLS_L_SERVO ((void *)&gen.servo3)
84 #define E_USER_STRAT 194
85 #define E_USER_I2C_PROTO 195
86 #define E_USER_SENSOR 196
94 #define I2C_POLL_PRIO 20
95 #define EEPROM_TIME_PRIO 10
97 #define CS_PERIOD 5000L
101 /* generic to all boards */
103 /* command line interface */
105 char prompt[RDLINE_PROMPT_SIZE];
108 struct pwm_ng pwm1_4A;
109 struct pwm_ng pwm2_4B;
110 struct pwm_ng pwm3_1A;
111 struct pwm_ng pwm4_1B;
114 struct pwm_ng servo1;
115 struct pwm_ng servo2;
116 struct pwm_ng servo3;
117 struct pwm_ng servo4;
123 uint8_t logs[NB_LOGS+1];
131 struct pid_filter pid;
132 struct quadramp_filter qr;
133 struct blocking_detection bd;
136 /* mainboard specific */
138 #define DO_ENCODERS 1
145 uint8_t flags; /* misc flags */
147 /* control systems */
148 struct cs_block angle;
149 struct cs_block distance;
150 struct cs_block left_cobroller;
151 struct cs_block right_cobroller;
153 /* x,y positionning */
154 struct robot_system rs;
155 struct robot_position pos;
156 struct trajectory traj;
160 volatile int16_t speed_a; /* current angle speed */
161 volatile int16_t speed_d; /* current dist speed */
162 int32_t pwm_l; /* current left pwm */
163 int32_t pwm_r; /* current right pwm */
166 /* state of cobboard, synchronized through i2c */
170 int16_t left_cobroller_speed;
171 int16_t right_cobroller_speed;
175 /* state of ballboard, synchronized through i2c */
180 extern struct genboard gen;
181 extern struct mainboard mainboard;
182 extern struct cobboard cobboard;
183 extern struct ballboard ballboard;
185 /* start the bootloader */
186 void bootloader(void);
188 #define WAIT_COND_OR_TIMEOUT(cond, timeout) \
190 microseconds __us = time_get_us2(); \
193 if (time_get_us2() - __us > (timeout)*1000L) {\
199 DEBUG(E_USER_STRAT, "cond is true at line %d",\
202 DEBUG(E_USER_STRAT, "timeout at line %d", \