From 46a85a34f459c13e462a4d4098735fbff26964b7 Mon Sep 17 00:00:00 2001 From: dufourj Date: Thu, 17 May 2007 17:42:49 +0000 Subject: * Sharp: - add minimun value bigger thant threshold to find an obstacle. --- n/es-2007/src/sharp.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'n') diff --git a/n/es-2007/src/sharp.c b/n/es-2007/src/sharp.c index 167b86b..f98a6ea 100644 --- a/n/es-2007/src/sharp.c +++ b/n/es-2007/src/sharp.c @@ -33,7 +33,6 @@ uint16_t sharp_values[SHARP_NUMBER]; /** Thresholds */ uint16_t sharp_threshold_high_[SHARP_NUMBER], sharp_threshold_low_[SHARP_NUMBER]; -uint8_t sharp_old_state[SHARP_NUMBER]; /** Init this module. */ void @@ -73,22 +72,27 @@ sharp_update_values (uint8_t sharp_num) int8_t sharp_analyse_values (uint8_t sharp_num) { + static int8_t compt = 0; /* Check sharp exists (prevent kernel panic) */ if (sharp_num < SHARP_NUMBER) { - // XXX Check more often first if (sharp_values[sharp_num] < sharp_threshold_low_[sharp_num]) { - sharp_old_state[sharp_num] = SHARP_CLEAR; + compt = 0; return SHARP_CLEAR; } - if (sharp_values[sharp_num] > sharp_threshold_high_[sharp_num]) + else { - sharp_old_state[sharp_num] = SHARP_OBSTACLE; - return SHARP_OBSTACLE; + if (compt == 10) + { + return SHARP_OBSTACLE; + } + else + { + compt++; + return SHARP_CLEAR; + } } - /* If we are here, we are inside the threshold, look at previous value */ - return sharp_old_state[sharp_num]; } return -1; } -- cgit v1.2.3