color test
This commit is contained in:
@@ -23,12 +23,12 @@ public class ColorSensorTest extends LinearOpMode{
|
|||||||
if (isStopRequested()) return;
|
if (isStopRequested()) return;
|
||||||
|
|
||||||
while (opModeIsActive()){
|
while (opModeIsActive()){
|
||||||
TELE.addData("Green1:", robot.pin0.getState());
|
TELE.addData("Green1:", robot.pin1.getState());
|
||||||
TELE.addData("Purple1:", robot.pin1.getState());
|
TELE.addData("Purple1:", robot.pin0.getState());
|
||||||
TELE.addData("Green2:", robot.pin2.getState());
|
TELE.addData("Green2:", robot.pin3.getState());
|
||||||
TELE.addData("Purple2:", robot.pin3.getState());
|
TELE.addData("Purple2:", robot.pin2.getState());
|
||||||
TELE.addData("Green3:", robot.pin4.getState());
|
TELE.addData("Green3:", robot.pin5.getState());
|
||||||
TELE.addData("Purple3:", robot.pin5.getState());
|
TELE.addData("Purple3:", robot.pin4.getState());
|
||||||
|
|
||||||
TELE.update();
|
TELE.update();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,41 @@
|
|||||||
package org.firstinspires.ftc.teamcode.utils;
|
package org.firstinspires.ftc.teamcode.utils;
|
||||||
|
|
||||||
|
import com.acmerobotics.dashboard.config.Config;
|
||||||
|
import com.bylazar.configurables.annotations.Configurable;
|
||||||
import com.qualcomm.hardware.rev.RevColorSensorV3;
|
import com.qualcomm.hardware.rev.RevColorSensorV3;
|
||||||
|
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
|
||||||
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
|
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
|
||||||
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
|
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
|
||||||
import com.qualcomm.robotcore.hardware.I2cDeviceSynchSimple;
|
import com.qualcomm.robotcore.hardware.I2cDeviceSynchSimple;
|
||||||
|
|
||||||
|
@Config
|
||||||
|
@Autonomous
|
||||||
|
|
||||||
|
|
||||||
@TeleOp
|
|
||||||
public class ConfigureColorRangefinder extends LinearOpMode {
|
public class ConfigureColorRangefinder extends LinearOpMode {
|
||||||
@Override
|
@Override
|
||||||
public void runOpMode() throws InterruptedException {
|
public void runOpMode() throws InterruptedException {
|
||||||
ColorRangefinder crf = new ColorRangefinder(hardwareMap.get(RevColorSensorV3.class, "color"));
|
ColorRangefinder crf = new ColorRangefinder(hardwareMap.get(RevColorSensorV3.class, "color"));
|
||||||
waitForStart();
|
/*
|
||||||
/* Using this example configuration, you can detect both artifact colors based on which pin is reading true:
|
Using this example configuration, you can detect all three sample colors based on which pin is reading true:
|
||||||
pin0 --> purple
|
both --> yellow
|
||||||
pin1 --> green */
|
only pin0 --> blue
|
||||||
crf.setPin0Digital(ColorRangefinder.DigitalMode.HSV, 0 / 360.0 * 255, 360 / 360.0 * 255); // purple
|
only pin1 --> red
|
||||||
crf.setPin0DigitalMaxDistance(ColorRangefinder.DigitalMode.HSV, 40); // 10mm or closer requirement
|
neither --> no object
|
||||||
crf.setPin1Digital(ColorRangefinder.DigitalMode.HSV, 110 / 360.0 * 255, 140 / 360.0 * 255); // green
|
*/
|
||||||
crf.setLedBrightness(2);
|
crf.setPin1Digital(ColorRangefinder.DigitalMode.HSV, 80 / 360.0 * 255, 140 / 360.0 * 255); // green
|
||||||
|
crf.setPin1Saturation(175, 255);
|
||||||
|
crf.setPin1Value(100,200);
|
||||||
|
crf.setPin1DigitalMaxDistance(ColorRangefinder.DigitalMode.HSV, 40); // 20mm or closer requirement
|
||||||
|
|
||||||
|
|
||||||
|
crf.setPin0Digital(ColorRangefinder.DigitalMode.DISTANCE, 0, 40); // purple
|
||||||
|
|
||||||
|
crf.setLedBrightness(0);
|
||||||
|
|
||||||
|
waitForStart();
|
||||||
|
|
||||||
|
stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,9 +44,12 @@ public class ConfigureColorRangefinder extends LinearOpMode {
|
|||||||
* Online documentation: <a href="https://docs.brushlandlabs.com">...</a>
|
* Online documentation: <a href="https://docs.brushlandlabs.com">...</a>
|
||||||
*/
|
*/
|
||||||
class ColorRangefinder {
|
class ColorRangefinder {
|
||||||
|
public static int LED_VALUE = 15;
|
||||||
|
public final RevColorSensorV3 emulator;
|
||||||
private final I2cDeviceSynchSimple i2c;
|
private final I2cDeviceSynchSimple i2c;
|
||||||
|
|
||||||
public ColorRangefinder(RevColorSensorV3 emulator) {
|
public ColorRangefinder(RevColorSensorV3 emulator) {
|
||||||
|
this.emulator = emulator;
|
||||||
this.i2c = emulator.getDeviceClient();
|
this.i2c = emulator.getDeviceClient();
|
||||||
this.i2c.enableWriteCoalescing(true);
|
this.i2c.enableWriteCoalescing(true);
|
||||||
}
|
}
|
||||||
@@ -53,6 +72,22 @@ class ColorRangefinder {
|
|||||||
setDigital(PinNum.PIN1, digitalMode, lowerBound, higherBound);
|
setDigital(PinNum.PIN1, digitalMode, lowerBound, higherBound);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPin0Saturation(double lowerBound, double higherBound) {
|
||||||
|
setDigital(PinNum.PIN0, DigitalMode.SATURATION, lowerBound, higherBound);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPin1Saturation(double lowerBound, double higherBound) {
|
||||||
|
setDigital(PinNum.PIN1, DigitalMode.SATURATION, lowerBound, higherBound);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Optional: Easy methods for value/brightness thresholding
|
||||||
|
public void setPin0Value(double lowerBound, double higherBound) {
|
||||||
|
setDigital(PinNum.PIN0, DigitalMode.VALUE, lowerBound, higherBound);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPin1Value(double lowerBound, double higherBound) {
|
||||||
|
setDigital(PinNum.PIN1, DigitalMode.VALUE, lowerBound, higherBound);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Sets the maximum distance (in millimeters) within which an object must be located for Pin 0's thresholds to trigger.
|
* Sets the maximum distance (in millimeters) within which an object must be located for Pin 0's thresholds to trigger.
|
||||||
* This is most useful when we want to know if an object is both close and the correct color.
|
* This is most useful when we want to know if an object is both close and the correct color.
|
||||||
@@ -74,18 +109,13 @@ class ColorRangefinder {
|
|||||||
* This is useful if we want to threshold red; instead of having two thresholds we would invert
|
* This is useful if we want to threshold red; instead of having two thresholds we would invert
|
||||||
* the color and look for blue.
|
* the color and look for blue.
|
||||||
*/
|
*/
|
||||||
public void setPin0InvertHue() {
|
|
||||||
setPin0DigitalMaxDistance(DigitalMode.HSV, 200);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invert the hue value before thresholding it, meaning that the colors become their opposite.
|
* Invert the hue value before thresholding it, meaning that the colors become their opposite.
|
||||||
* This is useful if we want to threshold red; instead of having two thresholds we would invert
|
* This is useful if we want to threshold red; instead of having two thresholds we would invert
|
||||||
* the color and look for blue.
|
* the color and look for blue.
|
||||||
*/
|
*/
|
||||||
public void setPin1InvertHue() {
|
|
||||||
setPin1DigitalMaxDistance(DigitalMode.HSV, 200);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The denominator is what the raw sensor readings will be divided by before being scaled to 12-bit analog.
|
* The denominator is what the raw sensor readings will be divided by before being scaled to 12-bit analog.
|
||||||
@@ -152,7 +182,7 @@ class ColorRangefinder {
|
|||||||
if (lowerBound == higherBound) {
|
if (lowerBound == higherBound) {
|
||||||
lo = (int) lowerBound;
|
lo = (int) lowerBound;
|
||||||
hi = (int) higherBound;
|
hi = (int) higherBound;
|
||||||
} else if (digitalMode.value <= DigitalMode.HSV.value) { // color value 0-255
|
} else if (digitalMode.value <= DigitalMode.VALUE.value) { // HSV/HUE/SATURATION/VALUE color range
|
||||||
lo = (int) Math.round(lowerBound / 255.0 * 65535);
|
lo = (int) Math.round(lowerBound / 255.0 * 65535);
|
||||||
hi = (int) Math.round(higherBound / 255.0 * 65535);
|
hi = (int) Math.round(higherBound / 255.0 * 65535);
|
||||||
} else { // distance in mm
|
} else { // distance in mm
|
||||||
@@ -205,7 +235,7 @@ class ColorRangefinder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public enum DigitalMode {
|
public enum DigitalMode {
|
||||||
RED(1), BLUE(2), GREEN(3), ALPHA(4), HSV(5), DISTANCE(6);
|
RED(1), BLUE(2), GREEN(3), ALPHA(4), HSV(5), DISTANCE(6), SATURATION(7), VALUE(8);
|
||||||
public final byte value;
|
public final byte value;
|
||||||
|
|
||||||
DigitalMode(int value) {
|
DigitalMode(int value) {
|
||||||
@@ -222,3 +252,4 @@ class ColorRangefinder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user