avant la coupe de belgique
[aversive.git] / projects / microb2010 / mainboard / main.h
index 7f21058..367718f 100755 (executable)
                        port |= _BV(bit);       \
        } while(0)
 
+#ifdef HOST_VERSION
+#define LED1_ON()
+#define LED1_OFF()
+#define LED1_TOGGLE()
+
+#define LED2_ON()
+#define LED2_OFF()
+#define LED2_TOGGLE()
+
+#define LED3_ON()
+#define LED3_OFF()
+#define LED3_TOGGLE()
+
+#define LED4_ON()
+#define LED4_OFF()
+#define LED4_TOGGLE()
+
+#define BRAKE_DDR()
+#define BRAKE_ON()
+#define BRAKE_OFF()
+
+#else
+
 #define LED1_ON()      sbi(PORTJ, 2)
 #define LED1_OFF()     cbi(PORTJ, 2)
 #define LED1_TOGGLE()  LED_TOGGLE(PORTJ, 2)
 
-#define LED2_ON()      sbi(PORTL, 7)
-#define LED2_OFF()     cbi(PORTL, 7)
-#define LED2_TOGGLE()  LED_TOGGLE(PORTL, 7)
+#define LED2_ON()      sbi(PORTJ, 3)
+#define LED2_OFF()     cbi(PORTJ, 3)
+#define LED2_TOGGLE()  LED_TOGGLE(PORTJ, 3)
 
-#define LED3_ON()      sbi(PORTJ, 3)
-#define LED3_OFF()     cbi(PORTJ, 3)
-#define LED3_TOGGLE()  LED_TOGGLE(PORTJ, 3)
+#define LED3_ON()      sbi(PORTL, 7)
+#define LED3_OFF()     cbi(PORTL, 7)
+#define LED3_TOGGLE()  LED_TOGGLE(PORTL, 7)
 
 #define LED4_ON()      sbi(PORTL, 6)
 #define LED4_OFF()     cbi(PORTL, 6)
 #define BRAKE_DDR()     do { DDRJ |= 0xF0; } while(0)
 #define BRAKE_ON()      do { PORTJ |= 0xF0; } while(0)
 #define BRAKE_OFF()     do { PORTJ &= 0x0F; } while(0)
+#endif
 
 /* only 90 seconds, don't forget it :) */
 #define MATCH_TIME 89
 
 /* decrease track to decrease angle */
-#define EXT_TRACK_MM 302.0188
+#define EXT_TRACK_MM 304.61875
 #define VIRTUAL_TRACK_MM EXT_TRACK_MM
 
-#define ROBOT_LENGTH 320
+#define ROBOT_HALF_LENGTH_FRONT 130
+#define ROBOT_HALF_LENGTH_REAR 120
 #define ROBOT_WIDTH 320
 
-/* it is a 2048 imps -> 8192 because we see 1/4 period
- * and diameter: 55mm -> perimeter 173mm 
- * 8192/173 -> 473 */
+/* it is a 1024 imps -> 4096 because we see 1/4 period
+ * and diameter: 55mm -> perimeter 134mm
+ * dist_imp_mm = 4096/134 x 10 -> 304 */
 /* increase it to go further */
-#define IMP_ENCODERS 2048
-#define WHEEL_DIAMETER_MM 55.0
+#define IMP_ENCODERS 1024
+#define WHEEL_DIAMETER_MM 42.9
 #define WHEEL_PERIM_MM (WHEEL_DIAMETER_MM * M_PI)
 #define IMP_COEF 10.
 #define DIST_IMP_MM (((IMP_ENCODERS*4) / WHEEL_PERIM_MM) * IMP_COEF)
 
-#define LEFT_ENCODER            ((void *)1)
 #define RIGHT_ENCODER           ((void *)0)
+#define LEFT_ENCODER            ((void *)1)
 #define LEFT_COBROLLER_ENCODER  ((void *)2)
 #define RIGHT_COBROLLER_ENCODER ((void *)3)
 
-#define LEFT_PWM            ((void *)&gen.pwm1_4A)
-#define RIGHT_PWM           ((void *)&gen.pwm2_4B)
+#define RIGHT_PWM           ((void *)&gen.pwm1_4A)
+#define LEFT_PWM            ((void *)&gen.pwm2_4B)
 #define LEFT_COBROLLER_PWM  ((void *)&gen.pwm3_1A)
 #define RIGHT_COBROLLER_PWM ((void *)&gen.pwm4_1B)
 
+#define SUPPORT_BALLS_R_SERVO ((void *)&gen.servo2)
+#define SUPPORT_BALLS_L_SERVO ((void *)&gen.servo3)
+
+
 /** ERROR NUMS */
 #define E_USER_STRAT           194
 #define E_USER_I2C_PROTO       195
 #define I2C_POLL_PRIO       20
 #define EEPROM_TIME_PRIO    10
 
-#define CS_PERIOD 5000L
+#define CS_PERIOD 5000L /* in microsecond */ 
+#define CS_HZ (1000000. / CS_PERIOD)
 
 #define NB_LOGS 4
 
@@ -111,7 +141,7 @@ struct genboard {
        struct pwm_ng servo2;
        struct pwm_ng servo3;
        struct pwm_ng servo4;
-       
+
        /* ax12 interface */
        AX12 ax12;
 
@@ -138,6 +168,7 @@ struct mainboard {
 #define DO_BD       16
 #define DO_TIMER    32
 #define DO_POWER    64
+#define DO_ERRBLOCKING 128
        uint8_t flags;                /* misc flags */
 
        /* control systems */
@@ -161,19 +192,24 @@ struct mainboard {
 
 /* state of cobboard, synchronized through i2c */
 struct cobboard {
-       uint8_t mode;   
+       uint8_t mode;
        uint8_t status;
+       int16_t left_cobroller_speed;
+       int16_t right_cobroller_speed;
+       uint8_t cob_count;
 };
 
 /* state of ballboard, synchronized through i2c */
 struct ballboard {
+       volatile uint8_t mode;
        uint8_t status;
+       uint8_t ball_count;
 };
 
 extern struct genboard gen;
 extern struct mainboard mainboard;
-extern struct cobboard cobboard;
-extern struct ballboard ballboard;
+extern volatile struct cobboard cobboard;
+extern volatile struct ballboard ballboard;
 
 /* start the bootloader */
 void bootloader(void);