From 94f06205a8a95bc9b03109329d84410967ba12b4 Mon Sep 17 00:00:00 2001 From: Jérémy Dufour Date: Mon, 21 Apr 2008 23:56:26 +0200 Subject: * digital/io/src - resetting of asserv parameters is now a separate state in order to get the acknowledge from the asserv board ; - integrate the handle of this event into the main loop. --- digital/io/src/main.c | 6 ++++++ digital/io/src/top.c | 12 ++++++++++++ digital/io/src/top.fsm | 13 ++++++++++--- digital/io/src/top.h | 11 +++++++++++ digital/io/src/top_cb.c | 35 +++++++++++++++++++++++++++++------ 5 files changed, 68 insertions(+), 9 deletions(-) diff --git a/digital/io/src/main.c b/digital/io/src/main.c index 1be36985..f9f7664a 100644 --- a/digital/io/src/main.c +++ b/digital/io/src/main.c @@ -42,6 +42,7 @@ #include "fsm.h" /* fsm_* */ #include "giboulee.h" /* team_color */ #include "getsamples.h" /* getsamples_start */ +#include "top.h" /* top_* */ #include "io.h" @@ -148,6 +149,11 @@ main_loop (void) fsm_handle_event (&top_fsm, switch_get_jack () ? TOP_EVENT_jack_removed_from_bot : TOP_EVENT_jack_inserted_into_bot); + /* Settings acknowledge */ + if (top_generate_settings_ack_event ()) + { + fsm_handle_event (&top_fsm, TOP_EVENT_settings_acknowledged); + } /* TODO: Check other sensors */ } } diff --git a/digital/io/src/top.c b/digital/io/src/top.c index d290efe5..6d8ab268 100644 --- a/digital/io/src/top.c +++ b/digital/io/src/top.c @@ -29,6 +29,12 @@ struct top_data_t top_data; +/** + * When we need to tell the main loop we want to be alerted when the last + * command sent to the asserv board has been acknowledged. + */ +uint8_t top_waiting_for_settings_ack_ = 0; + /** Start a main FSM. */ void top_start (uint8_t color_team) @@ -45,3 +51,9 @@ top_start (uint8_t color_team) fsm_handle_event (&top_fsm, TOP_EVENT_start); } +/* Do we need to tell the top FSM the settings has been acknowledged? */ +uint8_t +top_generate_settings_ack_event (void) +{ + return top_waiting_for_settings_ack_; +} diff --git a/digital/io/src/top.fsm b/digital/io/src/top.fsm index eed38367..2a9ad8e4 100644 --- a/digital/io/src/top.fsm +++ b/digital/io/src/top.fsm @@ -14,6 +14,8 @@ States: waiting for the jack to be inserted into the bot WAIT_JACK_OUT waiting for the jack to be removed from the bot + CONFIGURE_ASSERV + configuring the asserv board GO_TO_SAMPLE_DISTRIBUTOR go to our distributor of samples (using the move FSM) GO_TO_OUR_ICE_DISTRIBUTOR @@ -45,6 +47,8 @@ Events: the jack is inserted into the bot jack_removed_from_bot the jack is removed from the bot + settings_acknowledged + the asserv board has acknowledged the settings sent IDLE: start -> WAIT_JACK_IN @@ -57,10 +61,13 @@ WAIT_JACK_IN: bot WAIT_JACK_OUT: - jack_removed_from_bot -> GO_TO_SAMPLE_DISTRIBUTOR + jack_removed_from_bot -> CONFIGURE_ASSERV the match start, start the chronometer - we should also initialize all the subsystems of IO (reset position, get our - color, ...) + we should also initialize all the subsystems of IO (get our color, ...) + set the settings of the asserv board (especially the position) + +CONFIGURE_ASSERV: + settings_acknowledged -> GO_TO_SAMPLE_DISTRIBUTOR order the bot to move to our samples distributors with the move FSM GO_TO_SAMPLE_DISTRIBUTOR: diff --git a/digital/io/src/top.h b/digital/io/src/top.h index 78b83ce8..5e2da9b4 100644 --- a/digital/io/src/top.h +++ b/digital/io/src/top.h @@ -67,4 +67,15 @@ extern struct top_data_t top_data; void top_start (uint8_t team_color); +/** + * Do we need to tell the top FSM the settings has been acknowledged? + * You need to call this function in the main loop to ensure we pass a + * requested event (settings_acknowledged) to the top FSM. + * @return + * - 0 if you do not need to generate the event for the top FSM ; + * - 1 if you need to generate the event. + */ +uint8_t +top_generate_settings_ack_event (void); + #endif /* top_h */ diff --git a/digital/io/src/top_cb.c b/digital/io/src/top_cb.c index 60ea6c28..82ed00c4 100644 --- a/digital/io/src/top_cb.c +++ b/digital/io/src/top_cb.c @@ -39,6 +39,12 @@ #include "getsamples.h" /* getsamples_* */ #include "gutter.h" /* gutter_start */ +/** + * When we need to tell the main loop we want to be alerted when the last + * command sent to the asserv board has been acknowledged. + */ +extern uint8_t top_waiting_for_settings_ack_; + /* * DROP_OFF_BALLS_TO_GUTTER =gutter_fsm_finished=> * => GO_TO_SAMPLE_DISTRIBUTOR @@ -56,11 +62,10 @@ top__DROP_OFF_BALLS_TO_GUTTER__gutter_fsm_finished (void) /* * WAIT_JACK_OUT =jack_removed_from_bot=> - * => GO_TO_SAMPLE_DISTRIBUTOR + * => CONFIGURE_ASSERV * the match start, start the chronometer - * we should also initialize all the subsystems of IO (reset position, get our - * color, ...) - * order the bot to move to our samples distributors with the move FSM + * we should also initialize all the subsystems of IO (get our color, ...) + * set the settings of the asserv board (especially the position) */ fsm_branch_t top__WAIT_JACK_OUT__jack_removed_from_bot (void) @@ -71,8 +76,9 @@ top__WAIT_JACK_OUT__jack_removed_from_bot (void) chrono_init (); /* Reset the position of the bot */ asserv_set_position (PG_X_START, PG_Y_START, PG_A_START); - /* Start the move FSM to our samples distributor */ - move_start (PG_DISTRIBUTOR_SAMPLE_OUR_X, PG_DISTRIBUTOR_SAMPLE_OUR_Y); + /* Tell the main loop we need to be aware when the asserv acknowledge our + * settings command */ + top_waiting_for_settings_ack_ = 1; return top_next (WAIT_JACK_OUT, jack_removed_from_bot); } @@ -213,3 +219,20 @@ top__WAIT_JACK_IN__jack_inserted_into_bot (void) /* TODO */ return top_next (WAIT_JACK_IN, jack_inserted_into_bot); } + +/* + * CONFIGURE_ASSERV =settings_acknowledged=> + * => GO_TO_SAMPLE_DISTRIBUTOR + * order the bot to move to our samples distributors with the move FSM + */ +fsm_branch_t +top__CONFIGURE_ASSERV__settings_acknowledged (void) +{ + /* Clear the flag for the setting acknowleged */ + top_waiting_for_settings_ack_ = 0; + /* Start the move FSM to our samples distributor */ + move_start (PG_DISTRIBUTOR_SAMPLE_OUR_X, PG_DISTRIBUTOR_SAMPLE_OUR_Y); + return top_next (CONFIGURE_ASSERV, settings_acknowledged); +} + + -- cgit v1.2.3