git.droids-corp.org
/
aversive.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
wait obstacle -- c nul en fait
[aversive.git]
/
projects
/
microb2010
/
mainboard
/
strat.c
diff --git
a/projects/microb2010/mainboard/strat.c
b/projects/microb2010/mainboard/strat.c
index
dd06751
..
4955bba
100644
(file)
--- a/
projects/microb2010/mainboard/strat.c
+++ b/
projects/microb2010/mainboard/strat.c
@@
-75,6
+75,10
@@
static volatile uint8_t strat_running = 0;
volatile uint8_t strat_want_pack = 0;
volatile uint8_t strat_lpack60 = 0;
volatile uint8_t strat_rpack60 = 0;
volatile uint8_t strat_want_pack = 0;
volatile uint8_t strat_lpack60 = 0;
volatile uint8_t strat_rpack60 = 0;
+
+volatile uint8_t strat_opponent_lpack = 0;
+volatile uint8_t strat_opponent_rpack = 0;
+
struct strat_conf strat_conf = {
.dump_enabled = 0,
.opp_orange = 90,
struct strat_conf strat_conf = {
.dump_enabled = 0,
.opp_orange = 90,
@@
-97,6
+101,7
@@
void strat_preinit(void)
DO_POS | DO_BD | DO_POWER;
strat_db_init();
DO_POS | DO_BD | DO_POWER;
strat_db_init();
+ strat_conf.prev_wait_obstacle = -5;
strat_conf_dump(__FUNCTION__);
strat_db_dump(__FUNCTION__);
}
strat_conf_dump(__FUNCTION__);
strat_db_dump(__FUNCTION__);
}
@@
-107,10
+112,12
@@
void strat_conf_dump(const char *caller)
return;
printf_P(PSTR("-- conf --\r\n"));
return;
printf_P(PSTR("-- conf --\r\n"));
- printf_P(PSTR("opp_orange = %d\n"), strat_conf.opp_orange);
- printf_P(PSTR("orphan_tomato = %d\n"), strat_conf.orphan_tomato);
printf_P(PSTR("our_orange = %s\n"),
(strat_conf.flags & STRAT_CONF_OUR_ORANGE) ? "y":"n");
printf_P(PSTR("our_orange = %s\n"),
(strat_conf.flags & STRAT_CONF_OUR_ORANGE) ? "y":"n");
+ printf_P(PSTR("wait_obstacle = %s\n"),
+ (strat_conf.flags & STRAT_CONF_WAIT_OBSTACLE) ? "y":"n");
+ printf_P(PSTR("opp_orange = %d\n"), strat_conf.opp_orange);
+ printf_P(PSTR("orphan_tomato = %d\n"), strat_conf.orphan_tomato);
}
void strat_event_enable(void)
}
void strat_event_enable(void)
@@
-222,6
+229,7
@@
static void check_corn(void)
uint8_t lidx, ridx;
static uint8_t prev_check_time;
uint8_t cur_time;
uint8_t lidx, ridx;
static uint8_t prev_check_time;
uint8_t cur_time;
+ uint8_t need_lpack, need_rpack;
/* read sensors from ballboard */
IRQ_LOCK(flags);
/* read sensors from ballboard */
IRQ_LOCK(flags);
@@
-270,8
+278,10
@@
static void check_corn(void)
}
/* control the cobboard mode for left spickle */
}
/* control the cobboard mode for left spickle */
+ need_lpack = get_cob_count() >= 5 || strat_want_pack ||
+ strat_lpack60 || strat_opponent_lpack;
if (lcob_near && strat_db.corn_table[lidx]->present) {
if (lcob_near && strat_db.corn_table[lidx]->present) {
- if (
get_cob_count() >= 5 || strat_want_pack || strat_lpack60
) {
+ if (
need_lpack
) {
/* nothing */
}
else {
/* nothing */
}
else {
@@
-296,15
+306,17
@@
static void check_corn(void)
}
else {
/* no cob near us, we can pack or deploy freely */
}
else {
/* no cob near us, we can pack or deploy freely */
- if (
get_cob_count() >= 5 || strat_want_pack || strat_lpack60
)
+ if (
need_lpack
)
i2c_cobboard_pack_weak(I2C_LEFT_SIDE);
else
i2c_cobboard_deploy(I2C_LEFT_SIDE);
}
/* control the cobboard mode for right spickle */
i2c_cobboard_pack_weak(I2C_LEFT_SIDE);
else
i2c_cobboard_deploy(I2C_LEFT_SIDE);
}
/* control the cobboard mode for right spickle */
+ need_rpack = get_cob_count() >= 5 || strat_want_pack ||
+ strat_rpack60 || strat_opponent_rpack;
if (rcob_near && strat_db.corn_table[ridx]->present) {
if (rcob_near && strat_db.corn_table[ridx]->present) {
- if (
get_cob_count() >= 5 || strat_want_pack || strat_rpack60
) {
+ if (
need_rpack
) {
/* nothing */
}
else {
/* nothing */
}
else {
@@
-329,7
+341,7
@@
static void check_corn(void)
}
else {
/* no cob near us, we can pack or deploy freely */
}
else {
/* no cob near us, we can pack or deploy freely */
- if (
get_cob_count() >= 5 || strat_want_pack || strat_rpack60
)
+ if (
need_rpack
)
i2c_cobboard_pack_weak(I2C_RIGHT_SIDE);
else
i2c_cobboard_deploy(I2C_RIGHT_SIDE);
i2c_cobboard_pack_weak(I2C_RIGHT_SIDE);
else
i2c_cobboard_deploy(I2C_RIGHT_SIDE);
@@
-339,30
+351,42
@@
static void check_corn(void)
/* check opponent position */
void check_opponent(void)
{
/* check opponent position */
void check_opponent(void)
{
- int16_t x, y;
+ int16_t opp_x, opp_y;
+ int16_t opp_d, opp_a;
uint8_t i, j;
uint8_t i, j;
- if (get_opponent_xy(&x, &y) < 0)
+ strat_opponent_lpack = 0;
+ strat_opponent_rpack = 0;
+
+ if (get_opponent_xyda(&opp_x, &opp_y, &opp_d, &opp_a) < 0)
return;
return;
+ /* pack spickles if opponent too close */
+ if (opp_d < 600) {
+ if (opp_a > 45 && opp_a < 135)
+ strat_opponent_lpack = 1;
+ if (opp_a > 225 && opp_a < 315)
+ strat_opponent_rpack = 1;
+ }
+
/* check for oranges after 5 seconds */
if (time_get_s() > 5) {
if (mainboard.our_color == I2C_COLOR_YELLOW) {
/* check for oranges after 5 seconds */
if (time_get_s() > 5) {
if (mainboard.our_color == I2C_COLOR_YELLOW) {
- if (
y < 500 &&
x < 500)
+ if (
opp_y < 500 && opp_
x < 500)
strat_db.our_oranges_count = 0;
strat_db.our_oranges_count = 0;
- if (
y < 500 &&
x > AREA_X - 500)
+ if (
opp_y < 500 && opp_
x > AREA_X - 500)
strat_db.opp_oranges_count = 0;
}
else {
strat_db.opp_oranges_count = 0;
}
else {
- if (
y > AREA_Y - 500 &&
x < 500)
+ if (
opp_y > AREA_Y - 500 && opp_
x < 500)
strat_db.our_oranges_count = 0;
strat_db.our_oranges_count = 0;
- if (
y > AREA_Y - 500 &&
x > AREA_X - 500)
+ if (
opp_y > AREA_Y - 500 && opp_
x > AREA_X - 500)
strat_db.opp_oranges_count = 0;
}
}
/* malus for some tomatoes and cobs, visited by opponent */
strat_db.opp_oranges_count = 0;
}
}
/* malus for some tomatoes and cobs, visited by opponent */
- if (xycoord_to_ijcoord(&
x, &
y, &i, &j) < 0)
+ if (xycoord_to_ijcoord(&
opp_x, &opp_
y, &i, &j) < 0)
return;
strat_db.wp_table[i][j].opp_visited = 1;
return;
strat_db.wp_table[i][j].opp_visited = 1;
@@
-375,9
+399,9
@@
void strat_event(void *dummy)
if (strat_running == 0)
return;
if (strat_running == 0)
return;
+ check_opponent();
check_tomato();
check_corn();
check_tomato();
check_corn();
- check_opponent();
/* limit speed when opponent is near */
/* disabled for 2010, we are already slow :) */
/* limit speed when opponent is near */
/* disabled for 2010, we are already slow :) */
@@
-535,11
+559,27
@@
static uint8_t strat_beginning(uint8_t do_initturn)
strat_set_acc(ACC_DIST, ACC_ANGLE);
strat_set_speed(SPEED_CLITOID_SLOW, SPEED_ANGLE_SLOW);
strat_set_acc(ACC_DIST, ACC_ANGLE);
strat_set_speed(SPEED_CLITOID_SLOW, SPEED_ANGLE_SLOW);
+ l1:
err = line2line(0, LINE_UP, 2, LINE_R_DOWN, TRAJ_FLAGS_NO_NEAR);
err = line2line(0, LINE_UP, 2, LINE_R_DOWN, TRAJ_FLAGS_NO_NEAR);
+ if (err == END_OBSTACLE &&
+ strat_conf.flags & STRAT_CONF_WAIT_OBSTACLE &&
+ time_get_s() > strat_conf.prev_wait_obstacle + 5) {
+ strat_conf.prev_wait_obstacle = time_get_s();
+ time_wait_ms(2000);
+ goto l1;
+ }
if (!TRAJ_SUCCESS(err))
return err;
if (!TRAJ_SUCCESS(err))
return err;
+ l2:
err = line2line(2, LINE_R_DOWN, 2, LINE_R_UP, TRAJ_FLAGS_NO_NEAR);
err = line2line(2, LINE_R_DOWN, 2, LINE_R_UP, TRAJ_FLAGS_NO_NEAR);
+ if (err == END_OBSTACLE &&
+ strat_conf.flags & STRAT_CONF_WAIT_OBSTACLE &&
+ time_get_s() > strat_conf.prev_wait_obstacle + 5) {
+ strat_conf.prev_wait_obstacle = time_get_s();
+ time_wait_ms(2000);
+ goto l2;
+ }
if (!TRAJ_SUCCESS(err)) {
return err;
}
if (!TRAJ_SUCCESS(err)) {
return err;
}