FTC A Hint of CanDo - TBD 20220422

From wikidb
Jump to: navigation, search

TBD: Add details

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

Working with HSV

CanDo Code

Version 3 Stop on Color and Reverse tests

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.

RGB HSV02 REVColorV3 02.png

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:

RGB HSV TableLookup02.png

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

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

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

CanDoPerformanceRun.png