Skip to content

Commit

Permalink
Merge branch 'master' into 4bar_code
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua-Smith-42 authored Sep 25, 2024
2 parents 0f03286 + 768716c commit c188cc8
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 0 deletions.
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));
}
}
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));
}


}
}
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)));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.firstinspires.ftc.teamcode.ftc16072.Mechanisms.MecanumDrive;
import org.firstinspires.ftc.teamcode.ftc16072.Mechanisms.OpticalTrackingOdometrySensor;
import org.firstinspires.ftc.teamcode.ftc16072.Mechanisms.QQMechanism;
import org.firstinspires.ftc.teamcode.ftc16072.Mechanisms.Slides;

import java.util.Arrays;
import java.util.List;
Expand All @@ -19,6 +20,7 @@ public class Robot {
public OpticalTrackingOdometrySensor otos;
public Claw claw;
public DoubleReverse4Bar doubleReverse4Bar;
public Slides slides;
List<QQMechanism> mechanisms;

public Robot() {
Expand All @@ -28,12 +30,17 @@ public Robot() {
claw = new Claw();
doubleReverse4Bar = new DoubleReverse4Bar();

slides = new Slides();

mechanisms = Arrays.asList(
controlHub,
mecanumDrive,
otos,
claw,

doubleReverse4Bar);
slides);

}
public void init(HardwareMap hwMap) {
for (QQMechanism mechanism : mechanisms) {
Expand Down

0 comments on commit c188cc8

Please sign in to comment.