summaryrefslogtreecommitdiffhomepage
path: root/digital/io/src
diff options
context:
space:
mode:
Diffstat (limited to 'digital/io/src')
-rw-r--r--digital/io/src/Makefile2
-rw-r--r--digital/io/src/cylinder.c25
-rw-r--r--digital/io/src/cylinder.fsm102
-rw-r--r--digital/io/src/cylinder.h28
-rw-r--r--digital/io/src/cylinder_cb.c173
-rw-r--r--digital/io/src/fsm.h1
6 files changed, 330 insertions, 1 deletions
diff --git a/digital/io/src/Makefile b/digital/io/src/Makefile
index 5c572d52..87486890 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 elevator
+FSM_SOURCES := getsamples gutter move top filterbridge elevator cylinder
# Include FSM makefile.
include $(BASE)/make/Makefile.fsm
diff --git a/digital/io/src/cylinder.c b/digital/io/src/cylinder.c
new file mode 100644
index 00000000..9520e0b9
--- /dev/null
+++ b/digital/io/src/cylinder.c
@@ -0,0 +1,25 @@
+/* cylinder.c */
+/* io - Input & Output with Artificial Intelligence (ai) support on AVR. {{{
+ *
+ * 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 "cylinder.h"
diff --git a/digital/io/src/cylinder.fsm b/digital/io/src/cylinder.fsm
new file mode 100644
index 00000000..5b4827ae
--- /dev/null
+++ b/digital/io/src/cylinder.fsm
@@ -0,0 +1,102 @@
+# Cylinder FSM
+# Control the puck's entrance
+cylinder
+
+States:
+ IDLE
+ waiting for init
+ INIT
+ initializing cylinder
+ WAIT_A_PUCK
+ waiting a puck enter in cylinder
+ TURN_PLUS_2
+ turn cylinder to 2 positions after
+ WAIT_FOR_BRIDGE_READY
+ waiting for the bridge is ready
+ TURN_PLUS_2_AGAIN
+ release puck to the bridge after a wait (cf. WAIT_FOR_BRIDGE_READY)
+ TURN_PLUS_4
+ release a puck directly from the ground to the bridge
+ PROBE_OF
+ probe optical fence to detect puck in position 3
+ TURN_MINUS_3
+ turn cylinder to 3 positions before to eject puck to the ground
+ TURN_MINUS_1
+ turn cylinder to 1 position before to prevent new puck enter in the robot
+ WAIT_FOR_PUCKS_RELEASE
+ waiting for pucks release from the lift
+ TURN_PLUS_1
+ open the puck entrance
+
+Events:
+ jack_in
+ the init signal
+ init_done
+ cylinder ready for a new match
+ new_puck
+ there is a puck in position 1
+ move_done
+ cylinder move finished
+ bridge_ready
+ bridge ready to get a new puck
+ probe_done
+ Optical fence probe finished
+ lift_ready
+ lift ready to get pucks
+
+
+IDLE:
+ jack_in -> INIT
+ initialize robot
+
+INIT:
+ init_done -> WAIT_A_PUCK
+ the cylinder is ready to get pucks
+
+WAIT_A_PUCK:
+ new_puck: bridge_full -> TURN_PLUS_2
+ bridge full, waiting before release puck to the bridge
+ new_puck: bridge_ready -> TURN_PLUS_4
+ put puck to the bridge
+
+TURN_PLUS_2:
+ move_done -> WAIT_FOR_BRIDGE_READY
+ bridge full, waiting for Bison Fute's clearance
+
+WAIT_FOR_BRIDGE_READY:
+ bridge_ready -> TURN_PLUS_2_AGAIN
+ bridge clear, delivering puck...
+
+TURN_PLUS_2_AGAIN:
+ move_done -> PROBE_OF
+ there is a puck to the cylinder?
+
+TURN_PLUS_4:
+ move_done -> PROBE_OF
+ there is a puck to the cylinder?
+
+PROBE_OF:
+ probe_done: puck_detected_and_lift_full -> TURN_MINUS_3
+ BAD CASE, there is an undesirable puck to the cylinder
+ probe_done: puck_detected_and_lift_ready -> WAIT_FOR_BRIDGE_READY
+ there is a puck, we take a shortcut...
+ probe_done: cylinder_empty_and_lift_full -> TURN_MINUS_1
+ stop accepting new puck
+ probe_done: cylinder_empty_and_lift_ready -> WAIT_A_PUCK
+ ready for a new puck
+
+TURN_MINUS_3:
+ move_done -> WAIT_FOR_PUCKS_RELEASE
+ evil puck dropped and robot entrance closed
+
+TURN_MINUS_1:
+ move_done -> WAIT_FOR_PUCKS_RELEASE
+ robot entrance closed
+
+WAIT_FOR_PUCKS_RELEASE:
+ lift_ready -> TURN_PLUS_1
+ robot ready for new puck, open door
+
+TURN_PLUS_1:
+ move_done -> WAIT_A_PUCK
+ door opened, ready for a new puck
diff --git a/digital/io/src/cylinder.h b/digital/io/src/cylinder.h
new file mode 100644
index 00000000..8b9cb427
--- /dev/null
+++ b/digital/io/src/cylinder.h
@@ -0,0 +1,28 @@
+#ifndef cylinder_h
+#define cylinder_h
+/* cylinder.h */
+/* io - Input & Output with Artificial Intelligence (ai) support on AVR. {{{
+ *
+ * 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.
+ *
+ * }}} */
+
+#endif /* cylinder_h */
diff --git a/digital/io/src/cylinder_cb.c b/digital/io/src/cylinder_cb.c
new file mode 100644
index 00000000..1ff30760
--- /dev/null
+++ b/digital/io/src/cylinder_cb.c
@@ -0,0 +1,173 @@
+/* cylinder_cb.c - cylinder 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 "cylinder_cb.h"
+
+/*
+ * WAIT_FOR_BRIDGE_READY =bridge_ready=>
+ * => TURN_PLUS_2_AGAIN
+ * bridge clear, delivering puck...
+ */
+fsm_branch_t
+cylinder__WAIT_FOR_BRIDGE_READY__bridge_ready (void)
+{
+ return cylinder_next (WAIT_FOR_BRIDGE_READY, bridge_ready);
+}
+
+/*
+ * WAIT_A_PUCK =new_puck=>
+ * bridge_ready => TURN_PLUS_4
+ * put puck to the bridge
+ * bridge_full => TURN_PLUS_2
+ * bridge full, waiting before release puck to the bridge
+ */
+fsm_branch_t
+cylinder__WAIT_A_PUCK__new_puck (void)
+{
+ return cylinder_next_branch (WAIT_A_PUCK, new_puck, bridge_ready);
+ return cylinder_next_branch (WAIT_A_PUCK, new_puck, bridge_full);
+}
+
+/*
+ * INIT =init_done=>
+ * => WAIT_A_PUCK
+ * the cylinder is ready to get pucks
+ */
+fsm_branch_t
+cylinder__INIT__init_done (void)
+{
+ return cylinder_next (INIT, init_done);
+}
+
+/*
+ * WAIT_FOR_PUCKS_RELEASE =lift_ready=>
+ * => TURN_PLUS_1
+ * robot ready for new puck, open door
+ */
+fsm_branch_t
+cylinder__WAIT_FOR_PUCKS_RELEASE__lift_ready (void)
+{
+ return cylinder_next (WAIT_FOR_PUCKS_RELEASE, lift_ready);
+}
+
+/*
+ * IDLE =jack_in=>
+ * => INIT
+ * initialize robot
+ */
+fsm_branch_t
+cylinder__IDLE__jack_in (void)
+{
+ return cylinder_next (IDLE, jack_in);
+}
+
+/*
+ * TURN_PLUS_2 =move_done=>
+ * => WAIT_FOR_BRIDGE_READY
+ * bridge full, waiting for Bison Fute's clearance
+ */
+fsm_branch_t
+cylinder__TURN_PLUS_2__move_done (void)
+{
+ return cylinder_next (TURN_PLUS_2, move_done);
+}
+
+/*
+ * PROBE_OF =probe_done=>
+ * puck_detected_and_lift_full => TURN_MINUS_3
+ * BAD CASE, there is an undesirable puck to the cylinder
+ * puck_detected_and_lift_ready => WAIT_FOR_BRIDGE_READY
+ * there is a puck, we take a shortcut...
+ * cylinder_empty_and_lift_ready => WAIT_A_PUCK
+ * ready for a new puck
+ * cylinder_empty_and_lift_full => TURN_MINUS_1
+ * stop accepting new puck
+ */
+fsm_branch_t
+cylinder__PROBE_OF__probe_done (void)
+{
+ return cylinder_next_branch (PROBE_OF, probe_done, puck_detected_and_lift_full);
+ return cylinder_next_branch (PROBE_OF, probe_done, puck_detected_and_lift_ready);
+ return cylinder_next_branch (PROBE_OF, probe_done, cylinder_empty_and_lift_ready);
+ return cylinder_next_branch (PROBE_OF, probe_done, cylinder_empty_and_lift_full);
+}
+
+/*
+ * TURN_PLUS_1 =move_done=>
+ * => WAIT_A_PUCK
+ * door opened, ready for a new puck
+ */
+fsm_branch_t
+cylinder__TURN_PLUS_1__move_done (void)
+{
+ return cylinder_next (TURN_PLUS_1, move_done);
+}
+
+/*
+ * TURN_MINUS_1 =move_done=>
+ * => WAIT_FOR_PUCKS_RELEASE
+ * robot entrance closed
+ */
+fsm_branch_t
+cylinder__TURN_MINUS_1__move_done (void)
+{
+ return cylinder_next (TURN_MINUS_1, move_done);
+}
+
+/*
+ * TURN_MINUS_3 =move_done=>
+ * => WAIT_FOR_PUCKS_RELEASE
+ * evil puck dropped and robot entrance closed
+ */
+fsm_branch_t
+cylinder__TURN_MINUS_3__move_done (void)
+{
+ return cylinder_next (TURN_MINUS_3, move_done);
+}
+
+/*
+ * TURN_PLUS_2_AGAIN =move_done=>
+ * => PROBE_OF
+ * there is a puck to the cylinder?
+ */
+fsm_branch_t
+cylinder__TURN_PLUS_2_AGAIN__move_done (void)
+{
+ return cylinder_next (TURN_PLUS_2_AGAIN, move_done);
+}
+
+/*
+ * TURN_PLUS_4 =move_done=>
+ * => PROBE_OF
+ * there is a puck to the cylinder?
+ */
+fsm_branch_t
+cylinder__TURN_PLUS_4__move_done (void)
+{
+ return cylinder_next (TURN_PLUS_4, move_done);
+}
+
+
diff --git a/digital/io/src/fsm.h b/digital/io/src/fsm.h
index ca46c886..83f51b4b 100644
--- a/digital/io/src/fsm.h
+++ b/digital/io/src/fsm.h
@@ -103,5 +103,6 @@ fsm_handle_event (fsm_t *fsm, u8 event);
#include "top_fsm.h"
#include "filterbridge_fsm.h"
#include "elevator_fsm.h"
+#include "cylinder_fsm.h"
#endif /* fsm_h */