]> git.droids-corp.org - aversive.git/commitdiff
optim cobboard
authorzer0 <zer0@carbon.local>
Tue, 27 Apr 2010 22:03:28 +0000 (00:03 +0200)
committerzer0 <zer0@carbon.local>
Tue, 27 Apr 2010 22:03:28 +0000 (00:03 +0200)
projects/microb2010/mainboard/commands_mainboard.c
projects/microb2010/mainboard/i2c_protocol.c
projects/microb2010/mainboard/i2c_protocol.h
projects/microb2010/mainboard/strat.c
projects/microb2010/mainboard/strat_corn.c
projects/microb2010/mainboard/strat_corn.h
projects/microb2010/mainboard/strat_db.c

index 7c58bb995367a77498ec06cbccf2ba52209f7eea..ee0ffa4524f71377431343dd4e71e0036bf0c76c 100644 (file)
@@ -779,7 +779,7 @@ static void cmd_cobboard_setmode2_parsed(void *parsed_result, void *data)
        }
        else if (!strcmp_P(res->arg1, PSTR("harvest"))) {
                i2c_cobboard_set_mode(I2C_COBBOARD_MODE_HARVEST);
-               i2c_cobboard_harvest(side);
+               i2c_cobboard_autoharvest(side);
        }
        else if (!strcmp_P(res->arg1, PSTR("pack"))) {
                i2c_cobboard_set_mode(I2C_COBBOARD_MODE_HARVEST);
index d264622671c3e89fa013e9f7f13f15804a249fe3..9908f1a4541317a9f8f7ba06bf0f268ed772d54b 100644 (file)
@@ -426,7 +426,7 @@ int8_t i2c_cobboard_pack(uint8_t side)
        return i2c_cobboard_set_spickle(side, 0);
 }
 
