The Color Sensor part of your team's Autonomous OpMode might include these goals:
#. Seek a color, using the code from this Sample OpMode #. Take a robot action, based on finding that color
If so, select and read the Blocks or Java section below:
Blocks Beginners often try this first:
(Figure: Wrong way to act upon match result)
The problem is, after the robot does the action for RED, the OpMode is still inside the vision loop. Very messy and unpredictable.
A better approach is to save the result (as text!), exit the loop, then retrieve the stored result to take the desired RED action.
(Figure: Right way to act upon match result)
How to exit the vision loop? It could be based on time (https://github.com/FIRST-Tech-Challenge/FtcRobotController/wiki/Timers-in-FTC-Blocks) , or finding a particular color, or finding a particular color 10 times in a row, or finding only a particular color for 1 full second, or any other desired criteria.
Java The color result is generated inside a vision loop. Save the result (as text!), exit the loop, then retrieve the stored result to take the desired RED action.
String savedColorMatch = "NULL";
.
.
if (result.closestSwatch == Swatch.RED) {
savedColorMatch = "RED";
// your code here: optional to exit the vision loop based on your criteria
}
.
.
// After exiting the vision loop...
if (savedColorMatch == "RED") {
// your code here: robot actions if the ROI was RED
}
How to exit the vision loop? It could be based on time, or finding a particular color, or finding a particular color 10 times in a row, or finding only a particular color for 1 full second, or any other desired criteria.