Difference between revisions of "FTC A Hint of CanDo - TBD 20220422"
m (Edc moved page FTC A Hint of CanDo (TBD) 20220422 to FTC A Hint of CanDo - TBD 20220422) |
(→Version 6 Add Reverse and Turn) |
||
(47 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
= Why = | = Why = | ||
− | * | + | * Let’s have a little fun practice what we’ve learned by writing a CanDo program. We see who can knock a gold cube off our planing field. We may see who can do it the fastest. Later we will improve our program by recognizing where the gold cube is using Machine Learning with TensorFlow. |
− | = | + | = Color Sensor Lab References from March 11 = |
− | + | * [[FTC_Color_Sensor_20200311]] FTC Color Sensor Lab | |
+ | * [https://first-tech-challenge.github.io/SkyStone/index.html FTC API Reference] | ||
+ | * [https://docs.revrobotics.com/color-sensor/application-examples Color Sensor Examples] | ||
+ | * [https://docs.revrobotics.com/color-sensor/application-examples Color Sensor V3 - Overview] | ||
+ | * [https://codedocs.revrobotics.com/java/com/revrobotics/colorsensorv3 Class ColorSensorV3] | ||
+ | * [https://ftc-tricks.com/overview-color-sensor/ Overview of Color Sensors] from FTC Tricks | ||
− | * [https://github.com/edcepp/FTCJavaLabs/blob/main/CanDo03.java CanDo03.java] | + | = Working with HSV = |
+ | |||
+ | * [https://en.wikipedia.org/wiki/Hue Hue from Wikipedia] | ||
+ | * [https://stackoverflow.com/questions/28893613/convert-rgb-to-hsv-in-android Convert RGB to HSV in Android] | ||
+ | * [https://www.rapidtables.com/web/color/RGB_Color.html RGB/HSV Color Calculator with Rapid Tables] | ||
+ | |||
+ | = CanDo Code = | ||
+ | |||
+ | == Version 3 Stop on Color and Reverse tests == | ||
+ | |||
+ | * [https://github.com/edcepp/FTCJavaLabs/blob/main/CanDo03.java CanDo03.java] from the April 22 lab. | ||
+ | |||
+ | Beginning of a CanDo type of autonomous program. Tested the driveUntilColor and justDriveForATime methods. The field boundary is colored tape on a white background. | ||
+ | Discovered that Hue is not enough to determine color. | ||
+ | |||
+ | * [https://stackoverflow.com/questions/17931424/distinguish-red-color-from-white-is-hsv-or-similar-color-space Distinguishing Color in the HSV Color Space] | ||
+ | |||
+ | == Version 4 Add a displayColor Method == | ||
+ | |||
+ | === Color Values Captured by the Sensor === | ||
+ | |||
+ | * [https://github.com/edcepp/FTCJavaLabs/blob/main/CanDo04.java CanDo04.java] for the April 29 lab. See lines 137 through 164. | ||
+ | |||
+ | Add a displayColor method to display RGB components captured by the REV Color V3 sensor and their HSV converted values. The carts below show the results of test the | ||
+ | scanner of various pieces of construction paper. | ||
+ | My hope is to distinguish when the robot is traveling on a white background and crosses a boarder over a piece of color tape. | ||
+ | The following looks like a mess. | ||
+ | I was hoping for RGB values in the range of 0 to 255 with saturation and value values in 0 to 100 percent range. | ||
+ | I wonder if there is a calibration step I have missed. | ||
+ | |||
+ | Saturation for white and black should be close to 0. See next section. | ||
+ | For now, maybe we can check for a HSV value of less than 11 for non-white values and be careful with the color of boarder tape we use. | ||
+ | |||
+ | '''TBD''': Explore the REV V3 Color Sensor in more details. | ||
+ | |||
+ | [[File:RGB_HSV02_REVColorV3_02.png | 800px]] | ||
+ | |||
+ | === Using a Table to Compare RGB and HSV Color Values === | ||
+ | |||
+ | The tables below show the value values I expect from the color sensor. I used a | ||
+ | RGB / HSV color model conversion at: | ||
+ | |||
+ | * [https://www.rapidtables.com/web/color/RGB_Color.html RGB/HSV Color Calculator with Rapid Tables] | ||
+ | |||
+ | [[File:RGB_HSV_TableLookup02.png | 800px]] | ||
+ | |||
+ | === '''TBD''' Capture Using NormaizedColorSensor === | ||
+ | |||
+ | '''TBD''': Take measurements and create tables simialr to the ones in the previous section. | ||
+ | |||
+ | * [https://first-tech-challenge.github.io/SkyStone/index.html SkyStone Class API reference] | ||
+ | * [https://first-tech-challenge.github.io/SkyStone/com/qualcomm/robotcore/hardware/NormalizedColorSensor.html Normalized Color Sensor Interfacer] | ||
+ | |||
+ | == Version 5 Move Forward on White == | ||
+ | |||
+ | * [https://github.com/edcepp/FTCJavaLabs/blob/main/CanDo05.java CanDo05.java] for the April 29 lab. Set up to move forward on white and reverse for a some time. | ||
+ | |||
+ | |||
+ | Sets the move forward period until the HSV Value is less than 6.0. | ||
+ | |||
+ | '''TBD''': there needs to be a better test for white | ||
+ | |||
+ | = Exercise = | ||
+ | |||
+ | == Exercise 1 == | ||
+ | * We will see who can knock a gold cube off our playing field. | ||
+ | * After the robot backs up, it should do a random (or start with a fixed) turn and move forward again. | ||
+ | * Fine tune the reverse and turn values. | ||
+ | * Create a better non-white color test to trigger reverse. | ||
+ | |||
+ | == Exercise 2 == | ||
+ | * Determine who can do the CanDo the fastest | ||
+ | |||
+ | == Exercise 3 == | ||
+ | * Modify the program to use Machine Learn with TensorFlow to locate the gold mineral. Measure the time impact. | ||
+ | |||
+ | = CanDo Code - Spoiler Alert = | ||
+ | |||
+ | == Version 6 Add Reverse and Turn == | ||
+ | |||
+ | * [https://github.com/edcepp/FTCJavaLabs/blob/main/CanDo06.java CanDo06.java] for the May lab. | ||
+ | ** Move forward on white | ||
+ | ** Reverse for a some time | ||
+ | ** Turn - '''TBD''' - make the turn random | ||
+ | *** Explore: [https://droidbyme.medium.com/generate-random-number-in-android-2dd2def26ed Generate Random Number in Android] | ||
+ | |||
+ | = Performance = | ||
+ | |||
+ | It is clear from example runs that there is a time delay between crossing a color boundary and the robot response. | ||
+ | For example at 50% power the robot moved just beyond the boundary before stopping and reversing. | ||
+ | Here is a first attempt to analyze this result. | ||
+ | |||
+ | This is a naive performance analysis for the forward moving color detection portion of the CanDo program. | ||
+ | It may provide some insight but needs much for investication | ||
+ | |||
+ | == References == | ||
+ | |||
+ | * [https://stackoverflow.com/questions/26925727/how-to-test-function-for-execution-timing-in-android How to Test Function for Execution Timing in Android] | ||
+ | |||
+ | == Performance CanDo Do Code == | ||
+ | |||
+ | * [https://github.com/edcepp/FTCJavaLabs/blob/main/CanDoPerformance.java CanDoPerformance.java] Modifies the CanDo06 version to measure performance. | ||
+ | |||
+ | == Performance Annotations Example Code == | ||
+ | |||
+ | long time0 = System.nanoTime(); 0 | ||
+ | |||
+ | int rChannel = rgbValues.red(); | ||
+ | int gChannel = rgbValues.green(); | ||
+ | int bChannel = rgbValues.blue(); | ||
+ | |||
+ | long time1 = System.nanoTime(); add 17 milliseconds | ||
+ | |||
+ | float[] hsvValues = new float[3]; | ||
+ | Color.RGBToHSV(rChannel, gChannel, bChannel, hsvValues); | ||
+ | |||
+ | long time2 = System.nanoTime(); add 71 microseconds | ||
+ | |||
+ | double measuredHue = hsvValues[0]; | ||
+ | double measuredSaturation = hsvValues[1]; | ||
+ | double measuredValue = hsvValues[2]; | ||
+ | |||
+ | long time3 = System.nanoTime(); add 4.8 microseconds | ||
+ | |||
+ | leftMotor.setPower(percentPower); | ||
+ | rightMotor.setPower(percentPower); | ||
+ | |||
+ | long time4 = System.nanoTime(); add 3.4 milliseconds | ||
+ | |||
+ | leftMotor.setPower(0); | ||
+ | rightMotor.setPower(0); | ||
+ | |||
+ | long time5 = System.nanoTime(); add 3.3 milliseconds | ||
+ | |||
+ | telemetry.addData("Performance, ", String.format("time 0: %d ", time0)); | ||
+ | telemetry.addData("Performance, ", String.format("time 1: %d ", time1)); | ||
+ | telemetry.addData("Performance, ", String.format("time 2: %d ", time2)); | ||
+ | telemetry.addData("Performance, ", String.format("time 3: %d ", time3)); | ||
+ | telemetry.addData("Performance, ", String.format("time 4: %d ", time4)); | ||
+ | telemetry.addData("Performance, ", String.format("time 5: %d ", time5)); | ||
+ | telemetry.update(); | ||
+ | |||
+ | == Performance Run == | ||
+ | |||
+ | [[File:CanDoPerformanceRun.png | 1200px]] |
Latest revision as of 14:09, 3 June 2022
TBD: Add details
Contents
Why
- Let’s have a little fun practice what we’ve learned by writing a CanDo program. We see who can knock a gold cube off our planing field. We may see who can do it the fastest. Later we will improve our program by recognizing where the gold cube is using Machine Learning with TensorFlow.
Color Sensor Lab References from March 11
- FTC_Color_Sensor_20200311 FTC Color Sensor Lab
- FTC API Reference
- Color Sensor Examples
- Color Sensor V3 - Overview
- Class ColorSensorV3
- Overview of Color Sensors from FTC Tricks
Working with HSV
CanDo Code
Version 3 Stop on Color and Reverse tests
- CanDo03.java from the April 22 lab.
Beginning of a CanDo type of autonomous program. Tested the driveUntilColor and justDriveForATime methods. The field boundary is colored tape on a white background. Discovered that Hue is not enough to determine color.
Version 4 Add a displayColor Method
Color Values Captured by the Sensor
- CanDo04.java for the April 29 lab. See lines 137 through 164.
Add a displayColor method to display RGB components captured by the REV Color V3 sensor and their HSV converted values. The carts below show the results of test the scanner of various pieces of construction paper. My hope is to distinguish when the robot is traveling on a white background and crosses a boarder over a piece of color tape. The following looks like a mess. I was hoping for RGB values in the range of 0 to 255 with saturation and value values in 0 to 100 percent range. I wonder if there is a calibration step I have missed.
Saturation for white and black should be close to 0. See next section. For now, maybe we can check for a HSV value of less than 11 for non-white values and be careful with the color of boarder tape we use.
TBD: Explore the REV V3 Color Sensor in more details.
Using a Table to Compare RGB and HSV Color Values
The tables below show the value values I expect from the color sensor. I used a RGB / HSV color model conversion at:
TBD Capture Using NormaizedColorSensor
TBD: Take measurements and create tables simialr to the ones in the previous section.
Version 5 Move Forward on White
- CanDo05.java for the April 29 lab. Set up to move forward on white and reverse for a some time.
Sets the move forward period until the HSV Value is less than 6.0.
TBD: there needs to be a better test for white
Exercise
Exercise 1
- We will see who can knock a gold cube off our playing field.
- After the robot backs up, it should do a random (or start with a fixed) turn and move forward again.
- Fine tune the reverse and turn values.
- Create a better non-white color test to trigger reverse.
Exercise 2
- Determine who can do the CanDo the fastest
Exercise 3
- Modify the program to use Machine Learn with TensorFlow to locate the gold mineral. Measure the time impact.
CanDo Code - Spoiler Alert
Version 6 Add Reverse and Turn
- CanDo06.java for the May lab.
- Move forward on white
- Reverse for a some time
- Turn - TBD - make the turn random
- Explore: Generate Random Number in Android
Performance
It is clear from example runs that there is a time delay between crossing a color boundary and the robot response. For example at 50% power the robot moved just beyond the boundary before stopping and reversing. Here is a first attempt to analyze this result.
This is a naive performance analysis for the forward moving color detection portion of the CanDo program. It may provide some insight but needs much for investication
References
Performance CanDo Do Code
- CanDoPerformance.java Modifies the CanDo06 version to measure performance.
Performance Annotations Example Code
long time0 = System.nanoTime(); 0 int rChannel = rgbValues.red(); int gChannel = rgbValues.green(); int bChannel = rgbValues.blue(); long time1 = System.nanoTime(); add 17 milliseconds float[] hsvValues = new float[3]; Color.RGBToHSV(rChannel, gChannel, bChannel, hsvValues); long time2 = System.nanoTime(); add 71 microseconds double measuredHue = hsvValues[0]; double measuredSaturation = hsvValues[1]; double measuredValue = hsvValues[2]; long time3 = System.nanoTime(); add 4.8 microseconds leftMotor.setPower(percentPower); rightMotor.setPower(percentPower); long time4 = System.nanoTime(); add 3.4 milliseconds leftMotor.setPower(0); rightMotor.setPower(0); long time5 = System.nanoTime(); add 3.3 milliseconds telemetry.addData("Performance, ", String.format("time 0: %d ", time0)); telemetry.addData("Performance, ", String.format("time 1: %d ", time1)); telemetry.addData("Performance, ", String.format("time 2: %d ", time2)); telemetry.addData("Performance, ", String.format("time 3: %d ", time3)); telemetry.addData("Performance, ", String.format("time 4: %d ", time4)); telemetry.addData("Performance, ", String.format("time 5: %d ", time5)); telemetry.update();