X-Git-Url: http://git.droids-corp.org/?p=aversive.git;a=blobdiff_plain;f=projects%2Fmicrob2010%2Fmainboard%2Fstrat_base.c;h=871648666119706f8bd6aff0dd3aad538279b473;hp=1f3b6e5380ff4bd69ed4bb2a0c12ff6ed8acf81e;hb=28da5858ac871c626153f47566e968ecb05ff52b;hpb=4e7801883ed4076cb14b63a0571467747894c0f8 diff --git a/projects/microb2010/mainboard/strat_base.c b/projects/microb2010/mainboard/strat_base.c index 1f3b6e5..8716486 100644 --- a/projects/microb2010/mainboard/strat_base.c +++ b/projects/microb2010/mainboard/strat_base.c @@ -103,6 +103,8 @@ const char *get_err(uint8_t err) void strat_hardstop(void) { + DEBUG(E_USER_STRAT, "strat_hardstop"); + trajectory_hardstop(&mainboard.traj); pid_reset(&mainboard.angle.pid); pid_reset(&mainboard.distance.pid); @@ -154,6 +156,25 @@ void strat_reset_pos(int16_t x, int16_t y, int16_t a) if (a == DO_NOT_SET_POS) a = posa; + /* some issues with blocking on simulator */ +#ifdef HOST_VERSION + if (x == ROBOT_HALF_LENGTH_REAR) + x = ROBOT_HALF_LENGTH_REAR + 10; + if (x == AREA_X - ROBOT_HALF_LENGTH_REAR) + x = AREA_X - ROBOT_HALF_LENGTH_REAR - 10; + if (y == ROBOT_HALF_LENGTH_REAR) + y = ROBOT_HALF_LENGTH_REAR + 10; + if (y == AREA_Y - ROBOT_HALF_LENGTH_REAR) + y = AREA_Y - ROBOT_HALF_LENGTH_REAR - 10; + if (x == ROBOT_HALF_LENGTH_FRONT) + x = ROBOT_HALF_LENGTH_FRONT + 10; + if (x == AREA_X - ROBOT_HALF_LENGTH_FRONT) + x = AREA_X - ROBOT_HALF_LENGTH_FRONT - 10; + if (y == ROBOT_HALF_LENGTH_FRONT) + y = ROBOT_HALF_LENGTH_FRONT + 10; + if (y == AREA_Y - ROBOT_HALF_LENGTH_FRONT) + y = AREA_Y - ROBOT_HALF_LENGTH_FRONT - 10; +#endif DEBUG(E_USER_STRAT, "reset pos (%s%s%s)", x == DO_NOT_SET_POS ? "" : "x", y == DO_NOT_SET_POS ? "" : "y", @@ -174,14 +195,45 @@ uint8_t strat_calib(int16_t dist, uint8_t flags) int32_t max_in = pid_get_max_in(&mainboard.angle.pid); int32_t max_i = pid_get_max_I(&mainboard.angle.pid); int32_t max_out = pid_get_max_out(&mainboard.angle.pid); + uint32_t i_thres = mainboard.distance.bd.i_thres; + int32_t k1 = mainboard.distance.bd.k1; + int32_t k2 = mainboard.distance.bd.k2; + uint16_t cpt_thres = mainboard.distance.bd.cpt_thres; + uint8_t err; + /* go with a lower angle pid, and with a sensible blocking + * detection */ + bd_set_current_thresholds(&mainboard.distance.bd, 500, 8000, 400000, 20); pid_set_maximums(&mainboard.distance.pid, 0, 20000, 1000); - pid_set_gains(&mainboard.angle.pid, 200, 0, 2000); + pid_set_gains(&mainboard.angle.pid, 500, 10, 4000); trajectory_d_rel(&mainboard.traj, dist); err = wait_traj_end(flags); + if (err != END_BLOCKING) + goto fail; + + /* we detected a blocking, reset bd, remove angle pid and + * continue */ + trajectory_d_rel(&mainboard.traj, dist); + pid_set_maximums(&mainboard.distance.pid, max_in, max_i, 4095); + pid_set_gains(&mainboard.angle.pid, 1, 0, 0); + time_wait_ms(300); + strat_hardstop(); + +#ifdef HOST_VERSION + /* issue with block on simulator */ + if (dist > 0) + trajectory_d_rel(&mainboard.traj, -10); + else + trajectory_d_rel(&mainboard.traj, 10); + wait_traj_end(END_TRAJ); +#endif + + fail: pid_set_gains(&mainboard.angle.pid, p, i, d); pid_set_maximums(&mainboard.distance.pid, max_in, max_i, max_out); + bd_set_current_thresholds(&mainboard.distance.bd, k1, k2, i_thres, cpt_thres); + return err; } @@ -209,6 +261,11 @@ void strat_set_speed(uint16_t d, uint16_t a) IRQ_UNLOCK(flags); } +void strat_set_acc(double d, double a) +{ + trajectory_set_acc(&mainboard.traj, d, a); +} + void strat_get_speed(uint16_t *d, uint16_t *a) { uint8_t flags; @@ -218,6 +275,15 @@ void strat_get_speed(uint16_t *d, uint16_t *a) IRQ_UNLOCK(flags); } +void strat_get_acc(double *d, double *a) +{ + uint8_t flags; + IRQ_LOCK(flags); + *d = mainboard.traj.d_acc; + *a = mainboard.traj.a_acc; + IRQ_UNLOCK(flags); +} + void strat_limit_speed_enable(void) { strat_limit_speed_enabled = 1; @@ -228,7 +294,7 @@ void strat_limit_speed_disable(void) strat_limit_speed_enabled = 0; } -/* called periodically */ +/* called periodically (note: disabled in 2010) */ void strat_limit_speed(void) { uint16_t lim_d = 0, lim_a = 0; @@ -312,7 +378,6 @@ void strat_start(void) strat_init(); err = strat_main(); - printf("coucou\n"); NOTICE(E_USER_STRAT, "Finished !! returned %s", get_err(err)); strat_exit(); } @@ -320,7 +385,6 @@ void strat_start(void) /* return true if we have to brake due to an obstacle */ uint8_t strat_obstacle(void) { -#if 0 int16_t x_rel, y_rel; int16_t opp_x, opp_y, opp_d, opp_a; @@ -329,8 +393,7 @@ uint8_t strat_obstacle(void) return 0; /* no opponent detected */ - if (get_opponent_xyda(&opp_x, &opp_y, - &opp_d, &opp_a)) + if (get_opponent_xyda(&opp_x, &opp_y, &opp_d, &opp_a)) return 0; /* save obstacle position */ @@ -338,25 +401,9 @@ uint8_t strat_obstacle(void) opponent_obstacle.y = opp_y; opponent_obstacle.d = opp_d; opponent_obstacle.a = opp_a; -#else /* belgium cup only */ - int16_t x_rel, y_rel; - int16_t opp_d, opp_a; - double opp_x, opp_y; -#ifdef HOST_VERSION - if (time_get_s() >= 12 && time_get_s() <= 30) - return 1; -#endif - if (!sensor_get(S_RCOB_WHITE)) - return 0; - - opp_a = 0; - opp_d = 300; - - rel_da_to_abs_xy(opp_d, RAD(opp_a), &opp_x, &opp_y); if (!is_in_area(opp_x, opp_y, 250)) return 0; -#endif /* sensor are temporarily disabled */ if (sensor_obstacle_is_disabled()) @@ -367,7 +414,7 @@ uint8_t strat_obstacle(void) y_rel = sin(RAD(opp_a)) * (double)opp_d; /* opponent too far */ - if (opp_d > 600) + if (opp_d > 500) return 0; /* opponent is in front of us */