summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Haller2009-04-15 00:00:40 +0200
committerNicolas Haller2009-04-15 00:00:40 +0200
commitffa0ef335c0da785bf007f19857755661b13fd04 (patch)
treef3e21c4669b9a4e16f8b2f6229bbad63a617e94b
parentc070978b254893490ae35ae411bbdb2b8602bc7d (diff)
* digital/io/src:
- first version of elevator FSM
-rw-r--r--digital/io/src/Makefile2
-rw-r--r--digital/io/src/elevator.c29
-rw-r--r--digital/io/src/elevator.fsm89
-rw-r--r--digital/io/src/elevator.h28
-rw-r--r--digital/io/src/elevator_cb.c161
-rw-r--r--digital/io/src/fsm.h1
6 files changed, 309 insertions, 1 deletions
diff --git a/digital/io/src/Makefile b/digital/io/src/Makefile
index d74eb97f..5c572d52 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 filterbridge
+FSM_SOURCES := getsamples gutter move top filterbridge elevator
# Include FSM makefile.
include $(BASE)/make/Makefile.fsm
diff --git a/digital/io/src/elevator.c b/digital/io/src/elevator.c
new file mode 100644
index 00000000..989c132d
--- /dev/null
+++ b/digital/io/src/elevator.c
@@ -0,0 +1,29 @@
+/* elevator.c */
+/* io - Input & Output with Artificial Intelligence (ai) support on AVR. {{{
+ *
+ * Copyright (C) 2009 Nicolas Haller
+ *
+ * RobotAPB
+ * 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 "elevator.h"
+
+/* +AutoDec */
+/* -AutoDec */
+
diff --git a/digital/io/src/elevator.fsm b/digital/io/src/elevator.fsm
new file mode 100644
index 00000000..8466ae3e
--- /dev/null
+++ b/digital/io/src/elevator.fsm
@@ -0,0 +1,89 @@
+# Elevator FSM
+# Control the elevator's position and doors.
+elevator
+
+States:
+ IDLE
+ waiting for the beginning of the round
+ GO_TO_POS_X
+ go to a position to be ready to get a new puck
+ WAIT_A_PUCK
+ waiting for a new puck (hurry up filter bridge!)
+ BLAH
+ useless state (incrementing nb_puck variable)
+ WAIT_POS_ORDER
+ waiting for position order (depending where we want to drop our column)
+ GO_TO_POX_Y
+ go to a position to be ready to release pucks
+ WAIT_FOR_RELEASE_ORDER
+ ready to open doors at your command
+ OPEN_DOORS
+ releasing pucks
+ WAIT_FOR_CLOSE_ORDER
+ ready to close doors at your command
+ CLOSE_DOORS
+ closing the elevator's doors
+
+Events:
+ started
+ round had begun!
+ in_position
+ elevator is in position
+ new_puck
+ we received a new puck from FB (filter bridge, not facebook)
+ ok_for_other_pucks
+ complex event (nb_pucks < 4 . (time_ok + !fb_empty))
+ not_ok_for_other_pucks
+ complex event !ok_for_other_pucks
+ time_up
+ complex event (!time_ok . fb_empty)
+ order_received
+ we received a new order
+ doors_opened
+ doors are opened
+ doors_closed
+ doors are closed
+
+IDLE:
+ started -> GO_TO_POS_X
+ match begin, we're going to be ready to get a new puck
+
+GO_TO_POS_X:
+ in_position -> WAIT_A_PUCK
+ in position and ready to get a new puck
+
+WAIT_A_PUCK:
+ new_puck -> BLAH
+ incrementing nb_puck var
+ time_up -> WAIT_POS_ORDER
+ no more time to wait a new puck
+
+BLAH:
+ ok_for_other_pucks -> GO_TO_POS_X
+ update elevator position to get a new puck
+ not_ok_for_other_pucks -> WAIT_POS_ORDER
+ no more puck, going next step
+
+WAIT_POS_ORDER:
+ order_received -> GO_TO_POX_Y
+ go to position Y
+
+GO_TO_POX_Y:
+ in_position -> WAIT_FOR_RELEASE_ORDER
+ ready to release pucks at altitude Y
+
+WAIT_FOR_RELEASE_ORDER:
+ order_received -> OPEN_DOORS
+ release pucks to the target position (I hope)
+
+OPEN_DOORS:
+ doors_opened -> WAIT_FOR_CLOSE_ORDER
+ wait for close order
+
+WAIT_FOR_CLOSE_ORDER:
+ order_received -> CLOSE_DOORS
+ closing doors
+
+CLOSE_DOORS:
+ doors_closed -> GO_TO_POS_X
+ pucks are released and elevator is ready to make a new column
diff --git a/digital/io/src/elevator.h b/digital/io/src/elevator.h
new file mode 100644
index 00000000..19cf0f67
--- /dev/null
+++ b/digital/io/src/elevator.h
@@ -0,0 +1,28 @@
+#ifndef elevator_h
+#define elevator_h
+// elevator.h
+// 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.
+//
+// }}}
+
+#endif // elevator_h
diff --git a/digital/io/src/elevator_cb.c b/digital/io/src/elevator_cb.c
new file mode 100644
index 00000000..7fc880c6
--- /dev/null
+++ b/digital/io/src/elevator_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 "elevator_cb.h"
+
+/*
+ * OPEN_DOORS =doors_opened=>
+ * => WAIT_FOR_CLOSE_ORDER
+ * wait for close order
+ */
+fsm_branch_t
+elevator__OPEN_DOORS__doors_opened (void)
+{
+ return elevator_next (OPEN_DOORS, doors_opened);
+}
+
+/*
+ * WAIT_FOR_CLOSE_ORDER =order_received=>
+ * => CLOSE_DOORS
+ * closing doors
+ */
+fsm_branch_t
+elevator__WAIT_FOR_CLOSE_ORDER__order_received (void)
+{
+ return elevator_next (WAIT_FOR_CLOSE_ORDER, order_received);
+}
+
+/*
+ * CLOSE_DOORS =doors_closed=>
+ * => GO_TO_POS_X
+ * pucks are released and elevator is ready to make a new column
+ */
+fsm_branch_t
+elevator__CLOSE_DOORS__doors_closed (void)
+{
+ return elevator_next (CLOSE_DOORS, doors_closed);
+}
+
+/*
+ * WAIT_A_PUCK =time_up=>
+ * => WAIT_POS_ORDER
+ * no more time to wait a new puck
+ */
+fsm_branch_t
+elevator__WAIT_A_PUCK__time_up (void)
+{
+ return elevator_next (WAIT_A_PUCK, time_up);
+}
+
+/*
+ * WAIT_A_PUCK =new_puck=>
+ * => BLAH
+ * incrementing nb_puck var
+ */
+fsm_branch_t
+elevator__WAIT_A_PUCK__new_puck (void)
+{
+ return elevator_next (WAIT_A_PUCK, new_puck);
+}
+
+/*
+ * GO_TO_POX_Y =in_position=>
+ * => WAIT_FOR_RELEASE_ORDER
+ * ready to release pucks at altitude Y
+ */
+fsm_branch_t
+elevator__GO_TO_POX_Y__in_position (void)
+{
+ return elevator_next (GO_TO_POX_Y, in_position);
+}
+
+/*
+ * GO_TO_POS_X =in_position=>
+ * => WAIT_A_PUCK
+ * in position and ready to get a new puck
+ */
+fsm_branch_t
+elevator__GO_TO_POS_X__in_position (void)
+{
+ return elevator_next (GO_TO_POS_X, in_position);
+}
+
+/*
+ * WAIT_FOR_RELEASE_ORDER =order_received=>
+ * => OPEN_DOORS
+ * release pucks to the target position (I hope)
+ */
+fsm_branch_t
+elevator__WAIT_FOR_RELEASE_ORDER__order_received (void)
+{
+ return elevator_next (WAIT_FOR_RELEASE_ORDER, order_received);
+}
+
+/*
+ * BLAH =not_ok_for_other_pucks=>
+ * => WAIT_POS_ORDER
+ * no more puck, going next step
+ */
+fsm_branch_t
+elevator__BLAH__not_ok_for_other_pucks (void)
+{
+ return elevator_next (BLAH, not_ok_for_other_pucks);
+}
+
+/*
+ * BLAH =ok_for_other_pucks=>
+ * => GO_TO_POS_X
+ * update elevator position to get a new puck
+ */
+fsm_branch_t
+elevator__BLAH__ok_for_other_pucks (void)
+{
+ return elevator_next (BLAH, ok_for_other_pucks);
+}
+
+/*
+ * IDLE =started=>
+ * => GO_TO_POS_X
+ * match begin, we're going to be ready to get a new puck
+ */
+fsm_branch_t
+elevator__IDLE__started (void)
+{
+ return elevator_next (IDLE, started);
+}
+
+/*
+ * WAIT_POS_ORDER =order_received=>
+ * => GO_TO_POX_Y
+ * go to position Y
+ */
+fsm_branch_t
+elevator__WAIT_POS_ORDER__order_received (void)
+{
+ return elevator_next (WAIT_POS_ORDER, order_received);
+}
+
+
diff --git a/digital/io/src/fsm.h b/digital/io/src/fsm.h
index 5246d843..ca46c886 100644
--- a/digital/io/src/fsm.h
+++ b/digital/io/src/fsm.h
@@ -102,5 +102,6 @@ fsm_handle_event (fsm_t *fsm, u8 event);
#include "move_fsm.h"
#include "top_fsm.h"
#include "filterbridge_fsm.h"
+#include "elevator_fsm.h"
#endif /* fsm_h */