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.8 2009-05-02 10:08:09 zer0 Exp $
22 #define LED_TOGGLE(port, bit) do { \
23 if (port & _BV(bit)) \
29 #define LED1_ON() sbi(PORTB, 4)
30 #define LED1_OFF() cbi(PORTB, 4)
31 #define LED1_TOGGLE() LED_TOGGLE(PORTB, 4)
33 #define LED2_ON() sbi(PORTG, 3)
34 #define LED2_OFF() cbi(PORTG, 3)
35 #define LED2_TOGGLE() LED_TOGGLE(PORTG, 3)
37 #define LED3_ON() sbi(PORTG, 4)
38 #define LED3_OFF() cbi(PORTG, 4)
39 #define LED3_TOGGLE() LED_TOGGLE(PORTG, 4)
41 #define BRAKE_DDR() do { DDRF |= 0x01; } while(0)
42 #define BRAKE_ON() do { PORTF |= 0x01; } while(0)
43 #define BRAKE_OFF() do { PORTF &= 0xFE; } while(0)
45 /* only 90 seconds, don't forget it :) */
48 /* decrease track to decrease angle */
49 #define EXT_TRACK_MM 302.0188
50 #define VIRTUAL_TRACK_MM EXT_TRACK_MM
52 #define ROBOT_LENGTH 320
53 #define ROBOT_WIDTH 320
55 /* it is a 2048 imps -> 8192 because we see 1/4 period
56 * and diameter: 55mm -> perimeter 173mm
58 /* increase it to go further */
59 #define IMP_ENCODERS 2048
60 #define WHEEL_DIAMETER_MM 55.0
61 #define WHEEL_PERIM_MM (WHEEL_DIAMETER_MM * M_PI)
63 #define DIST_IMP_MM (((IMP_ENCODERS*4) / WHEEL_PERIM_MM) * IMP_COEF)
65 #define LEFT_ENCODER ((void *)1)
66 #define RIGHT_ENCODER ((void *)0)
68 #define LEFT_PWM ((void *)&gen.pwm3_3A)
69 #define RIGHT_PWM ((void *)&gen.pwm4_3B)
71 #define FESSOR_PWM ((void *)&gen.pwm2_1B)
72 #define FESSOR_ENC ((void *)2)
74 #define WHEEL_PWM ((void *)&gen.pwm1_1A)
75 #define WHEEL_ENC ((void *)3)
77 #define ELEVATOR_PWM ((void *)&gen.pwm3_3A)
78 #define ELEVATOR_ENC ((void *)0)
81 #define E_USER_STRAT 194
82 #define E_USER_I2C_PROTO 195
83 #define E_USER_SENSOR 196
89 #define FESSOR_PRIO 130
90 #define ELEVATOR_PRIO 130
93 #define I2C_POLL_PRIO 20
94 #define EEPROM_TIME_PRIO 10
96 #define CS_PERIOD 5000L
100 /* generic to all boards */
102 /* command line interface */
104 char prompt[RDLINE_PROMPT_SIZE];
107 struct pwm_ng pwm1_1A;
108 struct pwm_ng pwm2_1B;
109 struct pwm_ng pwm3_3A;
110 struct pwm_ng pwm4_3B;
113 uint8_t logs[NB_LOGS+1];
121 struct pid_filter pid;
122 struct quadramp_filter qr;
123 struct blocking_detection bd;
126 /* mainboard specific */
128 #define DO_ENCODERS 1
135 uint8_t flags; /* misc flags */
137 /* control systems */
138 struct cs_block angle;
139 struct cs_block distance;
140 struct cs_block fessor;
141 struct cs_block wheel;
142 struct cs_block elevator;
144 /* x,y positionning */
145 struct robot_system rs;
146 struct robot_position pos;
147 struct trajectory traj;
151 volatile int16_t speed_a; /* current angle speed */
152 volatile int16_t speed_d; /* current dist speed */
153 int32_t pwm_l; /* current left pwm */
154 int32_t pwm_r; /* current right pwm */
155 uint8_t enable_pickup_wheels; /* these PWM are on sensorboard */
159 /* state of mechboard, synchronized through i2c */
164 uint8_t column_flags;
172 /* currents (for left arm, we can just read it on adc) */
173 int16_t pump_right1_current;
174 int16_t pump_right2_current;
176 /* pwm for lintel servos */
177 uint16_t servo_lintel_left;
178 uint16_t servo_lintel_right;
181 /* state of sensorboard, synchronized through i2c */
191 #define I2C_SCAN_DONE 1
193 #define I2C_COLUMN_NO_DROPZONE -1
199 extern struct genboard gen;
200 extern struct mainboard mainboard;
201 extern struct mechboard mechboard;
202 extern struct sensorboard sensorboard;
204 /* start the bootloader */
205 void bootloader(void);
207 #define WAIT_COND_OR_TIMEOUT(cond, timeout) \
209 microseconds __us = time_get_us2(); \
212 if (time_get_us2() - __us > (timeout)*1000L) {\
218 DEBUG(E_USER_STRAT, "cond is true at line %d",\
221 DEBUG(E_USER_STRAT, "timeout at line %d", \