Driving Until Color Sensor Sees Yellow (FTC)

Hello! I am from FTC team 11289, and we are having trouble programming our color sensor. We want our robot to drive until it either sees the yellow mineral, or goes 20 inches. We already have the color sensor working in another program that just shows the color readout over telemetry, and our movement works great too. We just don’t know how to use the loop that would work. “hsvValues” is the Hue of HSV. We got it by using the Color.RGBtoHSV function for the RGB output of the color sensor.

right.setPower(.5);
left.setPower(-.5);

while (hsvValues[0] < 30 || hsvValues[0] > 35 || right.getCurrentPosition() > 140 * 20){
    idle();
}

right.setPower(0);
left.setPower(0);

What are we doing wrong.

Possibly the logic in the while loop isn’t correct. Are you wanting it to loop until you reach a postition of “20 * 140” or until the hsvValues[0] is between 30 and 35? If so then I think you want it read like this:

This is how I would write it out before substituting in the program variables:

while ( “Not Yellow” and “Not 20 inches” ){
idle();
}

“Not Yellow” = (hsvValues[0] < 30 || hsvValues[0] > 35)
“Not 20 Inches” = right.getCurrentPosition() < 140 * 20

You end up with:

while ((hsvValues[0] < 30 || hsvValues[0] > 35) && right.getCurrentPosition() < 140 * 20){
idle();
}

Thank you! I would have missed that for a loooong time.