From c070978b254893490ae35ae411bbdb2b8602bc7d Mon Sep 17 00:00:00 2001 From: Nicolas Haller Date: Mon, 13 Apr 2009 21:27:35 +0200 Subject: * digital/io/src: - first version of filterbridge FSM --- digital/io/src/Makefile | 2 +- digital/io/src/filterbridge.c | 29 +++++++ digital/io/src/filterbridge.fsm | 92 ++++++++++++++++++++++ digital/io/src/filterbridge.h | 28 +++++++ digital/io/src/filterbridge_cb.c | 161 +++++++++++++++++++++++++++++++++++++++ digital/io/src/fsm.h | 1 + 6 files changed, 312 insertions(+), 1 deletion(-) create mode 100644 digital/io/src/filterbridge.c create mode 100644 digital/io/src/filterbridge.fsm create mode 100644 digital/io/src/filterbridge.h create mode 100644 digital/io/src/filterbridge_cb.c (limited to 'digital/io/src') diff --git a/digital/io/src/Makefile b/digital/io/src/Makefile index ed386944..d74eb97f 100644 --- a/digital/io/src/Makefile +++ b/digital/io/src/Makefile @@ -16,6 +16,6 @@ AVR_MCU = atmega128 OPTIMIZE = -O2 # FSMs. -FSM_SOURCES := getsamples gutter move top +FSM_SOURCES := getsamples gutter move top filterbridge # Include FSM makefile. include $(BASE)/make/Makefile.fsm diff --git a/digital/io/src/filterbridge.c b/digital/io/src/filterbridge.c new file mode 100644 index 00000000..163ea9e6 --- /dev/null +++ b/digital/io/src/filterbridge.c @@ -0,0 +1,29 @@ +/* filterbridge.c */ +/* io - Input & Output with Artificial Intelligence (ai) support on AVR. {{{ + * + * Copyright (C) 2009 Nicolas Haller + * + * APBTeam + * Web: http://assos.efrei.fr/robot/ + * Email: robot AT efrei DOT fr + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ +#include "filterbridge.h" + +/* +AutoDec */ +/* -AutoDec */ + diff --git a/digital/io/src/filterbridge.fsm b/digital/io/src/filterbridge.fsm new file mode 100644 index 00000000..324314b7 --- /dev/null +++ b/digital/io/src/filterbridge.fsm @@ -0,0 +1,92 @@ +# Filter Bridge FSM +# Filter column element (our colour -> go to lift, !our colour -> EJECT) +filterbridge + +States: + IDLE + waiting the lift is ready to accept new puck + WAIT_A_PUCK + waiting for a new puck + CLOSE_FIRST_DOOR + isolating the firt puck on the bridge + WAIT_RGB_IDENT + waiting for RGB probe the first puck + EJECT_PUCK + eject a bad puck + RETURN_NORMAL_POS + move the bridge to his normal position + BLAH + useless states + OPEN_SECOND_DOOR + open and free the puck to the lift + CLOSE_SECOND_DOOR + prepare for a new puck + OPEN_FIRST_DOOR + accept a puck for a new test + +Events: + lift_ready + lift ready to accept new puck + puck_on_pos2 + a puck has been detected on bridge's position 2 + first_door_closed + the first door is closed + bad_color + the RGB had probed the puck and it is bad + no_puck_on_pos2 + there is no puck on position 2 + bridge_in_position + bridge is in his normal position + good_color + the RGB had probed the puck and it is good (and ready to listening horrible lift music) + second_door_closed + you shall not pass to the lift + first_door_opened + bridge ready to test a new puck + puck_ejected + the ejection procedure is completed + + +IDLE: + lift_ready -> WAIT_A_PUCK + the lift is ready to get pucks, we can begin testing procedure + +WAIT_A_PUCK: + puck_on_pos2 -> CLOSE_FIRST_DOOR + close the first door after a puck is ready for filtering + +CLOSE_FIRST_DOOR: + first_door_closed -> WAIT_RGB_IDENT + get puck color + +WAIT_RGB_IDENT: + bad_color -> EJECT_PUCK + eject bad PUCK + good_color -> OPEN_SECOND_DOOR + put puck to the lift + +EJECT_PUCK: + puck_ejected -> RETURN_NORMAL_POS + put bridge on normal position after puck ejection + +RETURN_NORMAL_POS: + bridge_in_position -> BLAH + ready for a new puck test (unless bad puck is here yet) + +BLAH: + puck_on_pos2 -> EJECT_PUCK + re-eject this sticky puck, grml! + no_puck_on_pos2 -> OPEN_FIRST_DOOR + make bridge ready to test a new puck + +OPEN_SECOND_DOOR: + no_puck_on_pos2 -> CLOSE_SECOND_DOOR + close the lift access door and tell to lift it has a new puck + +CLOSE_SECOND_DOOR: + second_door_closed -> OPEN_FIRST_DOOR + filter bridge is ready to get a new puck + +OPEN_FIRST_DOOR: + first_door_opened -> IDLE + filter bridge ready diff --git a/digital/io/src/filterbridge.h b/digital/io/src/filterbridge.h new file mode 100644 index 00000000..eb40d76f --- /dev/null +++ b/digital/io/src/filterbridge.h @@ -0,0 +1,28 @@ +#ifndef filterbridge_h +#define filterbridge_h +// filterbridge.h +// io - Input & Output with Artificial Intelligence (ai) support on AVR. {{{ +// +// Copyright (C) 2009 Nicolas Haller +// +// APBTeam/Efrei 2005. +// Web: http://assos.efrei.fr/robot/ +// Email: robot AT efrei DOT fr +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +// }}} + +#endif // filterbridge_h diff --git a/digital/io/src/filterbridge_cb.c b/digital/io/src/filterbridge_cb.c new file mode 100644 index 00000000..a34b9a6f --- /dev/null +++ b/digital/io/src/filterbridge_cb.c @@ -0,0 +1,161 @@ +/* filterbridge_cb.c - filterbridge FSM callbacks. */ +/* {{{ + * + * Copyright (C) 2009 Nicolas Haller + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ +#include "common.h" +#include "fsm.h" +#include "filterbridge_cb.h" + +/* + * CLOSE_FIRST_DOOR =first_door_closed=> + * => WAIT_RGB_IDENT + * get puck color + */ +fsm_branch_t +filterbridge__CLOSE_FIRST_DOOR__first_door_closed (void) +{ + return filterbridge_next (CLOSE_FIRST_DOOR, first_door_closed); +} + +/* + * WAIT_A_PUCK =puck_on_pos2=> + * => CLOSE_FIRST_DOOR + * close the first door after a puck is ready for filtering + */ +fsm_branch_t +filterbridge__WAIT_A_PUCK__puck_on_pos2 (void) +{ + return filterbridge_next (WAIT_A_PUCK, puck_on_pos2); +} + +/* + * CLOSE_SECOND_DOOR =second_door_closed=> + * => OPEN_FIRST_DOOR + * filter bridge is ready to get a new puck + */ +fsm_branch_t +filterbridge__CLOSE_SECOND_DOOR__second_door_closed (void) +{ + return filterbridge_next (CLOSE_SECOND_DOOR, second_door_closed); +} + +/* + * WAIT_RGB_IDENT =good_color=> + * => OPEN_SECOND_DOOR + * put puck to the lift + */ +fsm_branch_t +filterbridge__WAIT_RGB_IDENT__good_color (void) +{ + return filterbridge_next (WAIT_RGB_IDENT, good_color); +} + +/* + * WAIT_RGB_IDENT =bad_color=> + * => EJECT_PUCK + * eject bad PUCK + */ +fsm_branch_t +filterbridge__WAIT_RGB_IDENT__bad_color (void) +{ + return filterbridge_next (WAIT_RGB_IDENT, bad_color); +} + +/* + * BLAH =no_puck_on_pos2=> + * => OPEN_FIRST_DOOR + * make bridge ready to test a new puck + */ +fsm_branch_t +filterbridge__BLAH__no_puck_on_pos2 (void) +{ + return filterbridge_next (BLAH, no_puck_on_pos2); +} + +/* + * BLAH =puck_on_pos2=> + * => EJECT_PUCK + * re-eject this sticky puck, grml! + */ +fsm_branch_t +filterbridge__BLAH__puck_on_pos2 (void) +{ + return filterbridge_next (BLAH, puck_on_pos2); +} + +/* + * IDLE =lift_ready=> + * => WAIT_A_PUCK + * the lift is ready to get pucks, we can begin testing procedure + */ +fsm_branch_t +filterbridge__IDLE__lift_ready (void) +{ + return filterbridge_next (IDLE, lift_ready); +} + +/* + * RETURN_NORMAL_POS =bridge_in_position=> + * => BLAH + * ready for a new puck test (unless bad puck is here yet) + */ +fsm_branch_t +filterbridge__RETURN_NORMAL_POS__bridge_in_position (void) +{ + return filterbridge_next (RETURN_NORMAL_POS, bridge_in_position); +} + +/* + * OPEN_FIRST_DOOR =first_door_opened=> + * => IDLE + * filter bridge ready + */ +fsm_branch_t +filterbridge__OPEN_FIRST_DOOR__first_door_opened (void) +{ + return filterbridge_next (OPEN_FIRST_DOOR, first_door_opened); +} + +/* + * OPEN_SECOND_DOOR =no_puck_on_pos2=> + * => CLOSE_SECOND_DOOR + * close the lift access door and tell to lift it has a new puck + */ +fsm_branch_t +filterbridge__OPEN_SECOND_DOOR__no_puck_on_pos2 (void) +{ + return filterbridge_next (OPEN_SECOND_DOOR, no_puck_on_pos2); +} + +/* + * EJECT_PUCK =puck_ejected=> + * => RETURN_NORMAL_POS + * put bridge on normal position after puck ejection + */ +fsm_branch_t +filterbridge__EJECT_PUCK__puck_ejected (void) +{ + return filterbridge_next (EJECT_PUCK, puck_ejected); +} + + diff --git a/digital/io/src/fsm.h b/digital/io/src/fsm.h index 4933cb8e..5246d843 100644 --- a/digital/io/src/fsm.h +++ b/digital/io/src/fsm.h @@ -101,5 +101,6 @@ fsm_handle_event (fsm_t *fsm, u8 event); #include "gutter_fsm.h" #include "move_fsm.h" #include "top_fsm.h" +#include "filterbridge_fsm.h" #endif /* fsm_h */ -- cgit v1.2.3