-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into 4bar_code
- Loading branch information
Showing
4 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
TeamCode/src/main/java/org/firstinspires/ftc/teamcode/ftc16072/Mechanisms/Slides.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.firstinspires.ftc.teamcode.ftc16072.Mechanisms; | ||
|
||
import com.acmerobotics.dashboard.config.Config; | ||
import com.qualcomm.robotcore.hardware.HardwareMap; | ||
import com.qualcomm.robotcore.hardware.Servo; | ||
|
||
import org.firstinspires.ftc.teamcode.ftc16072.Tests.QQTest; | ||
import org.firstinspires.ftc.teamcode.ftc16072.Tests.TestServo; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
@Config | ||
public class Slides extends QQMechanism { | ||
public static double SLIDE_BACK_POSITION = 0.125; | ||
public static double SLIDE_FRONT_POSITION = 1.0; | ||
public static double SLIDE_MIDDLE_POSITION = 0.5; | ||
|
||
Servo slideServo; | ||
|
||
@Override | ||
public void init(HardwareMap hwMap) { | ||
slideServo = hwMap.get(Servo.class, "slide_movement"); | ||
} | ||
|
||
public void goToPos(double position){ | ||
slideServo.setPosition(position); | ||
} | ||
|
||
@Override | ||
public List<QQTest> getTests() { | ||
return Arrays.asList( | ||
new TestServo("slide_back", SLIDE_BACK_POSITION, SLIDE_MIDDLE_POSITION, slideServo), | ||
new TestServo("slide_front", SLIDE_FRONT_POSITION, SLIDE_MIDDLE_POSITION, slideServo)); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
TeamCode/src/main/java/org/firstinspires/ftc/teamcode/ftc16072/OpModes/ColorLocator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.firstinspires.ftc.teamcode.ftc16072.OpModes; | ||
|
||
import android.util.Size; | ||
|
||
import com.qualcomm.robotcore.eventloop.opmode.Autonomous; | ||
import com.qualcomm.robotcore.eventloop.opmode.OpMode; | ||
|
||
import org.firstinspires.ftc.robotcore.external.hardware.camera.WebcamName; | ||
import org.firstinspires.ftc.vision.VisionPortal; | ||
import org.firstinspires.ftc.vision.opencv.ColorBlobLocatorProcessor; | ||
import org.firstinspires.ftc.vision.opencv.ColorRange; | ||
import org.firstinspires.ftc.vision.opencv.ImageRegion; | ||
import org.opencv.core.RotatedRect; | ||
|
||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
@Autonomous | ||
@SuppressWarnings("unused") | ||
public class ColorLocator extends OpMode { | ||
ColorBlobLocatorProcessor colorLocator; | ||
public void init(){ | ||
colorLocator = new ColorBlobLocatorProcessor.Builder() | ||
.setTargetColorRange(ColorRange.BLUE) // use a predefined color match | ||
.setContourMode(ColorBlobLocatorProcessor.ContourMode.EXTERNAL_ONLY) // exclude blobs inside blobs | ||
.setRoi(ImageRegion.asUnityCenterCoordinates(-0.5, 0.5, 0.5, -0.5)) // search central 1/4 of camera view | ||
.setDrawContours(true) // Show contours on the Stream Preview | ||
.setBlurSize(5) // Smooth the transitions between different colors in image | ||
.build(); | ||
@SuppressWarnings("unused") | ||
VisionPortal portal = new VisionPortal.Builder() | ||
.addProcessor(colorLocator) | ||
.setCameraResolution(new Size(320, 240)) | ||
.setCamera(hardwareMap.get(WebcamName.class, "Webcam 1")) | ||
.build(); | ||
} | ||
|
||
public void loop (){ | ||
List<ColorBlobLocatorProcessor.Blob> blobs = colorLocator.getBlobs(); | ||
ColorBlobLocatorProcessor.Util.filterByArea(50, 2000, blobs); // filter out very small blobs. | ||
telemetry.addLine(" Area Density Aspect Center"); | ||
for(ColorBlobLocatorProcessor.Blob b : blobs) | ||
{ | ||
RotatedRect boxFit = b.getBoxFit(); | ||
telemetry.addLine(String.format(Locale.US, "%5d %4.2f %5.2f (%3d,%3d)", | ||
b.getContourArea(), b.getDensity(), b.getAspectRatio(), (int) boxFit.center.x, (int) boxFit.center.y)); | ||
} | ||
|
||
|
||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
TeamCode/src/main/java/org/firstinspires/ftc/teamcode/ftc16072/OpModes/ColorSensor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.firstinspires.ftc.teamcode.ftc16072.OpModes; | ||
|
||
import android.graphics.Color; | ||
import android.util.Size; | ||
|
||
import com.qualcomm.robotcore.eventloop.opmode.Autonomous; | ||
import com.qualcomm.robotcore.eventloop.opmode.OpMode; | ||
|
||
import org.firstinspires.ftc.robotcore.external.hardware.camera.WebcamName; | ||
import org.firstinspires.ftc.vision.VisionPortal; | ||
import org.firstinspires.ftc.vision.opencv.ImageRegion; | ||
import org.firstinspires.ftc.vision.opencv.PredominantColorProcessor; | ||
|
||
import java.util.Locale; | ||
|
||
@Autonomous | ||
@SuppressWarnings("unused") | ||
public class ColorSensor extends OpMode { | ||
PredominantColorProcessor colorSensor; | ||
public void init(){ | ||
colorSensor = new PredominantColorProcessor.Builder() | ||
.setRoi(ImageRegion.asUnityCenterCoordinates(0.5, 0.6, 0.6, 0.5)) | ||
.setSwatches( | ||
PredominantColorProcessor.Swatch.RED, | ||
PredominantColorProcessor.Swatch.BLUE, | ||
PredominantColorProcessor.Swatch.YELLOW, | ||
PredominantColorProcessor.Swatch.BLACK, | ||
PredominantColorProcessor.Swatch.WHITE) | ||
.build(); | ||
|
||
@SuppressWarnings("unused") | ||
VisionPortal portal = new VisionPortal.Builder() | ||
.addProcessor(colorSensor) | ||
.setCameraResolution(new Size(320, 240)) | ||
.setCamera(hardwareMap.get(WebcamName.class, "Webcam 1")) | ||
.build(); | ||
|
||
} | ||
|
||
@Override | ||
public void loop(){ | ||
PredominantColorProcessor.Result result = colorSensor.getAnalysis(); | ||
|
||
// Display the Color Sensor result. | ||
telemetry.addData("Best Match:", result.closestSwatch); | ||
telemetry.addLine(String.format(Locale.US,"R %3d, G %3d, B %3d", Color.red(result.rgb), Color.green(result.rgb), Color.blue(result.rgb))); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters