This repository has been archived by the owner on Jan 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14f7484
commit 4450d5d
Showing
9 changed files
with
334 additions
and
45 deletions.
There are no files selected for viewing
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
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,27 @@ | ||
package org.firstinspires.ftc.teamcode; | ||
|
||
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; | ||
|
||
import org.firstinspires.ftc.teamcode.modules.DriveTrain; | ||
|
||
public class HybridAuto extends LinearOpMode { | ||
|
||
private DriveTrain driveTrain; | ||
protected static final boolean LEFT = false; | ||
protected static final boolean RIGHT = true; | ||
/** | ||
* Whether the robot is on the left or right side of the alliance station. | ||
*/ | ||
private final boolean sideOfField; | ||
|
||
public HybridAuto(boolean sideOfField) { | ||
this.sideOfField = sideOfField; | ||
} | ||
|
||
@Override | ||
public void runOpMode() { | ||
DriveTrain drivetrain = new DriveTrain(this); | ||
driveTrain.init(hardwareMap); | ||
|
||
} | ||
} |
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
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
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
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
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,148 @@ | ||
package org.firstinspires.ftc.teamcode.modules.Webcams; | ||
|
||
import android.util.Size; | ||
|
||
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; | ||
import com.qualcomm.robotcore.hardware.HardwareMap; | ||
|
||
import org.firstinspires.ftc.robotcore.external.hardware.camera.BuiltinCameraDirection; | ||
import org.firstinspires.ftc.robotcore.external.hardware.camera.WebcamName; | ||
import org.firstinspires.ftc.robotcore.external.navigation.AngleUnit; | ||
import org.firstinspires.ftc.robotcore.external.navigation.AxesOrder; | ||
import org.firstinspires.ftc.robotcore.external.navigation.AxesReference; | ||
import org.firstinspires.ftc.robotcore.external.navigation.DistanceUnit; | ||
import org.firstinspires.ftc.robotcore.external.navigation.Orientation; | ||
import org.firstinspires.ftc.teamcode.modules.Webcams.AprilTagDetectionPipeline; | ||
import org.firstinspires.ftc.vision.VisionPortal; | ||
import org.firstinspires.ftc.vision.apriltag.AprilTagDetection; | ||
import org.firstinspires.ftc.vision.apriltag.AprilTagGameDatabase; | ||
import org.firstinspires.ftc.vision.apriltag.AprilTagProcessor; | ||
import org.openftc.easyopencv.OpenCvCamera; | ||
import org.openftc.easyopencv.OpenCvCameraFactory; | ||
import org.openftc.easyopencv.OpenCvCameraRotation; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class AprilTagWebcam { | ||
|
||
OpenCvCamera camera; | ||
AprilTagDetectionPipeline aprilTagDetectionPipeline; | ||
|
||
static final double FEET_PER_METER = 3.28084; | ||
|
||
// Lens intrinsics | ||
// UNITS ARE PIXELS | ||
// NOTE: this calibration is for the C920 webcam at 800x448. | ||
// You will need to do your own calibration for other configurations! | ||
double fx = 578.272; | ||
double fy = 578.272; | ||
double cx = 402.145; | ||
double cy = 221.506; | ||
|
||
private static final boolean USE_WEBCAM = true; // true for webcam, false for phone camera | ||
|
||
/** | ||
* The variable to store our instance of the AprilTag processor. | ||
*/ | ||
private AprilTagProcessor aprilTag; | ||
|
||
/** | ||
* The variable to store our instance of the vision portal. | ||
*/ | ||
private VisionPortal visionPortal; | ||
|
||
/** | ||
* Initialize the AprilTag processor. | ||
*/ | ||
public void init(HardwareMap hardwareMap) { | ||
|
||
// Create the AprilTag processor. | ||
aprilTag = new AprilTagProcessor.Builder() | ||
.setDrawAxes(false) | ||
.setDrawCubeProjection(false) | ||
.setDrawTagOutline(true) | ||
.setTagFamily(AprilTagProcessor.TagFamily.TAG_36h11) | ||
.setTagLibrary(AprilTagGameDatabase.getCenterStageTagLibrary()) | ||
.setOutputUnits(DistanceUnit.INCH, AngleUnit.DEGREES) | ||
|
||
// == CAMERA CALIBRATION == | ||
// If you do not manually specify calibration parameters, the SDK will attempt | ||
// to load a predefined calibration for your camera. | ||
.setLensIntrinsics(fx, fy, cx, cy) | ||
// ... these parameters are fx, fy, cx, cy. | ||
|
||
.build(); | ||
|
||
// Adjust Image Decimation to trade-off detection-range for detection-rate. | ||
// eg: Some typical detection data using a Logitech C920 WebCam | ||
// Decimation = 1 .. Detect 2" Tag from 10 feet away at 10 Frames per second | ||
// Decimation = 2 .. Detect 2" Tag from 6 feet away at 22 Frames per second | ||
// Decimation = 3 .. Detect 2" Tag from 4 feet away at 30 Frames Per Second (default) | ||
// Decimation = 3 .. Detect 5" Tag from 10 feet away at 30 Frames Per Second (default) | ||
// Note: Decimation can be changed on-the-fly to adapt during a match. | ||
aprilTag.setDecimation(3); | ||
|
||
// Create the vision portal by using a builder. | ||
VisionPortal.Builder builder = new VisionPortal.Builder(); | ||
|
||
// Set the camera (webcam vs. built-in RC phone camera). | ||
if (USE_WEBCAM) { | ||
builder.setCamera(hardwareMap.get(WebcamName.class, "Webcam 1")); | ||
} else { | ||
builder.setCamera(BuiltinCameraDirection.BACK); | ||
} | ||
|
||
// Choose a camera resolution. Not all cameras support all resolutions. | ||
builder.setCameraResolution(new Size(640, 480)); | ||
|
||
// Enable the RC preview (LiveView). Set "false" to omit camera monitoring. | ||
builder.enableLiveView(true); | ||
|
||
// Set the stream format; MJPEG uses less bandwidth than default YUY2. | ||
builder.setStreamFormat(VisionPortal.StreamFormat.YUY2); | ||
|
||
// Choose whether or not LiveView stops if no processors are enabled. | ||
// If set "true", monitor shows solid orange screen if no processors enabled. | ||
// If set "false", monitor shows camera view without annotations. | ||
builder.setAutoStopLiveView(false); | ||
|
||
// Set and enable the processor. | ||
builder.addProcessor(aprilTag); | ||
|
||
// Build the Vision Portal, using the above settings. | ||
visionPortal = builder.build(); | ||
|
||
// Disable or re-enable the aprilTag processor at any time. | ||
visionPortal.setProcessorEnabled(aprilTag, true); | ||
|
||
} // end method initAprilTag() | ||
|
||
|
||
/** | ||
* Add telemetry about AprilTag detections. | ||
*/ | ||
public double[] detectIter() { | ||
|
||
List<org.firstinspires.ftc.vision.apriltag.AprilTagDetection> currentDetections = aprilTag.getDetections(); | ||
|
||
double avg_z = 0; | ||
double avg_y = 0; | ||
double avg_x = 0; | ||
// Step through the list of detections and display info for each one. | ||
for (AprilTagDetection detection : currentDetections) { | ||
if (detection.metadata != null) { | ||
avg_z += detection.metadata.fieldPosition.get(2) - detection.ftcPose.z; | ||
avg_y += detection.metadata.fieldPosition.get(1) - detection.ftcPose.y; | ||
avg_x += detection.metadata.fieldPosition.get(0) - detection.ftcPose.x; | ||
} | ||
} // end for() loop | ||
|
||
avg_z /= currentDetections.size(); | ||
avg_y /= currentDetections.size(); | ||
avg_x /= currentDetections.size(); | ||
|
||
return new double[]{avg_x, avg_y, avg_z}; | ||
|
||
} // end method telemetryAprilTag() | ||
} |
Oops, something went wrong.