]> git.droids-corp.org - aversive.git/commitdiff
traj update
authorzer0 <zer0@carbon.local>
Fri, 30 Apr 2010 19:08:37 +0000 (21:08 +0200)
committerzer0 <zer0@carbon.local>
Fri, 30 Apr 2010 19:08:37 +0000 (21:08 +0200)
projects/microb2010/mainboard/display.py
projects/microb2010/mainboard/strat.c
projects/microb2010/mainboard/strat_corn.c
projects/microb2010/mainboard/strat_db.c

index 6106ff02ff92104029b7b4d3ca421a5cb690612d..b5084072c5622d08bedae101a4840570394b2438 100644 (file)
@@ -345,7 +345,7 @@ while True:
             if not m:
                 m = re.match("ballboard=%s"%(INT), l)
                 if m:
-                    print int(m.groups()[0])
+                    print "ballboard: %d"%(int(m.groups()[0]))
 
             # parse cobboard
             if not m:
index 38397387431d4aed1aac4720d1482ef2d05b8cac..ea846693ad4f5073b29201e78097128654811c2c 100644 (file)
@@ -163,6 +163,14 @@ void strat_event(void *dummy)
 
        /* XXX take opponent position into account */
 
+#ifdef HOST_VERSION
+       if (time_get_s() == 15)
+               cobboard.cob_count = 5;
+       if (time_get_s() == 16)
+               cobboard.cob_count = 0;
+       if (time_get_s() == 25)
+               cobboard.cob_count = 5;
+#endif
 
        /* detect cob on left side */
        if (corn_is_near(&lidx, I2C_LEFT_SIDE)) {
@@ -225,37 +233,34 @@ static uint8_t strat_beginning(void)
 
 #if 1
  l1:
+       DEBUG(E_USER_STRAT, "%s():%d", __FUNCTION__, __LINE__);
        if (get_cob_count() >= 5)
                strat_set_speed(600, SPEED_ANGLE_FAST);
 
        err = line2line(LINE_UP, 0, LINE_R_DOWN, 2);
        if (!TRAJ_SUCCESS(err)) {
-               trajectory_hardstop(&mainboard.traj);
+               strat_hardstop();
                time_wait_ms(2000);
                goto l1;
        }
 
  l2:
+       DEBUG(E_USER_STRAT, "%s():%d", __FUNCTION__, __LINE__);
        if (get_cob_count() >= 5)
                strat_set_speed(600, SPEED_ANGLE_FAST);
 
        err = line2line(LINE_R_DOWN, 2, LINE_R_UP, 2);
        if (!TRAJ_SUCCESS(err)) {
-               trajectory_hardstop(&mainboard.traj);
+               strat_hardstop();
                time_wait_ms(2000);
                goto l2;
        }
 
- l3:
-       if (get_cob_count() >= 5)
-               strat_set_speed(600, SPEED_ANGLE_FAST);
+       WAIT_COND_OR_TRAJ_END(distance_from_robot(2625, COLOR_Y(1847)) < 100,
+                             TRAJ_FLAGS_STD);
+       trajectory_goto_xy_abs(&mainboard.traj, 2625, COLOR_Y(1847));
+       err = wait_traj_end(END_INTR|END_TRAJ);
 
-       err = line2line(LINE_R_UP, 2, LINE_UP, 5);
-       if (!TRAJ_SUCCESS(err)) {
-               trajectory_hardstop(&mainboard.traj);
-               time_wait_ms(2000);
-               goto l3;
-       }
 #else
        strat_set_speed(600, SPEED_ANGLE_FAST);
        err = line2line(LINE_UP, 0, LINE_R_DOWN, 3);
@@ -268,11 +273,13 @@ static uint8_t strat_beginning(void)
        err = line2line(LINE_L_UP, 1, LINE_L_DOWN, 1);
        err = line2line(LINE_L_DOWN, 1, LINE_DOWN, 0);
        wait_ms(500);
-       trajectory_hardstop(&mainboard.traj);
+       strat_hardstop();
        return END_TRAJ;
 #endif
 
-       trajectory_hardstop(&mainboard.traj);
+       DEBUG(E_USER_STRAT, "%s():%d", __FUNCTION__, __LINE__);
+       strat_hardstop();
+       strat_set_speed(600, SPEED_ANGLE_FAST);
 
        /* ball ejection */
        trajectory_a_abs(&mainboard.traj, COLOR_A(90));
@@ -280,8 +287,62 @@ static uint8_t strat_beginning(void)
        time_wait_ms(2000);
 
        /* half turn */
+       i2c_cobboard_pack(I2C_LEFT_SIDE);
+       i2c_cobboard_pack(I2C_RIGHT_SIDE);
+       trajectory_a_rel(&mainboard.traj, COLOR_A(180));
+       err = wait_traj_end(END_INTR|END_TRAJ);
+
+       /* cob ejection */
+       trajectory_d_rel(&mainboard.traj, -100);
+       err = wait_traj_end(END_INTR|END_TRAJ);
+       i2c_cobboard_set_mode(I2C_COBBOARD_MODE_EJECT);
+       time_wait_ms(2000);
+
+       strat_set_speed(250, SPEED_ANGLE_FAST);
+
+ l4:
+       DEBUG(E_USER_STRAT, "%s():%d", __FUNCTION__, __LINE__);
+       if (get_cob_count() >= 5)
+               strat_set_speed(600, SPEED_ANGLE_FAST);
+
+       err = line2line(LINE_DOWN, 5, LINE_L_UP, 2);
+       if (!TRAJ_SUCCESS(err)) {
+               strat_hardstop();
+               time_wait_ms(2000);
+               goto l4;
+       }
+
+ l5:
+       DEBUG(E_USER_STRAT, "%s():%d", __FUNCTION__, __LINE__);
+       if (get_cob_count() >= 5)
+               strat_set_speed(600, SPEED_ANGLE_FAST);
+
+       err = line2line(LINE_L_UP, 2, LINE_R_UP, 2);
+       if (!TRAJ_SUCCESS(err)) {
+               strat_hardstop();
+               time_wait_ms(2000);
+               goto l5;
+       }
+
+       DEBUG(E_USER_STRAT, "%s():%d", __FUNCTION__, __LINE__);
+       if (get_cob_count() >= 5)
+               strat_set_speed(600, SPEED_ANGLE_FAST);
+
+       WAIT_COND_OR_TRAJ_END(distance_from_robot(2625, COLOR_Y(1847)) < 100,
+                             TRAJ_FLAGS_STD);
        trajectory_goto_xy_abs(&mainboard.traj, 2625, COLOR_Y(1847));
        err = wait_traj_end(END_INTR|END_TRAJ);
+
+       DEBUG(E_USER_STRAT, "%s():%d", __FUNCTION__, __LINE__);
+       strat_hardstop();
+       strat_set_speed(600, SPEED_ANGLE_FAST);
+
+       /* ball ejection */
+       trajectory_a_abs(&mainboard.traj, COLOR_A(90));
+       i2c_ballboard_set_mode(I2C_BALLBOARD_MODE_EJECT);
+       time_wait_ms(2000);
+
+       /* half turn */
        i2c_cobboard_pack(I2C_LEFT_SIDE);
        i2c_cobboard_pack(I2C_RIGHT_SIDE);
        trajectory_a_rel(&mainboard.traj, COLOR_A(180));
@@ -293,7 +354,6 @@ static uint8_t strat_beginning(void)
        i2c_cobboard_set_mode(I2C_COBBOARD_MODE_EJECT);
        time_wait_ms(2000);
 
-       trajectory_hardstop(&mainboard.traj);
        return END_TRAJ;
 }
 
