summaryrefslogtreecommitdiff
path: root/n/es-2006/src/sniff_rvb.c
diff options
context:
space:
mode:
Diffstat (limited to 'n/es-2006/src/sniff_rvb.c')
-rw-r--r--n/es-2006/src/sniff_rvb.c147
1 files changed, 41 insertions, 106 deletions
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;
- }
-}