-int8_t i2c_cobboard_harvest(uint8_t side)
+int8_t i2c_cobboard_autoharvest(uint8_t side)
 {
        return i2c_cobboard_set_spickle(side,
                                        I2C_COBBOARD_SPK_DEPLOY |
index 20c8ada5738c55fb70520be1dcc09b48aa919ee1..b107c44582029a264d18af029370d202456c8ab9 100644 (file)
@@ -37,7 +37,7 @@ int8_t i2c_led_control(uint8_t addr, uint8_t led, uint8_t state);
 
 int8_t i2c_cobboard_set_mode(uint8_t mode);
 int8_t i2c_cobboard_pack(uint8_t side);
-int8_t i2c_cobboard_harvest(uint8_t side);
+int8_t i2c_cobboard_autoharvest(uint8_t side);
 int8_t i2c_cobboard_deploy(uint8_t side);
 int8_t i2c_ballboard_set_mode(uint8_t mode);
 
index 2c6042828a6b74e1593388d8e8b7acdfc5acc315..38397387431d4aed1aac4720d1482ef2d05b8cac 100644 (file)
@@ -67,6 +67,7 @@
 #define COL_DISP_MARGIN 400 /* stop 40 cm in front of dispenser */
 #define COL_SCAN_PRE_MARGIN 250
 
+static uint8_t strat_running = 0;
 struct strat_conf strat_conf;
 
 /*************************************************************/
@@ -100,22 +101,19 @@ void strat_conf_dump(const char *caller)
 /* call it just before launching the strat */
 void strat_init(void)
 {
+#ifdef HOST_VERSION
        position_set(&mainboard.pos, 298.16,
                     COLOR_Y(308.78), COLOR_A(70.00));
-
-       /* XXX init rollers, .. */
-
-       strat_db_init();
+#endif
 
        /* we consider that the color is correctly set */
-
+       strat_running = 1;
+       strat_db_init();
        strat_set_speed(SPEED_DIST_FAST, SPEED_ANGLE_FAST);
        time_reset();
        interrupt_traj_reset();
 
        i2c_cobboard_set_mode(I2C_COBBOARD_MODE_HARVEST);
-       i2c_cobboard_harvest(I2C_LEFT_SIDE);
-       i2c_cobboard_harvest(I2C_RIGHT_SIDE);
        i2c_ballboard_set_mode(I2C_BALLBOARD_MODE_HARVEST);
 
        /* used in strat_base for END_TIMER */
@@ -131,6 +129,7 @@ void strat_exit(void)
        uint8_t flags;
 #endif
 
+       strat_running = 0;
        mainboard.flags &= ~(DO_TIMER);
        strat_hardstop();
        time_reset();
@@ -144,11 +143,16 @@ void strat_exit(void)
 #endif
 }
 
-/* called periodically */
+/* called periodically (10ms) */
 void strat_event(void *dummy)
 {
        uint8_t flags;
        uint8_t lcob, rcob;
+       uint8_t lidx, ridx;
+
+       /* ignore when strat is not running */
+       if (strat_running == 0)
+               return;
 
        IRQ_LOCK(flags);
        lcob = ballboard.lcob;
@@ -157,14 +161,41 @@ void strat_event(void *dummy)
        ballboard.rcob = I2C_COB_NONE;
        IRQ_UNLOCK(flags);
 
-       if (lcob == I2C_COB_WHITE)
-               DEBUG(E_USER_STRAT, "lcob white");
-       if (lcob == I2C_COB_BLACK)
-               DEBUG(E_USER_STRAT, "lcob black");
-       if (rcob == I2C_COB_WHITE)
-               DEBUG(E_USER_STRAT, "rcob white");
-       if (rcob == I2C_COB_BLACK)
-               DEBUG(E_USER_STRAT, "rcob black");
+       /* XXX take opponent position into account */
+
+
+       /* detect cob on left side */
+       if (corn_is_near(&lidx, I2C_LEFT_SIDE)) {
+               if (lcob != I2C_COB_NONE) {
+                       corn_set_color(strat_db.corn_table[lidx], lcob);
+                       DEBUG(E_USER_STRAT, "lcob %s %d",
+                             lcob == I2C_COB_WHITE ? "white" : "black", lidx);
+               }
+               if (strat_db.corn_table[lidx]->corn.color == I2C_COB_WHITE)
+                       i2c_cobboard_autoharvest(I2C_LEFT_SIDE);
+               else
+                       i2c_cobboard_deploy(I2C_LEFT_SIDE);
+       }
+       else {
+               i2c_cobboard_deploy(I2C_LEFT_SIDE);
+       }
+
+       /* detect cob on right side */
+       if (corn_is_near(&ridx, I2C_RIGHT_SIDE)) {
+               if (rcob != I2C_COB_NONE) {
+                       corn_set_color(strat_db.corn_table[ridx], rcob);
+                       DEBUG(E_USER_STRAT, "rcob %s %d",
+                             rcob == I2C_COB_WHITE ? "white" : "black", ridx);
+               }
+               if (strat_db.corn_table[ridx]->corn.color == I2C_COB_WHITE)
+                       i2c_cobboard_autoharvest(I2C_RIGHT_SIDE);
+               else
+                       i2c_cobboard_deploy(I2C_RIGHT_SIDE);
+       }
+       else {
+               i2c_cobboard_deploy(I2C_RIGHT_SIDE);
+       }
+
 
        /* limit speed when opponent is close */
        strat_limit_speed();
index 5224787a5976685669d9ff17431d283cc471ba1a..7fa64c4ed086ec98661160d9276bf26235688252 100644 (file)
@@ -66,9 +66,8 @@
 #include "sensor.h"
 #include "actuator.h"
 
-#if 0
 /* return 1 if there is a corn near, and fill the index ptr */
-uint8_t corn_is_near(int8_t *corn_idx, uint8_t side)
+int8_t corn_is_near(uint8_t *corn_idx, uint8_t side)
 {
 #define SENSOR_CORN_DIST  225
 #define SENSOR_CORN_ANGLE 90
@@ -91,11 +90,11 @@ uint8_t corn_is_near(int8_t *corn_idx, uint8_t side)
        y_corn_int = y_corn;
 
        wp = xycoord_to_corn_idx(&x_corn_int, &y_corn_int);
-       if (wp->corn.idx < 0)
+       if (wp == NULL)
                return 0;
+       *corn_idx = wp->corn.idx;
        return 1;
 }
-#endif
 
 /*
  * - send the correct commands to the spickles
index ca4a7d6aee737589b7902801d267cd025aa7c60b..ac806d3575858482fca68de4938535b0333883d2 100644 (file)
@@ -32,6 +32,8 @@ struct line_2pts {
        point_t p2;
 };
 
+int8_t corn_is_near(uint8_t *corn_idx, uint8_t side);
+
 void num2line(struct line_2pts *l, uint8_t dir, uint8_t num);
 
 uint8_t line2line(uint8_t dir1, uint8_t num1,
index 57c20bab93ee116e44341e98b198a6db6fc51447..18db6ea1f2c576d3da816931228e25f0cc8cf914 100644 (file)
@@ -289,6 +289,8 @@ void corn_set_color(struct waypoint_db *wp, uint8_t color)
        wp->corn.color = color;
        if (color == I2C_COB_UNKNOWN)
                return;
+       if (wp->corn.color != I2C_COB_UNKNOWN)
+               return;
        corn_deduct_other(wp->corn.idx, color);
        symidx = corn_get_sym_idx(wp->corn.idx);
        strat_db.corn_table[symidx]->corn.color = color;