summaryrefslogtreecommitdiff
path: root/n
diff options
context:
space:
mode:
authorgaillaro2006-05-17 16:44:24 +0000
committergaillaro2006-05-17 16:44:24 +0000
commit78be69dba5d5b6f00beabacd599169fc1d91b24d (patch)
treed24e7a2a0a22f7d9111ecfe556141f7c670c463f /n
parente8634493098188f1a33dfa491a8bfa4b6e5dbd35 (diff)
* detection vert/rouge/bleu marche
* detection balle blanc/noir a faire marcher main.c * suppression des commandes set_threshold, load/save values from/to eeprom sniff_rvb.c * suppression hysteresis - ni filtre déjà * suppresion de la fonction set_threshold * suppression de tableaux statiques inutiles * nettoyage sensor_eeprom.c *suppression du fichier
Diffstat (limited to 'n')
-rw-r--r--n/es-2006/src/main.c16
-rw-r--r--n/es-2006/src/sensor_eeprom.c89
-rw-r--r--n/es-2006/src/sniff_rvb.c147
-rw-r--r--n/es-2006/src/sniff_rvb.h26
4 files changed, 48 insertions, 230 deletions
diff --git a/n/es-2006/src/main.c b/n/es-2006/src/main.c
index c65fd55..68fffa8 100644
--- a/n/es-2006/src/main.c
+++ b/n/es-2006/src/main.c
@@ -35,7 +35,6 @@
#include "sniff_rvb.h" /* RVB sensors analysis */
#include "timer_1.h" /* timer/counter 1 */
#include "others.h" /* define game color mode + jack + frontal sensor */
-#include "sensor_eeprom.c"
#include "barillet.h"
#include "servo_motor.h"
@@ -79,13 +78,6 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
sensor_rvb_stat_enable[compt] = sensor_rvb_stats[compt] =
args[2];
break;
- /* Set threshold for the differents colors */
- case c ('s', 9):
- sniff_rvb_set_threshold
- (args[0], v8_to_v16 (args[1], args[2]),
- v8_to_v16 (args[3], args[4]), v8_to_v16 (args[5], args[6]),
- v8_to_v16 (args[7], args[8]));
- break;
/* Set current color as reference */
case c ('r', 3):
temp_16b = v8_to_v16 (args[0], args[1]);
@@ -105,14 +97,6 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
case c ('c', 0 ):
proto_send1b('c', others_selectcoul());
break;
- /* Load sniff values from eeprom */
- case c ('l', 0):
- sensor_eeprom_read_params ();
- break;
- /* saVe sniff values from eeprom */
- case c ('v', 0):
- sensor_eeprom_write_params ();
- break;
/* Communication with the servo motor */
case c ('m', 2):
servo_motor_set_pos (args[0], args[1]);
diff --git a/n/es-2006/src/sensor_eeprom.c b/n/es-2006/src/sensor_eeprom.c
deleted file mode 100644
index c9bcdc1..0000000
--- a/n/es-2006/src/sensor_eeprom.c
+++ /dev/null
@@ -1,89 +0,0 @@
-/* sniff_eeprom.c */
-/* es - Input/Output general purpose board. {{{
- *
- * Copyright (C) 2006 Dufour Jrmy
- *
- * Robot APB Team/Efrei 2004.
- * Web: http://assos.efrei.fr/robot/
- * Email: robot AT efrei DOT fr
- *
- * 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 <avr/eeprom.h>
-
-/* Change the eeprom key each time you change eeprom format. */
-#define EEPROM_KEY 0x45
-#define EEPROM_START 256
-
-/* +AutoDec */
-/* -AutoDec */
-
-/* Read parameters from eeprom. */
-static void
-sensor_eeprom_read_params (void)
-{
- uint8_t *p8 = (uint8_t *) EEPROM_START;
- uint16_t *p16;
- uint8_t sensor, compt, color;
- if (eeprom_read_byte (p8++) != EEPROM_KEY)
- return;
- p16 = (uint16_t *) p8;
- for (sensor = 0; sensor < RVB_MAX_SENSOR; sensor++)
- for (compt = 0; compt < RVB_SNIFF_MAX_INDEX; compt++)
- sniff_rvb_reference_color[sensor][compt] = eeprom_read_word (p16++);
- for (color = 0; color < 2; color++)
- for (sensor = 0; sensor < RVB_MAX_SENSOR; sensor++)
- for (compt = 0; compt < RVB_SNIFF_MAX_INDEX; compt++)
- sniff_rvb_threshold[color][sensor][compt] = eeprom_read_word (p16++);
- p8 = (uint8_t *) p16;
- for (color = 0; color < 2; color++)
- for (sensor = 0; sensor < RVB_MAX_SENSOR; sensor++)
- for (compt = 0; compt < RVB_SNIFF_MAX_INDEX; compt++)
- sniff_rvb_sign[color][sensor][compt] = eeprom_read_byte (p8++);
-}
-
-/* Write parameters to eeprom. */
-static void
-sensor_eeprom_write_params (void)
-{
- uint8_t *p8 = (uint8_t *) EEPROM_START;
- uint16_t *p16;
- uint8_t sensor, compt, color;
- eeprom_write_byte (p8++, EEPROM_KEY);
- p16 = (uint16_t *) p8;
- for (sensor = 0; sensor < RVB_MAX_SENSOR; sensor++)
- for (compt = 0; compt < RVB_SNIFF_MAX_INDEX; compt++)
- eeprom_write_word (p16++, sniff_rvb_reference_color[sensor][compt]);
- for (color = 0; color < 2; color++)
- for (sensor = 0; sensor < RVB_MAX_SENSOR; sensor++)
- for (compt = 0; compt < RVB_SNIFF_MAX_INDEX; compt++)
- eeprom_write_word (p16++, sniff_rvb_threshold[color][sensor][compt]);
- p8 = (uint8_t *) p16;
- for (color = 0; color < 2; color++)
- for (sensor = 0; sensor < RVB_MAX_SENSOR; sensor++)
- for (compt = 0; compt < RVB_SNIFF_MAX_INDEX; compt++)
- eeprom_write_byte (p8++, sniff_rvb_sign[color][sensor][compt]);
-}
-
-/* Clear eeprom parameters. */
-// static void
-// sensor_eeprom_clear_params (void)
-// {
-// uint8_t *p = (uint8_t *) EEPROM_START;
-// eeprom_write_byte (p, 0xff);
-// }
-
diff --git a/n/es-2006/src/sniff_rvb.c b/n/es-2006/src/sniff_rvb.c
index 5941316..1b0bc96 100644
--- a/n/es-2006/src/sniff_rvb.c
+++ b/n/es-2006/src/sniff_rvb.c
@@ -43,7 +43,16 @@ uint8_t sniff_rvb_sign[2][RVB_MAX_SENSOR][RVB_SNIFF_MAX_INDEX];
uint16_t sniff_rvb_reference_color_min[RVB_MAX_SENSOR][RVB_SNIFF_MAX_INDEX];
uint16_t sniff_rvb_reference_color_max[RVB_MAX_SENSOR][RVB_SNIFF_MAX_INDEX];
/** Ratio for the computing the min/max value from the reference color. */
-uint8_t sniff_rvb_ref_ratio = 3;
+uint8_t sniff_rvb_ref_ratio = 4;
+/* if no difference between 2 colors we can have problems, this constant is
+ * the minimum value for one component to get used */
+int16_t sniff_rvb_min_diff = 1000;
+
+/* test with new robot clothes */
+/* ball black/white detection */
+uint16_t green_limit = 7000;
+uint16_t clear_limit = 8000;
+
/** Configure the sensor analysis system. */
void
@@ -78,37 +87,32 @@ sniff_rvb_try_reference (uint8_t sensor_num, uint16_t
return 0;
}
+/* test "barillet" black/white */
+uint8_t
+sniff_rvb_ball (uint8_t sensor)
+{
+ if ((sensor_rvb_values[sensor][RVB_INDEX_GREEN] > green_limit)
+ && (sensor_rvb_values[sensor][RVB_INDEX_CLEAR] > clear_limit))
+ return RVB_SNIFF_BLACK;
+ else return RVB_SNIFF_WHITE;
+}
/* Test blue or red */
uint8_t
-sniff_rvb_analysis_color_other (uint8_t sensor, uint8_t color,
- uint16_t threshold[RVB_SNIFF_MAX_INDEX],
- uint8_t sign[RVB_SNIFF_MAX_INDEX])
+sniff_rvb_analysis_color_other (uint8_t sensor, uint8_t color)
{
- uint8_t compt;
- uint8_t what_is_it = color;
- for (compt = 0; compt < RVB_SNIFF_MAX_INDEX; compt++)
+ uint8_t what_is_it = RVB_SNIFF_OTHER;
+ if (color == RVB_SNIFF_BLUE)
+ {
+ if (sensor_rvb_values[sensor][RVB_INDEX_GREEN] > sniff_rvb_reference_color[sensor][RVB_INDEX_GREEN])
+ what_is_it = RVB_SNIFF_BLUE;
+ }
+ else if (color == RVB_SNIFF_RED)
{
- // if relative threshold is positive, current value must be greater
- // than the threshold
- if (sign[compt] > 0)
- {
- if (sensor_rvb_values[sensor][compt] > threshold[compt])
- {
- continue;
- }
- }
- // if negative, must be lower
- else
- {
- if (sensor_rvb_values[sensor][compt] < threshold[compt])
- {
- continue;
- }
- }
- // if conditions not true, color is not blue
- what_is_it = RVB_SNIFF_OTHER;
- break;
+ if ((sensor_rvb_values[sensor][RVB_INDEX_RED] < sniff_rvb_reference_color[sensor][RVB_INDEX_RED])
+ && (sensor_rvb_values[sensor][RVB_INDEX_CLEAR] > sniff_rvb_reference_color[sensor][RVB_INDEX_CLEAR])
+ && (sensor_rvb_values[sensor][RVB_INDEX_GREEN] > sniff_rvb_reference_color[sensor][RVB_INDEX_GREEN]))
+ what_is_it = RVB_SNIFF_RED;
}
return what_is_it;
}
@@ -117,7 +121,6 @@ sniff_rvb_analysis_color_other (uint8_t sensor, uint8_t color,
uint8_t
sniff_rvb_analysis_color (uint8_t sensor, uint8_t mode)
{
- static uint8_t hysteresis[RVB_MAX_SENSOR] = {RVB_SNIFF_GREEN};
uint8_t compt, what_is_it = RVB_SNIFF_GREEN;
/* test for green */
for (compt = 0; compt < RVB_SNIFF_MAX_INDEX; compt++)
@@ -131,36 +134,23 @@ sniff_rvb_analysis_color (uint8_t sensor, uint8_t mode)
}
if ((what_is_it == RVB_SNIFF_GREEN) || (mode == RVB_SNIFF_ONLY_GREEN))
- goto sniff_rvb_set_ref_color_end;
+ return what_is_it;
- /* test for blue */
- if (sniff_rvb_analysis_color_other (sensor, RVB_SNIFF_BLUE,
- sniff_rvb_threshold[RVB_THRESHOLD_BLUE][sensor],
- sniff_rvb_sign[RVB_THRESHOLD_BLUE][sensor]) == RVB_SNIFF_BLUE)
- {
- what_is_it = RVB_SNIFF_BLUE;
- goto sniff_rvb_set_ref_color_end;
- }
/* test for red */
- if (sniff_rvb_analysis_color_other (sensor, RVB_SNIFF_RED,
- sniff_rvb_threshold[RVB_THRESHOLD_RED][sensor],
- sniff_rvb_sign[RVB_THRESHOLD_RED][sensor]) == RVB_SNIFF_RED)
+ if (sniff_rvb_analysis_color_other (sensor, RVB_SNIFF_RED))
{
what_is_it = RVB_SNIFF_RED;
- goto sniff_rvb_set_ref_color_end;
- }
- /* else other */
- what_is_it = RVB_SNIFF_OTHER;
-
-/* sometimes it's goooood ! */
-sniff_rvb_set_ref_color_end:
- if (what_is_it == hysteresis[sensor])
return what_is_it;
- else
+ }
+ /* test for blue */
+ if (sniff_rvb_analysis_color_other (sensor, RVB_SNIFF_BLUE))
{
- hysteresis[sensor] = what_is_it;
- return RVB_SNIFF_GREEN;
+ what_is_it = RVB_SNIFF_BLUE;
+ return what_is_it;
}
+ /* else other */
+ what_is_it = RVB_SNIFF_OTHER;
+ return what_is_it;
}
@@ -181,42 +171,6 @@ sniff_rvb_set_ref_color_green (uint8_t sensor)
}
}
-/* sub function of sniff_rvb_set_ref_color */
-/* XXX call only after the reference color initialization has been done */
-void
-sniff_rvb_set_ref_color_other (uint8_t sensor, uint8_t color)
-{
- uint8_t compt;
- uint16_t *threshold;
- uint8_t *sign;
- if (color == RVB_SNIFF_BLUE)
- {
- threshold = sniff_rvb_threshold[RVB_THRESHOLD_BLUE][sensor];
- sign = sniff_rvb_sign[RVB_THRESHOLD_BLUE][sensor];
- }
- else
- {
- threshold = sniff_rvb_threshold[RVB_THRESHOLD_RED][sensor];
- sign = sniff_rvb_sign[RVB_THRESHOLD_RED][sensor];
- }
- /* get sensor values */
- /* test if valid */
- if (sensor_rvb_values[sensor][0] != 0)
- for (compt = 0; compt < RVB_SNIFF_MAX_INDEX; compt++)
- {
- /* compute threshold */
- int16_t tmp = (sensor_rvb_values[sensor][compt]
- - sniff_rvb_reference_color[sensor][compt]) / 2;
- // XXX use ratio instead of 2
- threshold[compt] = tmp + sniff_rvb_reference_color[sensor][compt];
- /* store sign for faster processing later */
- if (tmp > 0)
- sign[compt] = RVB_THRESHOLD_POSITIVE;
- else
- sign[compt] = RVB_THRESHOLD_NEGATIVE;
- }
-}
-
/** Set the current color seen by some sensors as the reference color
* and do some cache creation for preventing useless computing. */
void
@@ -229,26 +183,7 @@ sniff_rvb_set_ref_color (uint8_t sensor, uint8_t color)
break;
case RVB_SNIFF_RED:
case RVB_SNIFF_BLUE:
- sniff_rvb_set_ref_color_other (sensor, color);
break;
}
}
-/** Set the threshold of the differents colors. */
-void
-sniff_rvb_set_threshold (uint8_t color, int16_t red_ts, int16_t blue_ts,
- int16_t clear_ts, int16_t green_ts)
-{
- // XXX no green needed
- switch (color)
- {
- case RVB_SNIFF_RED:
- case RVB_SNIFF_BLUE:
- case RVB_SNIFF_GREEN:
-// sniff_rvb_thresholdtable[color][0] = red_ts;
-// sniff_rvb_thresholdtable[color][1] = blue_ts;
-// sniff_rvb_thresholdtable[color][2] = clear_ts;
-// sniff_rvb_thresholdtable[color][3] = green_ts;
- break;
- }
-}
diff --git a/n/es-2006/src/sniff_rvb.h b/n/es-2006/src/sniff_rvb.h
index 313af5a..b318485 100644
--- a/n/es-2006/src/sniff_rvb.h
+++ b/n/es-2006/src/sniff_rvb.h
@@ -36,6 +36,8 @@
#define RVB_SNIFF_BLUE 1
#define RVB_SNIFF_RED 2
#define RVB_SNIFF_OTHER 3
+#define RVB_SNIFF_BLACK 4
+#define RVB_SNIFF_WHITE 5
/** Mode for color detection
* ONLY_GREEN is faster but tells only if it's green or not
@@ -44,30 +46,11 @@
#define RVB_SNIFF_ALL_COLORS 1
-/** Used for blue/red test */
-#define RVB_THRESHOLD_POSITIVE 0
-#define RVB_THRESHOLD_NEGATIVE 1
-
-#define RVB_THRESHOLD_BLUE 0
-#define RVB_THRESHOLD_RED 1
-
-/** Reference color. */
-extern uint16_t sniff_rvb_reference_color[RVB_MAX_SENSOR][RVB_SNIFF_MAX_INDEX];
-/** Threshold table data. */
-extern uint16_t sniff_rvb_threshold[2][RVB_MAX_SENSOR][RVB_SNIFF_MAX_INDEX];
-/** Used to build threshold */
-extern uint8_t sniff_rvb_sign[2][RVB_MAX_SENSOR][RVB_SNIFF_MAX_INDEX];
-
/** Set the current color seen by some sensors as the reference color.
* It must be called at the begining of the match for setting the green value.
*/
void sniff_rvb_set_ref_color (uint8_t sensor, uint8_t color);
-/** Set the threshold of the differents colors.
- * There are used for the algorithm that distinguish colors.
- */
-void sniff_rvb_set_threshold (uint8_t color, int16_t red_ts, int16_t
- blue_ts, int16_t clear_ts, int16_t green_ts);
/** Analysis a color :
* - sensor : the sensor number to analysis ;
@@ -76,6 +59,11 @@ void sniff_rvb_set_threshold (uint8_t color, int16_t red_ts, int16_t
*/
uint8_t sniff_rvb_analysis_color (uint8_t sensor, uint8_t mode);
+/* Test "barillet" black/white
+ * - sensor : the sensor number to analysis ;
+*/
+uint8_t sniff_rvb_ball (uint8_t sensor);
+
/** Configure the sensor analysis system.
* - ref_ratio : ratio for the reference color.
*/