Detecting Color
Adding a Hue Variable
@TeleOp
public class HelloRobot_ColorSensor extends LinearOpMode {
private NormalizedColorSensor test_color;
double hue; // <------ New codewhile (opModeIsActive()) {
telemetry.addData("Light Detected", ((OpticalDistanceSensor) test_color).getLightDetected());
NormalizedRGBA colors = test_color.getNormalizedColors();
hue = JavaUtil.colorToHue(colors.toColor()); // <------ New code@TeleOp
public class HelloRobot_ColorSensor extends LinearOpMode {
private NormalizedColorSensor test_color;
double hue; // <------ New code
@Override
public void runOpMode() {
test_color = hardwareMap.get(NormalizedColorSensor.class, "test_color");
waitForStart();
while (opModeIsActive()) {
telemetry.addData("Light Detected", ((OpticalDistanceSensor) test_color).getLightDetected());
NormalizedRGBA colors = test_color.getNormalizedColors();
hue = JavaUtil.colorToHue(colors.toColor()); // <------ New code
//Determining the amount of red, green, and blue
telemetry.addData("Red", "%.3f", colors.red);
telemetry.addData("Green", "%.3f", colors.green);
telemetry.addData("Blue", "%.3f", colors.blue);
//Determining HSV and alpha
telemetry.addData("Hue", JavaUtil.colorToHue(colors.toColor()));
telemetry.addData("Saturation", "%.3f", JavaUtil.colorToSaturation(colors.toColor()));
telemetry.addData("Value", "%.3f", JavaUtil.colorToValue(colors.toColor()));
telemetry.addData("Alpha", "%.3f", colors.alpha);
telemetry.update();
}
}
}Detecting Common Colors
Full Color Sensor Program
Last updated
Was this helpful?

