From 69bae8c81600790e5593facf92be774458d7b7c7 Mon Sep 17 00:00:00 2001 From: Jérôme Jutteau Date: Mon, 30 May 2011 18:15:49 +0200 Subject: digital/io-hub: manage founded towers --- digital/io-hub/src/robospierre/logistic.c | 34 ++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'digital/io-hub/src/robospierre/logistic.c') diff --git a/digital/io-hub/src/robospierre/logistic.c b/digital/io-hub/src/robospierre/logistic.c index 1e44d675..35e40efa 100644 --- a/digital/io-hub/src/robospierre/logistic.c +++ b/digital/io-hub/src/robospierre/logistic.c @@ -250,6 +250,33 @@ logistic_put_element () } } +/** If we picked up a tower. */ +static void +logistic_new_tower () +{ + uint8_t dir_bay, nodir_bay; + if (ctx.collect_direction == DIRECTION_FORWARD) + { + dir_bay = CLAMP_SLOT_FRONT_BOTTOM; + nodir_bay = CLAMP_SLOT_BACK_BOTTOM; + } + else + { + dir_bay = CLAMP_SLOT_BACK_BOTTOM; + nodir_bay = CLAMP_SLOT_FRONT_BOTTOM; + } + if (ctx.slots[dir_bay] == ELEMENT_TOWER) + { + ctx.ready = 1; + if (ctx.collect_direction == DIRECTION_FORWARD) + ctx.collect_direction = DIRECTION_BACKWARD; + else + ctx.collect_direction = DIRECTION_FORWARD; + } + if (ctx.slots[nodir_bay] == ELEMENT_TOWER) + ctx.ready = 1; +} + /** Examine current state and take a decision. */ static void logistic_decision (void) @@ -268,6 +295,11 @@ logistic_decision (void) if (ctx.prepare == 3) return; + /* We founded a tower ! */ + logistic_new_tower (); + if (ctx.ready) + return; + /* Check if we really need to prepare something. */ logistic_check_need_prepare (); @@ -359,7 +391,7 @@ logistic_decision (void) return; } /* We have to prepare an element to put out. */ - else if ((ctx.prepare == 2 || ctx.need_prepare) && ctx.construct_possible) + else if (ctx.prepare == 2 && ctx.construct_possible) { logistic_put_element (); } -- cgit v1.2.3