cobboard
[aversive.git] / projects / microb2010 / cobboard / state.c
index 8e8affc..3308405 100644 (file)
@@ -114,6 +114,13 @@ static uint8_t state_cob_color(uint8_t side)
                return 0;
 }
 
+/* return true if the cob is correctly inside */
+static uint8_t state_cob_inside(void)
+{
+       return sensor_get(S_COB_INSIDE_L) &&
+               sensor_get(S_COB_INSIDE_R);
+}
+
 /* set a new state, return 0 on success */
 int8_t state_set_mode(uint8_t mode)
 {
@@ -139,6 +146,7 @@ static uint8_t state_want_exit(void)
                return 0;
        if (vt100_parser(&local_vt100, c) == KEY_CTRL_C)
                return 1;
+       printf_P(PSTR("CTRL-C\r\n"));
        return 0;
 }
 
@@ -155,29 +163,45 @@ static void state_do_harvest(uint8_t side)
        /* if there is no cob, return */
        if (state_cob_present(side))
                return;
-               
+
        /* if it is black, nothing to do */
        if (state_cob_color(side) == I2C_COB_BLACK)
                return;
 
        /* eat the cob */
        spickle_pack(side);
-       state_debug_wait_key_pressed();
+       /* xxx */
+       time_wait_ms(250);
+       left_cobroller_on();
        delay = spickle_get_pack_delay(side);
-       time_wait_ms(delay);
+
+       WAIT_COND_OR_TIMEOUT(state_cob_inside(), delay);
 
        /* redeploy the spickle */
        spickle_deploy(side);
        state_debug_wait_key_pressed();
 
+       /* let the cob go */
+       servo_carry_open();
+       wait_ms(300); /* XXX */
+       state_debug_wait_key_pressed();
+
        cob_count ++;
 
        /* store it */
        shovel_up();
        wait_ms(200);
        state_debug_wait_key_pressed();
+
+       /* close the carry servos */
+       servo_carry_close();
+       wait_ms(300); /* XXX */
+       state_debug_wait_key_pressed();
+
        shovel_down();
+       left_cobroller_off();
        state_debug_wait_key_pressed();
+       time_wait_ms(500);
 }
 
 /* eject cobs */
@@ -185,10 +209,12 @@ static void state_do_eject(void)
 {
        cob_count = 0;
        shovel_mid();
+       servo_carry_open();
        servo_door_open();
        time_wait_ms(2000);
        shovel_down();
        servo_door_close();
+       servo_carry_close();
 }
 
 /* main state machine */
@@ -205,7 +231,8 @@ void state_machine(void)
                /* pack/deply spickles, enable/disable roller */
                if (L_DEPLOY(state_mode)) {
                        spickle_deploy(I2C_LEFT_SIDE);
-                       left_cobroller_on();
+                       //left_cobroller_on();
+                       left_cobroller_off();
                }
                else {
                        spickle_pack(I2C_LEFT_SIDE);
@@ -239,6 +266,7 @@ void state_init(void)
        vt100_init(&local_vt100);
        shovel_down();
        servo_door_close();
+       servo_carry_close();
        spickle_pack(I2C_LEFT_SIDE);
        spickle_pack(I2C_RIGHT_SIDE);
        state_mode = 0;