index 7fa64c4ed086ec98661160d9276bf26235688252..f8a9666a20dde12992004bd44f1815b359b2f9fe 100644 (file)
@@ -218,9 +218,10 @@ uint8_t line2line(uint8_t dir1, uint8_t num1,
        strat_get_speed(&d_speed, &a_speed);
 
        /* XXX 600 -> cste */
-       if (err == 0 && d_speed < 600 &&
-           mainboard.traj.state == RUNNING_CLITOID_LINE)
-               strat_set_speed(600, SPEED_ANGLE_FAST);
+/*     if (err == 0 && d_speed < 600 && */
+/*         mainboard.traj.state == RUNNING_CLITOID_LINE) */
+/*             strat_set_speed(600, SPEED_ANGLE_FAST); */
+
        err = wait_traj_end(0xFF);
 
        return err;
index 18db6ea1f2c576d3da816931228e25f0cc8cf914..2d3896793bcfe80201a281b9747898d2204bfd80 100644 (file)
@@ -149,7 +149,7 @@ int8_t ijcoord_to_xycoord(uint8_t i, uint8_t j, int16_t *x, int16_t *y)
        if (i >= WAYPOINTS_NBX && j >= WAYPOINTS_NBY)
                return -1;
        *x = (OFFSET_CORN_X + i*STEP_CORN_X);
-       *y = (OFFSET_CORN_Y + j*STEP_CORN_Y);
+       *y = COLOR_Y(OFFSET_CORN_Y + j*STEP_CORN_Y);
        return 0;
 }
 
@@ -188,6 +188,7 @@ int8_t corn_idx_to_xycoord(uint8_t idx, int16_t *x, int16_t *y)
        return 0;
 }
 
+#define CORN_MARGIN 200
 /* return the index of the closest corn at these coordinates. If the
  * corn is really too far (~20cm), return NULL. The x and y pointer are
  * updated with the real position of the corn */
@@ -202,8 +203,7 @@ struct waypoint_db *xycoord_to_corn_idx(int16_t *x, int16_t *y)
        for (n = 0; n < CORN_NB; n ++) {
                corn_idx_to_xycoord(n, &x_corn, &y_corn);
                d = xy_norm(x_corn, y_corn, *x, *y);
-               /* XXX 200 -> constant */
-               if (d < 200 && (d_min == 0 || d < d_min)) {
+               if (d < CORN_MARGIN && (d_min == 0 || d < d_min)) {
                        d_min = d;
                        idx = n;
                        x_corn_min = x_corn;
@@ -341,6 +341,7 @@ int8_t tomato_idx_to_xycoord(uint8_t idx, int16_t *x, int16_t *y)
        return 0;
 }
 
+#define TOMATO_MARGIN 200
 /* return the index of the closest tomato at these coordinates. If the
  * tomato is really too far (~20cm), return NULL. The x and y pointer are
  * updated with the real position of the tomato */
@@ -355,8 +356,7 @@ struct waypoint_db *xycoord_to_tomato_idx(int16_t *x, int16_t *y)
        for (n = 0; n < TOMATO_NB; n ++) {
                tomato_idx_to_xycoord(n, &x_tomato, &y_tomato);
                d = xy_norm(x_tomato, y_tomato, *x, *y);
-               /* XXX 200 -> constant */
-               if (d < 200 && (d_min == 0 || d < d_min)) {
+               if (d < TOMATO_MARGIN && (d_min == 0 || d < d_min)) {
                        d_min = d;
                        idx = n;
                        x_tomato_min = x_tomato;