From ea6b47fd42b1e7e3d8976674d9aab4638d550dc9 Mon Sep 17 00:00:00 2001 From: dufourj Date: Fri, 12 May 2006 01:01:53 +0000 Subject: ES (RVB) : - commande et fonction pour la défintion/récupération de la couleur de référence (le vert) ; - commande, fonction, structure pour définir des seuils pour l'algorithme de d'analyse de couleurs ; - fonction vide pour l'analyse de couleurs d'un capteur ; - fonction vide pour la mise à jour des pattes de l'AVR ; - remise à zéro des valeurs des capteurs qui sont considérés comme HS. --- n/es-2006/src/main.c | 11 ++++++ n/es-2006/src/sensor_rvb.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++ n/es-2006/src/sensor_rvb.h | 28 +++++++++++++-- 3 files changed, 122 insertions(+), 3 deletions(-) (limited to 'n') diff --git a/n/es-2006/src/main.c b/n/es-2006/src/main.c index b69c861..07a4a28 100644 --- a/n/es-2006/src/main.c +++ b/n/es-2006/src/main.c @@ -62,10 +62,21 @@ 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): + sensor_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; /* RVB sensors configuration */ case c ('R', 3): sensor_rvb_config (args[0], args[1], args[2]); break; + /* Set current color as reference */ + case c ('r', 0): + sensor_rvb_set_ref_color (); + break; /* color mode game */ case c ('c', 0 ): proto_send1b('c', others_selectcoul()); diff --git a/n/es-2006/src/sensor_rvb.c b/n/es-2006/src/sensor_rvb.c index e98d62f..a8ccf5a 100644 --- a/n/es-2006/src/sensor_rvb.c +++ b/n/es-2006/src/sensor_rvb.c @@ -27,6 +27,7 @@ #include "io.h" #include "modules/utils/utils.h" /* regv */ +#include "modules/proto/proto.h" /** * Somes defines. @@ -74,6 +75,10 @@ volatile uint8_t sensor_rvb_overflow_count_; volatile uint16_t sensor_rvb_values[RVB_MAX_SENSOR][4]; /** Count the number of IC before starting a good capture. */ uint8_t sensor_rvb_ic_count_; +/** Reference color. */ +uint16_t sensor_rvb_reference_color[4] = { 0 }; +/** Threshold table data. */ +uint16_t sensor_rvb_threshold_table[4][4] = { { 0 } }; /** Update everything for you. */ void sensor_rvb_update (void); @@ -138,6 +143,83 @@ sensor_rvb_sensor_select (uint8_t sensor_rvb_num) return 1; } +/** Try to reference the sensor_num sensor into the reference color. */ +inline uint8_t +sensor_rvb_try_reference (uint8_t sensor_num) +{ + uint8_t compt; + + /* If sensor is valid */ + if (sensor_rvb_values[sensor_num][0]) + { + /* For each color add this value by averrage */ + for (compt = 0; compt < 4; compt++) + { + sensor_rvb_reference_color[compt] = + (sensor_rvb_values[sensor_num][compt] + + sensor_rvb_reference_color[compt]) / 2; + } + return 1; + } + return 0; +} + + +/** Analysis a color */ +inline uint8_t +sensor_rvb_analysis_color (uint8_t sensor, uint8_t mode) +{ + return 0; +} + +/** Set the current color seen by some sensors as the reference color. */ +void +sensor_rvb_set_ref_color (void) +{ + /* The most significant sensor to uses are 7 & 8 for the moment */ + if (sensor_rvb_try_reference (7) || sensor_rvb_try_reference (8)) + // XXX Put this outside of this file ? + proto_send4w ('r', + sensor_rvb_reference_color[0], + sensor_rvb_reference_color[1], + sensor_rvb_reference_color[2], + sensor_rvb_reference_color[3]); +} + +/** Set the threshold of the differents colors. */ +void +sensor_rvb_set_threshold (uint8_t color, uint16_t red_ts, uint16_t blue_ts, + uint16_t clear_ts, uint16_t green_ts) +{ + switch (color) + { + case RVB_INDEX_RED: + case RVB_INDEX_BLUE: + case RVB_INDEX_CLEAR: + case RVB_INDEX_GREEN: + sensor_rvb_threshold_table[color][0] = red_ts; + sensor_rvb_threshold_table[color][1] = blue_ts; + sensor_rvb_threshold_table[color][2] = clear_ts; + sensor_rvb_threshold_table[color][3] = green_ts; + break; + } +} + +/** Update pins connected to the asserv AVR with the colors seen by the + * sensors. */ +void +sensor_rvb_update_asserv_pins (void) +{ + // TODO: + // - called the desired sensors with sensor_rvb_analysis_color ; + // - choose with Ni ; + // - do we need to update all the pins ? + // - this functions have to be hightly configurable : for example, choose + // if we can select frequency of update ; + // - manage a case for knowing the mode of the robot in order to select + // which pins we should update. +} + /** Initialisation of the RVB sensors module. */ void sensor_rvb_init (void) @@ -153,6 +235,8 @@ sensor_rvb_init (void) DDRD |= _BV(6); /* Put color selector pins in output */ DDRF |= _BV(S0RVB) | _BV(S1RVB); + /* Put asserv color states pins in output */ + DDRA |= _BV(7) | _BV(6) | _BV(5) | _BV(4); /* Nothing to do for the moment */ sensor_rvb_state_ = RVB_STATE_SLEEP; } @@ -246,6 +330,8 @@ SIGNAL (SIG_OVERFLOW1) // TODO : check this >= and the IC2 used if (++sensor_rvb_overflow_count_ >= sensor_rvb_conf_max_ov_) { + /* Invalidate the sensor */ + sensor_rvb_values[sensor_rvb_number_ - 1][0] = 0; /* Disable IC interrupt */ TIMSK &= ~_BV (TICIE1); /* Ask for next sensor */ diff --git a/n/es-2006/src/sensor_rvb.h b/n/es-2006/src/sensor_rvb.h index de9a498..ef53706 100644 --- a/n/es-2006/src/sensor_rvb.h +++ b/n/es-2006/src/sensor_rvb.h @@ -68,13 +68,35 @@ void sensor_rvb_init (void); void sensor_rvb_start_capture (void); /** Configure some internal variables. - * - false_ic = maximum input capture to ignore before begining the real + * - false_ic : maximum input capture to ignore before begining the real * capture. - * - max_ov = maximum overflow of the timer/counter 1 before setting the + * - max_ov : maximum overflow of the timer/counter 1 before setting the * sensor dead. uint8_t ! - * - latency = delay between change for sensor. Must be more than 100ns. This + * - latency : delay between change for sensor. Must be more than 100ns. This * setting is in ns. */ void sensor_rvb_config (uint8_t false_ic, uint8_t max_ov, uint8_t latency); +/** 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 sensor_rvb_set_ref_color (void); + +/** Set the threshold of the differents colors. + * There are used for the algorithm that distinguish colors. + */ +void sensor_rvb_set_threshold (uint8_t color, uint16_t red_ts, uint16_t + blue_ts, uint16_t clear_ts, uint16_t green_ts); + +/** Analysis a color : + * - sensor : the sensor number to analysis ; + * - mode : for futur use. + * return the color number. + */ +uint8_t sensor_rvb_analysis_color (uint8_t sensor, uint8_t mode); + +/** Update pins connected to the asserv AVR with the colors seen by the + * sensors. */ +void sensor_rvb_update_asserv_pins (void); + #endif // sensor_rvb_h -- cgit v1.2.3