Difference between revisions of "FTC Color Sensor 20230424"

From wikidb
Jump to: navigation, search
(Exercises)
(Exercises)
Line 89: Line 89:
 
               break;
 
               break;
 
             }
 
             }
 
+
** '''Hint''': [[FTC Power Up a Motor 20221007]] Marry your code to the motor code we saw here
** '''Hint''': Marry your code to the motor code we saw in: [[FTC Power Up a Motor 20221007]]
+
 
** [https://github.com/edcepp/DeLaSalle/blob/main/TestMotorEpp.java TestMotorEpp.java] The motor power up code
 
** [https://github.com/edcepp/DeLaSalle/blob/main/TestMotorEpp.java TestMotorEpp.java] The motor power up code
  

Revision as of 19:47, 24 April 2023

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