FTC Color Sensor 20230424

From wikidb
Jump to: navigation, search

Why

  • Color imaging is used for object detection in machine learning applications.
  • Tensorflow is an example software framework that leverages camera sensing. We'll learn about it in another lab.
  • In this lab will learn about using simple color sensors as a first step.
  • We'll start by seeing how we can convert the RGB (Red Green Blue) color space from our sensors to HSV (Hue, Saturation and Value).
  • This will make it easier to compare color objects and understand how color works when we get to Tensorflow labs.

Color Sensor Demo Setup

Color Sensor Demo Code

Physical Connection

  • Connect Color Sensor to one of the I2C ports - 1 in my case

Configure Hardware

 colorSensor = hardwareMap.get(NormalizedColorSensor.class, "sensor_color");
  • Control Hub
    • I2C Bus 1
      • Port 0 MR IR Color Sensor V3
      • sensor_color

Example HW color senso configuration entry. Change ColorV3 to sensor_color for our examples.

ColorSensorConfiguration.png

From: https://docs.revrobotics.com/color-sensor/application-examples.

Exercise

  • Exercise 1: Load the TestColorSensorEpp Op Mode into Onbot Java and test it.
  • Note: There is a switch on the REV Color Sensor V3 that turns its light off.

RGB (Red Green Blue) and HSV (Hue Saturation Value) Color Models

RGB Camera Sensor

Color Calculator

HSV Color Wheel

  • Note: Divide the Hue angle number by two. They we implemented that way so color angle 0 to 360 could fit into one byte (0 to 255).

HSVColorWheel.png

  • broken link: FTC Forum: HSV color wheel copied from this site.



HSVColorCylinder.png

Why HSV

"... two shades of red colour might have similar Hue values, but widely different RGB values. In real life scenarios such as object racking based on colour, we need to make sure the our program rus well irrespective of environment changes ..."

Exercises

  • Exercise 2: Modify the TestColorSensorEpp.java to stop the robot when it reaches the blue tape or some other marker.
           // Code hint: Suppose you wanted to stop at a cobalt green line with a hue angle of 135. 
           // You could put something like the following in your while loop. Remember, we have to 
           // divide the hue by 2 so cobalt green is 68 in FTC Java.
           
           if (hue > 63 && hue < 73)
           {
              break;
           }

References

Normalized Colors - Next Steps

REV Sensor

We used the ColorSensor API above. This is a reasonable start for this simple demo. However, there appears to be some color mismatch with the REV sensor. We need investigate and determine which API best supports the REV Sensor V3 (REV-31-1557). One possibility is demonstrated with the Normalized color API demonstrated below.

Modern Robotics Sensor

not applicable to us

There is also the demo below which supports the Modern Robotics Color Sensor which we don't use.

TBD