summaryrefslogtreecommitdiff
path: root/digital/io
diff options
context:
space:
mode:
authorJérémy Dufour2008-05-01 00:57:16 +0200
committerJérémy Dufour2008-05-01 00:57:16 +0200
commit94ed449899985636256b5228d5e0f6bba5af2971 (patch)
treeb6ce5ee5b89bc795652f8e9564394e9a492affa1 /digital/io
parente03562b2b6fc1914b4d848fc6a6940ed55e4214a (diff)
* digital/io/src
- add a function to the sharp module to know if there is a obstacle in front of us (by taking in account the current moving direction of the bot).
Diffstat (limited to 'digital/io')
-rw-r--r--digital/io/src/main.c22
-rw-r--r--digital/io/src/sharp.c26
-rw-r--r--digital/io/src/sharp.h14
3 files changed, 44 insertions, 18 deletions
diff --git a/digital/io/src/main.c b/digital/io/src/main.c
index 2e7dafcd..e5d25cf3 100644
--- a/digital/io/src/main.c
+++ b/digital/io/src/main.c
@@ -274,25 +274,11 @@ main_loop (void)
/* If we are moving */
if (moving_direction)
{
- /* If we are moving forward */
- if (moving_direction == 1)
+ if (sharp_path_obstrued (moving_direction))
{
- /* Use only front sharps */
- if (sharp_get_interpreted (SHARP_FRONT_LEFT) ||
- sharp_get_interpreted (SHARP_FRONT_MIDDLE) ||
- sharp_get_interpreted (SHARP_FRONT_RIGHT))
- /* Generate an event for move FSM */
- FSM_HANDLE_EVENT (&move_fsm,
- MOVE_EVENT_bot_move_obstacle);
- }
- /* If we are moving backward */
- else if (moving_direction == 2)
- {
- /* Use only back sharps */
- if (sharp_get_interpreted (SHARP_BACK_LEFT) ||
- sharp_get_interpreted (SHARP_BACK_RIGHT))
- /* Generate an event for move FSM */
- FSM_HANDLE_EVENT (&move_fsm, MOVE_EVENT_bot_move_obstacle);
+ /* Generate an event for move FSM */
+ FSM_HANDLE_EVENT (&move_fsm,
+ MOVE_EVENT_bot_move_obstacle);
}
}
}
diff --git a/digital/io/src/sharp.c b/digital/io/src/sharp.c
index f5f80152..79e6c08f 100644
--- a/digital/io/src/sharp.c
+++ b/digital/io/src/sharp.c
@@ -172,3 +172,29 @@ sharp_get_interpreted (uint8_t sharp_id)
{
return sharp_cache_interpreted_[sharp_id];
}
+
+/* Is there an obstacle in front of the bot? */
+uint8_t
+sharp_path_obstrued (uint8_t moving_direction)
+{
+ /* If we are moving forward */
+ if (moving_direction == 1)
+ {
+ /* Use only front sharps */
+ if (sharp_get_interpreted (SHARP_FRONT_LEFT) ||
+ sharp_get_interpreted (SHARP_FRONT_MIDDLE) ||
+ sharp_get_interpreted (SHARP_FRONT_RIGHT))
+ /* Something in front */
+ return 1;
+ }
+ /* If we are moving backward */
+ else if (moving_direction == 2)
+ {
+ /* Use only back sharps */
+ if (sharp_get_interpreted (SHARP_BACK_LEFT) ||
+ sharp_get_interpreted (SHARP_BACK_RIGHT))
+ /* Something in front */
+ return 1;
+ }
+ return 0;
+}
diff --git a/digital/io/src/sharp.h b/digital/io/src/sharp.h
index 2417856e..3011e095 100644
--- a/digital/io/src/sharp.h
+++ b/digital/io/src/sharp.h
@@ -110,4 +110,18 @@ void sharp_set_threshold (uint8_t sharp_id, uint16_t low, uint16_t high);
*/
uint8_t sharp_get_interpreted (uint8_t sharp_id);
+/**
+ * Is there an obstacle in front of the bot?
+ * This function correctly handles the moving direction of the bot to check
+ * only the necessary sharps.
+ * @param moving_direction
+ * - 1 when moving forward ;
+ * - 2 when moving backward.
+ * @return
+ * - 0 if there is nothing in front ;
+ * - 1 if there is an obstacle in front of the bot.
+ */
+uint8_t
+sharp_path_obstrued (uint8_t moving_direction);
+
#endif /* sharp_h */