TCS34725
The TCS34725 is a color sensor that outputs the detected color in RGB format. In Rescue Maze, it was used to identify blue and black tiles. The sensor was placed in the front of the robot to be able to make detections before more than half of the robot entered the tile.
Product link: https://www.adafruit.com/product/1334
Library used: https://github.com/adafruit/Adafruit_TCS34725
The sensor has multiple modes (see Adafruit_TCS34725.h lines 145-181). Each mode changes the time that the sensor takes to make a detection, the tradeoff being that the more time it takes, the more accurate the detection is. The mode used in the rescue maze was:
The main methods we used to interact with the Adafruit_TCS34725 object are:
When comparing the rgb output of both methods, getRawData displayed a greater difference between colors and was thus used.
Processing RGB input
The idea behind our implementation to relate a RGB output with a color was very simple:
- For each color, establish minimum and maximum expected values for each color channel.
static constexpr char colorList[colorAmount + 1] = {"NAG"}; // List of color initials
// Each row represents the upper and lower limits for detecting a color.
// colorThresholds[0] = {redMin, redmax, greenMin, greenMax, blueMin, blueMax}
static constexpr int colorThresholds[colorAmount][6] = {
{0, 40, 0, 40, 0, 40},
{60, 100, 120, 150, 125, 175},
{180, 240, 190, 210, 180, 210}};
-
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::getColorWithThresholds()
{
if (colorThresholds == nullptr)
return 'u';
updateRGBC(); // Update the RGB values
for (uint8_t i = 0; i < colorAmount; i++) {
if (inRangeThreshold(colorThresholds[i][0], red, colorThresholds[i][1]) && inRangeThreshold(colorThresholds[i][2], green, colorThresholds[i][3]) && inRangeThreshold(colorThresholds[i][4], blue, colorThresholds[i][5])){
return colorList[i];
}
}
return 'u'; // In case no color is detected.
}