From b23fa0b6c90ad62f336230cea9e8350862b6269f Mon Sep 17 00:00:00 2001 From: Maxime Hadjinlian Date: Fri, 10 May 2013 03:10:33 +0200 Subject: digital/io-hub/src/apbirthday: fix RGB recognition in cannon --- digital/io-hub/src/apbirthday/rgb.hh | 6 +----- digital/io-hub/src/apbirthday/rgb.stm32.cc | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 14 deletions(-) (limited to 'digital') diff --git a/digital/io-hub/src/apbirthday/rgb.hh b/digital/io-hub/src/apbirthday/rgb.hh index b935c632..f82506e4 100644 --- a/digital/io-hub/src/apbirthday/rgb.hh +++ b/digital/io-hub/src/apbirthday/rgb.hh @@ -26,10 +26,6 @@ #include "ucoolib/hal/gpio/gpio.hh" -/* This value was determined during tests using a BLUE filter */ -/* This will only be used for the cannon method */ -#define BASIC_GREY 190 - class Rgb { public: @@ -79,7 +75,7 @@ class Rgb ucoo::Gpio* g[RGB_TYPE_NB]; enum rgb_type type_; - uint32_t cannon_offset_; + uint32_t cannon_ref_grey_; bool router_; bool seen_color_, seen_white_; int measure_cnt_; diff --git a/digital/io-hub/src/apbirthday/rgb.stm32.cc b/digital/io-hub/src/apbirthday/rgb.stm32.cc index 50655745..3000c6d3 100644 --- a/digital/io-hub/src/apbirthday/rgb.stm32.cc +++ b/digital/io-hub/src/apbirthday/rgb.stm32.cc @@ -125,7 +125,7 @@ Rgb::calibrate_cannon_sensor () { // Do a measure to get current light situation do_measure (CANNON, false); - cannon_offset_ = BASIC_GREY - color_value_[BLUE]; + cannon_ref_grey_ = color_value_[BLUE]; } void @@ -244,25 +244,26 @@ Rgb::ic_isr () if (router_) { - uint16_t v = color_value_[BLUE] + cannon_offset_; - if (v > 120 && v < 165) + uint16_t v = (color_value_[BLUE] * 100) / cannon_ref_grey_; + + if (v > 0 && v < 30) + { + seen_white_ = true; + } + else if (v > 30 && v < 90) { // we don't know if it's blue or red, and we don't care // It's colored and must be thrown out ! seen_color_ = true; } - else if (v > 40 && v < 100) - { - seen_white_ = true; - } // Check if we are seeing GREY again - else if (v > 180 && v < 210) + else if (v > 90) { // If we have seen color if (seen_color_ && !seen_white_) { robot->hardware.cherry_bad_out.set (true); - router_timer_ = 4; + router_timer_ = 18; } seen_color_ = seen_white_ = false; } -- cgit v1.2.3