FreeOfCharge2022-23/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/createdcode/enhancedautos/AutoBlueColorSensor.java

61 lines
1.7 KiB
Java
Raw Normal View History

2022-11-05 11:38:44 -05:00
package org.firstinspires.ftc.teamcode.createdcode.enhancedautos;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.hardware.ColorSensor;
@Autonomous
2022-11-05 18:59:22 -05:00
public class AutoBlueColorSensor extends LinearOpMode {
2022-11-05 11:38:44 -05:00
@Override
public void runOpMode() throws InterruptedException {
ColorSensor sensor = hardwareMap.get(ColorSensor.class, "color");
2022-11-05 19:14:00 -05:00
API api = new API(this);
2022-11-08 12:53:17 -06:00
MovementAPI movementAPI = new MovementAPI(api);
2022-11-05 11:38:44 -05:00
waitForStart();
2022-11-08 12:53:17 -06:00
movementAPI.move(0, 0.7);
2022-11-09 17:45:26 -06:00
api.pause(0.25);
2022-11-08 12:53:17 -06:00
movementAPI.stop();
2022-11-05 12:01:07 -05:00
2022-11-05 19:14:00 -05:00
api.pause(5);
2022-11-05 11:38:44 -05:00
int r = sensor.red();
int g = sensor.green();
int b = sensor.blue();
2022-11-09 17:45:26 -06:00
if (r < 100 && g < 100 && b < 100) {
movementAPI.move(-180, 0.7);
api.pause(0.25);
movementAPI.move(-180, 0.7);
api.pause(0.5);
movementAPI.move(90, 0.7);
api.pause(0.7);
movementAPI.stop();
terminateOpModeNow();
}
2022-11-05 19:14:00 -05:00
int largest = api.getLargest(r, g, b);
2022-11-05 11:38:44 -05:00
2022-11-09 17:45:26 -06:00
api.print("r", String.valueOf(r));
api.print("g", String.valueOf(g));
api.print("b", String.valueOf(b));
2022-11-07 16:29:03 -06:00
if (largest == g) {
2022-11-05 11:38:44 -05:00
// move to position 1
2022-11-08 12:53:17 -06:00
movementAPI.move(90, 0.7);
api.pause(0.25);
2022-11-07 16:29:03 -06:00
} else if (largest == r) {
2022-11-05 11:38:44 -05:00
// move to position 2
2022-11-08 12:53:17 -06:00
movementAPI.move(0, 0.7);
api.pause(0.25);
2022-11-05 11:38:44 -05:00
} else if (largest == b) {
// move to position 3
2022-11-08 12:53:17 -06:00
movementAPI.move(-90, 0.7);
api.pause(0.25);
2022-11-05 11:38:44 -05:00
}
2022-11-08 12:53:17 -06:00
movementAPI.stop();
2022-11-05 11:38:44 -05:00
}
}