summaryrefslogtreecommitdiffhomepage
path: root/digital/io/src/move_cb.c
diff options
context:
space:
mode:
authorNélio Laranjeiro2008-04-21 23:35:19 +0200
committerNélio Laranjeiro2008-04-21 23:35:19 +0200
commit06f1c2cd6f511ea0990d3bb60103cf9512b8d634 (patch)
tree1f0e0cf25f3c25eed9cd6a17b606d2a3abfa0187 /digital/io/src/move_cb.c
parent32eb5589411c13e6ed92a3af6e9d7a74c3599edf (diff)
move : update the move fsm transitions. (Not optimized in code size).
Diffstat (limited to 'digital/io/src/move_cb.c')
-rw-r--r--digital/io/src/move_cb.c141
1 files changed, 110 insertions, 31 deletions
diff --git a/digital/io/src/move_cb.c b/digital/io/src/move_cb.c
index 65ec02ea..13571d29 100644
--- a/digital/io/src/move_cb.c
+++ b/digital/io/src/move_cb.c
@@ -11,10 +11,10 @@
#include "move.h"
#include "asserv.h"
+
/* if the left border is under 500 mm of the actual position do not go there. */
#define MOVE_BORDER_LEVEL 200
-
/*
* IDLE =start=>
* => DESIRED_POSITION
@@ -28,14 +28,74 @@ move__IDLE__start (void)
}
/*
- * DESIRED_POSITION =failed_or_blocked=>
+ * MOVE_ON_RIGHT =failed=>
+ * => MOVE_ON_LEFT
+ * The position is fail again, it will try to reach another one.
+ */
+fsm_branch_t
+move__MOVE_ON_RIGHT__failed (void)
+{
+ asserv_position_t pos;
+ asserv_position_t new_pos;
+
+ asserv_get_position (&pos);
+ new_pos.x = pos.x - MOVE_BORDER_LEVEL;
+ new_pos.y = pos.y;
+ new_pos.a = pos.a;
+
+ if (move_can_go_on_left_or_right (pos, new_pos))
+ {
+ asserv_goto (new_pos.x, new_pos.y);
+ }
+
+ return move_next (MOVE_ON_RIGHT, failed);
+}
+
+/*
+ * 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)
+{
+ asserv_goto (move_data.position_x, move_data.position_y);
+ return move_next (MOVE_ON_RIGHT, reached);
+}
+
+/*
+ * MOVE_ON_RIGHT =blocked=>
+ * => MOVE_ON_LEFT
+ * The position is fail again, it will go backward to reach another one.
+ */
+fsm_branch_t
+move__MOVE_ON_RIGHT__blocked (void)
+{
+ asserv_position_t pos;
+ asserv_position_t new_pos;
+
+ asserv_get_position (&pos);
+ new_pos.x = pos.x - MOVE_BORDER_LEVEL;
+ new_pos.y = pos.y;
+ new_pos.a = pos.a;
+
+ if (move_can_go_on_left_or_right (pos, new_pos))
+ {
+ asserv_goto (new_pos.x, new_pos.y);
+ }
+
+ return move_next (MOVE_ON_RIGHT, blocked);
+}
+
+/*
+ * DESIRED_POSITION =failed=>
* near_left_border => MOVE_ON_RIGHT
- * Same process as the previous one but on the right.
+ * 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 right only if the right border is the farest one.
* near_right_border => 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)
+move__DESIRED_POSITION__failed (void)
{
asserv_position_t pos;
asserv_position_t new_pos;
@@ -47,20 +107,20 @@ move__DESIRED_POSITION__failed_or_blocked (void)
if (move_can_go_on_left_or_right (pos, new_pos))
{
asserv_goto (new_pos.x, new_pos.y);
- return move_next_branch (DESIRED_POSITION, failed_or_blocked, near_left_border);
+ return move_next_branch (DESIRED_POSITION, failed, near_left_border);
}
else
{
new_pos.x = pos.x + MOVE_BORDER_LEVEL;
// replace this by the correct function.
asserv_goto (new_pos.x, new_pos.y);
- return move_next_branch (DESIRED_POSITION, failed_or_blocked, near_right_border);
+ return move_next_branch (DESIRED_POSITION, failed, near_right_border);
}
}
/*
* DESIRED_POSITION =reached=>
- * => END
+ * => IDLE
* The position provided by the user has been reached, the FSM can stop.
*/
fsm_branch_t
@@ -70,48 +130,43 @@ move__DESIRED_POSITION__reached (void)
}
/*
- * MOVE_ON_RIGHT =failed_or_blocked_or_near_border=>
- * => MOVE_ON_LEFT
- * The position is fail again, it will try to reach another one.
+ * DESIRED_POSITION =blocked=>
+ * near_right_border => 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.
+ * near_left_border => MOVE_ON_RIGHT
+ * 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 right only if the right border is the farest one.
*/
fsm_branch_t
-move__MOVE_ON_RIGHT__failed_or_blocked_or_near_border (void)
+move__DESIRED_POSITION__blocked (void)
{
asserv_position_t pos;
asserv_position_t new_pos;
asserv_get_position (&pos);
- new_pos.x = pos.x - MOVE_BORDER_LEVEL;
- new_pos.y = pos.y;
- new_pos.a = pos.a;
+ new_pos = pos;
+ new_pos.x += MOVE_BORDER_LEVEL ;
if (move_can_go_on_left_or_right (pos, new_pos))
{
asserv_goto (new_pos.x, new_pos.y);
+ return move_next_branch (DESIRED_POSITION, blocked, near_right_border);
+ }
+ else
+ {
+ new_pos.x = pos.x + MOVE_BORDER_LEVEL;
+ // replace this by the correct function.
+ asserv_goto (new_pos.x, new_pos.y);
+ return move_next_branch (DESIRED_POSITION, blocked, near_left_border);
}
-
- return move_next (MOVE_ON_RIGHT, failed_or_blocked_or_near_border);
-}
-
-/*
- * 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)
-{
- asserv_goto (move_data.position_x, move_data.position_y);
- return move_next (MOVE_ON_RIGHT, reached);
}
/*
- * MOVE_ON_LEFT =failed_or_blocked_or_near_border=>
+ * MOVE_ON_LEFT =failed=>
* => MOVE_ON_RIGHT
* The position is fail again, it will try to reach another one.
*/
fsm_branch_t
-move__MOVE_ON_LEFT__failed_or_blocked_or_near_border (void)
+move__MOVE_ON_LEFT__failed (void)
{
asserv_position_t pos;
asserv_position_t new_pos;
@@ -126,7 +181,7 @@ move__MOVE_ON_LEFT__failed_or_blocked_or_near_border (void)
asserv_goto (new_pos.x, new_pos.y);
}
- return move_next (MOVE_ON_LEFT, failed_or_blocked_or_near_border);
+ return move_next (MOVE_ON_LEFT, failed);
}
/*
@@ -141,4 +196,28 @@ move__MOVE_ON_LEFT__reached (void)
return move_next (MOVE_ON_LEFT, reached);
}
+/*
+ * MOVE_ON_LEFT =blocked=>
+ * => MOVE_ON_RIGHT
+ * The position is fail again, it will go backward to reach another one.
+ */
+fsm_branch_t
+move__MOVE_ON_LEFT__blocked (void)
+{
+ asserv_position_t pos;
+ asserv_position_t new_pos;
+
+ asserv_get_position (&pos);
+ new_pos.x = pos.x + MOVE_BORDER_LEVEL;
+ new_pos.y = pos.y;
+ new_pos.a = pos.a;
+ if (move_can_go_on_left_or_right (pos, new_pos))
+ {
+ // call the correct function to go to the right.
+ asserv_goto (new_pos.x, new_pos.y);
+ }
+
+ return move_next (MOVE_ON_LEFT, blocked);
+}
+