summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--digital/io/src/Makefile2
-rw-r--r--digital/io/src/fsm.h1
-rw-r--r--digital/io/src/move.c42
-rw-r--r--digital/io/src/move.h45
-rw-r--r--digital/io/src/move_cb.c113
-rw-r--r--digital/io/src/test/move/Makefile13
-rw-r--r--digital/io/src/test/move/main.c101
7 files changed, 316 insertions, 1 deletions
diff --git a/digital/io/src/Makefile b/digital/io/src/Makefile
index 3e85aa96..ae765ece 100644
--- a/digital/io/src/Makefile
+++ b/digital/io/src/Makefile
@@ -3,7 +3,7 @@ PROGS = io
io_SOURCES = main.c asserv.c servo.avr.c eeprom.avr.c trap.c sharp.c \
simu.host.c \
fsm.c getsamples.c getsamples_fsm.c getsamples_cb.c \
- gutter_fsm.c gutter_cb.c
+ gutter_fsm.c gutter_cb.c move_fsm.c move_cb.c move.c
MODULES = proto uart twi utils adc
CONFIGFILE = avrconfig.h
# atmega8, atmega8535, atmega128...
diff --git a/digital/io/src/fsm.h b/digital/io/src/fsm.h
index bfdaf19b..d4a6fef8 100644
--- a/digital/io/src/fsm.h
+++ b/digital/io/src/fsm.h
@@ -87,5 +87,6 @@ fsm_handle_event (fsm_t *fsm, u8 event);
#include "getsamples_fsm.h"
#include "gutter_fsm.h"
+#include "move_fsm.h"
#endif /* fsm_h */
diff --git a/digital/io/src/move.c b/digital/io/src/move.c
new file mode 100644
index 00000000..211c53ac
--- /dev/null
+++ b/digital/io/src/move.c
@@ -0,0 +1,42 @@
+/* move.c */
+/* io - Input & Output with Artificial Intelligence (ai) support on AVR. {{{
+ *
+ * Copyright (C) 2008 Nélio Laranjeiro
+ *
+ * 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 "move.h"
+#include "fsm.h"
+
+struct move_data_t move_data;
+
+/** Start a move FSM. */
+void
+move_start (uint32_t position_x, uint32_t position_y)
+{
+ /* Set parameters. */
+ move_data.position_x = position_x;
+ move_data.position_y = position_y;
+ /* Start the FSM. */
+ fsm_init (&move_fsm);
+ fsm_handle_event (&move_fsm, MOVE_EVENT_ok);
+}
+
diff --git a/digital/io/src/move.h b/digital/io/src/move.h
new file mode 100644
index 00000000..a416043d
--- /dev/null
+++ b/digital/io/src/move.h
@@ -0,0 +1,45 @@
+#ifndef move_h
+#define move_h
+/* move.h */
+/* io - Input & Output with Artificial Intelligence (ai) support on AVR. {{{
+ *
+ * Copyright (C) 2008 Nélio Laranjeiro
+ *
+ * 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.
+ *
+ * }}} */
+
+/** move FSM associated data. */
+struct move_data_t
+{
+ /* Desired x position to reached. */
+ uint32_t position_x;
+ /* Desired y position to reached. */
+ uint32_t position_y;
+};
+
+
+/** move global. */
+extern struct move_data_t move_data;
+
+/** Start a move FSM. */
+void
+move_start (uint32_t position_x, uint32_t position_y);
+
+#endif /* move_h */
diff --git a/digital/io/src/move_cb.c b/digital/io/src/move_cb.c
new file mode 100644
index 00000000..05217c02
--- /dev/null
+++ b/digital/io/src/move_cb.c
@@ -0,0 +1,113 @@
+/*
+ * THIS IS AN AUTOMATICALLY GENERATED FILE, DO NOT EDIT!
+ *
+ * Skeleton for move callbacks implementation.
+ *
+ *
+ */
+#include "common.h"
+#include "fsm.h"
+#include "move_cb.h"
+#include "move.h"
+#include "asserv.h"
+
+/*
+ * START =ok=>
+ * => DESIRED_POSITION
+ * Tries to reach a position provided by the user. If the position desired can not be reached, it all try to move on the right or the left.
+ */
+fsm_branch_t
+move__START__ok (void)
+{
+ return move_next (START, ok);
+}
+
+/*
+ * DESIRED_POSITION =failed_or_blocked=>
+ * => MOVE_ON_LEFT
+ * The robot has failed to reach the position. It shall try another position before trying to reach this one again. It shall go to the on the left only if the left border is the farest one.
+ */
+fsm_branch_t
+move__DESIRED_POSITION__failed_or_blocked (void)
+{
+ return move_next (DESIRED_POSITION, failed_or_blocked);
+}
+
+/*
+ * DESIRED_POSITION =reached=>
+ * => END
+ * The position provided by the user has been reached, the FSM can stop.
+ */
+fsm_branch_t
+move__DESIRED_POSITION__reached (void)
+{
+ return move_next (DESIRED_POSITION, reached);
+}
+
+/*
+ * MOVE_ON_RIGHT =failed_or_blocked=>
+ * => MOVE_ON_RIGHT
+ * The position is fail again, it will try to reach another one.
+ */
+fsm_branch_t
+move__MOVE_ON_RIGHT__failed_or_blocked (void)
+{
+ return move_next (MOVE_ON_RIGHT, failed_or_blocked);
+}
+
+/*
+ * MOVE_ON_RIGHT =reached=>
+ * => DESIRED_POSITION
+ * The position has been reached. It will now try to reach the position provided by the user.
+ */
+fsm_branch_t
+move__MOVE_ON_RIGHT__reached (void)
+{
+ return move_next (MOVE_ON_RIGHT, reached);
+}
+
+/*
+ * MOVE_ON_RIGHT =near_border=>
+ * => MOVE_ON_LEFT
+ * The robot is now too near of the border.
+ */
+fsm_branch_t
+move__MOVE_ON_RIGHT__near_border (void)
+{
+ return move_next (MOVE_ON_RIGHT, near_border);
+}
+
+/*
+ * MOVE_ON_LEFT =failed_or_blocked=>
+ * => MOVE_ON_LEFT
+ * The position is fail again, it will try to reach another one.
+ */
+fsm_branch_t
+move__MOVE_ON_LEFT__failed_or_blocked (void)
+{
+ return move_next (MOVE_ON_LEFT, failed_or_blocked);
+}
+
+/*
+ * MOVE_ON_LEFT =reached=>
+ * => DESIRED_POSITION
+ * The position has been reached. It will now try to reach the position provided by the user.
+ */
+fsm_branch_t
+move__MOVE_ON_LEFT__reached (void)
+{
+ return move_next (MOVE_ON_LEFT, reached);
+}
+
+/*
+ * MOVE_ON_LEFT =near_border=>
+ * => MOVE_ON_RIGHT
+ * The robot is now too near of the border.
+ */
+fsm_branch_t
+move__MOVE_ON_LEFT__near_border (void)
+{
+ return move_next (MOVE_ON_LEFT, near_border);
+}
+
+
diff --git a/digital/io/src/test/move/Makefile b/digital/io/src/test/move/Makefile
new file mode 100644
index 00000000..4b301734
--- /dev/null
+++ b/digital/io/src/test/move/Makefile
@@ -0,0 +1,13 @@
+BASE= ../../../../avr
+HOST_PROGS = fsm
+IOBASE = ../..
+fsm_SOURCES = main.c $(IOBASE)/fsm.c \
+ $(IOBASE)/move_cb.c $(IOBASE)/move_fsm.c \
+ $(IOBASE)/move.c
+MODULES = utils
+CONFIGFILE =
+# -O2 : speed
+# -Os : size
+OPTIMIZE = -O2
+
+include $(BASE)/make/Makefile.gen
diff --git a/digital/io/src/test/move/main.c b/digital/io/src/test/move/main.c
new file mode 100644
index 00000000..60f62aa3
--- /dev/null
+++ b/digital/io/src/test/move/main.c
@@ -0,0 +1,101 @@
+/* main.c */
+/* {{{
+ *
+ * Copyright (C) 2008 Nélio Laranjeiro
+ *
+ * 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 <stdio.h>
+
+void
+move_print_test (fsm_t *move)
+{
+ printf ("Machine state ");
+
+ switch (move->state_current)
+ {
+ case MOVE_STATE_END:
+ printf ("END");
+ break;
+ case MOVE_STATE_DESIRED_POSITION:
+ printf ("DESIRED POSITION");
+ break;
+ case MOVE_STATE_MOVE_ON_RIGHT:
+ printf ("MOVE ON RIGHT");
+ break;
+ case MOVE_STATE_MOVE_ON_LEFT:
+ printf ("MOVE ON LEFT");
+ break;
+ default:
+ printf ("STATE_NB");
+ }
+ printf ("\n");
+}
+
+int
+main (void)
+{
+ fsm_init (&move_fsm);
+
+ fsm_handle_event (&move_fsm, MOVE_EVENT_ok);
+
+ move_print_test (&move_fsm);
+
+ fsm_handle_event (&move_fsm, MOVE_EVENT_failed_or_blocked);
+ move_print_test (&move_fsm);
+
+ fsm_handle_event (&move_fsm, MOVE_EVENT_failed_or_blocked);
+ move_print_test (&move_fsm);
+
+ fsm_handle_event (&move_fsm, MOVE_EVENT_near_border);
+ move_print_test (&move_fsm);
+
+ fsm_handle_event (&move_fsm, MOVE_EVENT_failed_or_blocked);
+ move_print_test (&move_fsm);
+
+ fsm_handle_event (&move_fsm, MOVE_EVENT_reached);
+ move_print_test (&move_fsm);
+
+ fsm_handle_event (&move_fsm, MOVE_EVENT_failed_or_blocked);
+ move_print_test (&move_fsm);
+
+ fsm_handle_event (&move_fsm, MOVE_EVENT_reached);
+ move_print_test (&move_fsm);
+
+ fsm_handle_event (&move_fsm, MOVE_EVENT_reached);
+ move_print_test (&move_fsm);
+
+ return 0;
+}
+
+//void
+//asserv_set_x_position (uint32_t position)
+//{
+// printf ("X position : %d\n", position);
+//}
+//
+//void
+//asserv_set_y_position (int32_t y)
+//{
+// printf ("Y position : %d\n", y);
+//}