TCS34725
The TCS34725 is a color light-to-digital converter that provides digital readings for red, green, blue (RGB), and clear light sensing values. In a specific application, it was utilized to detect black and blue tiles. The sensor was strategically positioned at the bottom front of the robot, allowing it to have a time buffer for timely responses.
The main methods used were:
Processing RGB input
The idea behind our implementation to relate a RGB output with a color was very simple:
- For each color, establish the expected values for each color channel.
// BLUE TILE
static constexpr float kRedValueInBlue_ = 211;
static constexpr float kGreenValueInBlue_ = 770;
static constexpr float kBlueValueInBlue_ = 1190;
// BLACK TILE
static constexpr float kRedValueInBlack_ = 70.00;
static constexpr float kGreenValueInBlack_ = 90.00;
static constexpr float kBlueValueInBlack_ = 90.00;
- Update the constants to match the displayed readings.
If readings look off, adjust integration time and gain in TCS.h(): - Undersaturated (values too small / differences barely distinguishable): increase integration time or gain. - Oversaturated (values maxed out / clipping): decrease integration time or gain.
Recalibrate whenever the arena lighting or sensor mounting height changes.
- Each expected value passes through a treshold that makes a range of values for color.
-
After each reading, check if the values are within the expected range for each color.
-
Return a value indicating a specific color if all three channels match the expected range.
char TCS::getColor() {
updateRGBC(); // Update the RGB values
char colorLetter = kUndefinedColor_;
if (red_ > kMinRedValueInBlue_ && green_ > kMinGreenValueInBlue_ &&
blue_ > kMinBlueValueInBlue_ && red_ < kMaxRedValueInBlue_ &&
green_ < kMaxGreenValueInBlue_ && blue_ < kMaxBlueValueInBlue_) {
colorLetter = kBlueColor_;
#if DEBUG_TCS
Serial.println("blue");
#endif
} else if (red_ > kMinRedValueInBlack_ && green_ > kMinGreenValueInBlack_ &&
blue_ > kMinBlueValueInBlack_ && red_ < kMaxRedValueInBlack_ &&
green_ < kMaxGreenValueInBlack_ && blue_ < kMaxBlueValueInBlack_) {
colorLetter = kBlackColor_;
#if DEBUG_TCS
Serial.println("black");
#endif
} else if (red_ > kMinRedValueInCheckpoint_ &&
green_ > kMinGreenValueInCheckpoint_ &&
blue_ > kMinBlueValueInCheckpoint_ &&
red_ < kMaxRedValueInCheckpoint_ &&
green_ < kMaxGreenValueInCheckpoint_ &&
blue_ < kMaxBlueValueInCheckpoint_) {
colorLetter = kCheckpointColor_;
#if DEBUG_TCS
Serial.println("checkpoint");
#endif
} else {
colorLetter = kUndefinedColor_;
#if DEBUG_TCS
Serial.println("unknown");
#endif
}
#if DEBUG_TCS
Serial.print("colorLetter: ");
Serial.println(colorLetter);
#endif
return colorLetter;
}