Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
535tobor authored Sep 25, 2023
1 parent f371b3f commit af2031a
Show file tree
Hide file tree
Showing 6 changed files with 365 additions and 0 deletions.
169 changes: 169 additions & 0 deletions teamcode/BlueBoardSide.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
package org.firstinspires.ftc.teamcode;

import static org.firstinspires.ftc.robotcore.external.BlocksOpModeCompanion.hardwareMap;
import static org.firstinspires.ftc.robotcore.external.BlocksOpModeCompanion.opMode;

import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorSimple;

import org.firstinspires.ftc.robotcore.external.hardware.camera.BuiltinCameraDirection;
import org.firstinspires.ftc.robotcore.external.hardware.camera.WebcamName;
import org.firstinspires.ftc.vision.VisionPortal;
import org.firstinspires.ftc.vision.apriltag.AprilTagDetection;
import org.firstinspires.ftc.vision.apriltag.AprilTagProcessor;

import java.util.List;

@Autonomous(name="Blue, Board Side")
public class BlueBoardSide extends LinearOpMode {

private static final boolean USE_WEBCAM = true; // true for webcam, false for phone camera
public double tag;

/**
* 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;

@Override
public void runOpMode() {
// init();
DcMotor frontLeftMotor = hardwareMap.dcMotor.get("fl");
DcMotor backLeftMotor = hardwareMap.dcMotor.get("bl");
DcMotor frontRightMotor = hardwareMap.dcMotor.get("fr");
DcMotor backRightMotor = hardwareMap.dcMotor.get("br");

frontRightMotor.setDirection(DcMotorSimple.Direction.REVERSE);
backRightMotor.setDirection(DcMotorSimple.Direction.REVERSE);
initAprilTag();

telemetry.update();

waitForStart();
// start();
if (isStopRequested()) return;
double speed = 0.5;

while (opModeIsActive()) {
// loop();
telemetry.update();
frontRightMotor.setPower(speed);
frontLeftMotor.setPower(speed);
backRightMotor.setPower(speed);
backLeftMotor.setPower(speed);


telemetryAprilTag();
if (gamepad1.a) {
frontRightMotor.setPower(speed);
frontLeftMotor.setPower(speed);
backRightMotor.setPower(speed);
backLeftMotor.setPower(speed);
}
else {
frontRightMotor.setPower(0);
frontLeftMotor.setPower(0);
backRightMotor.setPower(0);
backLeftMotor.setPower(0);
}

if (gamepad1.x) {
frontRightMotor.setPower(0);
frontLeftMotor.setPower(speed);
backRightMotor.setPower(0);
backLeftMotor.setPower(speed);
}
else {
frontRightMotor.setPower(0);
frontLeftMotor.setPower(0);
backRightMotor.setPower(0);
backLeftMotor.setPower(0);
}

if (gamepad1.b) {
frontRightMotor.setPower(0);
frontLeftMotor.setPower(speed);
backRightMotor.setPower(0);
backLeftMotor.setPower(speed);
}
else {
frontRightMotor.setPower(0);
frontLeftMotor.setPower(0);
backRightMotor.setPower(0);
backLeftMotor.setPower(0);
}

telemetry.addData("--> ", tag);
if (tag == 1){
telemetry.addData("--> ", "The First Tag!");
//requestOpModeStop();
}
else if (tag == 2){
telemetry.addData("--> ", "The Second Tag!");
requestOpModeStop();
}
else if (tag == 2){
telemetry.addData("--> ", "The Third Tag!");
requestOpModeStop();
}

}
visionPortal.close();
}

private void initAprilTag() {

// Create the AprilTag processor the easy way.
aprilTag = AprilTagProcessor.easyCreateWithDefaults();

// Create the vision portal the easy way.
if (USE_WEBCAM) {
visionPortal = VisionPortal.easyCreateWithDefaults(
hardwareMap.get(WebcamName.class, "Webcam 1"), aprilTag);
} else {
visionPortal = VisionPortal.easyCreateWithDefaults(
BuiltinCameraDirection.BACK, aprilTag);
}

} // end method initAprilTag()

/**
* Add telemetry about AprilTag detections.
*/
public void telemetryAprilTag() {

List<AprilTagDetection> currentDetections = aprilTag.getDetections();
telemetry.addData("# AprilTags Detected", currentDetections.size());

// Step through the list of detections and display info for each one.
for (AprilTagDetection detection : currentDetections) {
if (detection.metadata != null) {
telemetry.addLine(String.format("\n==== (ID %d) %s", detection.id, detection.metadata.name));
telemetry.addLine(String.format("XYZ %6.1f %6.1f %6.1f (inch)", detection.ftcPose.x, detection.ftcPose.y, detection.ftcPose.z));
telemetry.addLine(String.format("PRY %6.1f %6.1f %6.1f (deg)", detection.ftcPose.pitch, detection.ftcPose.roll, detection.ftcPose.yaw));
telemetry.addLine(String.format("RBE %6.1f %6.1f %6.1f (inch, deg, deg)", detection.ftcPose.range, detection.ftcPose.bearing, detection.ftcPose.elevation));
} else {
telemetry.addLine(String.format("\n==== (ID %d) Unknown", detection.id));
telemetry.addLine(String.format("Center %6.0f %6.0f (pixels)", detection.center.x, detection.center.y));
}

tag = detection.id;
String name = detection.metadata.name;
telemetry.addData("id: ", tag);
}

// Add "key" information to telemetry
telemetry.addLine("\nkey:\nXYZ = X (Right), Y (Forward), Z (Up) dist.");
telemetry.addLine("PRY = Pitch, Roll & Yaw (XYZ Rotation)");
telemetry.addLine("RBE = Range, Bearing & Elevation");

} // end method telemetryAprilTag()
}

31 changes: 31 additions & 0 deletions teamcode/BlueFarSide.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.firstinspires.ftc.teamcode;

import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import org.firstinspires.ftc.robotcore.external.hardware.camera.BuiltinCameraDirection;
import org.firstinspires.ftc.robotcore.external.hardware.camera.WebcamName;
import org.firstinspires.ftc.vision.VisionPortal;
import org.firstinspires.ftc.vision.apriltag.AprilTagDetection;
import org.firstinspires.ftc.vision.apriltag.AprilTagProcessor;

import java.util.List;

@Autonomous(name="Blue, Far Side")
public class BlueFarSide extends LCore {

@Override
public void runOpMode() {

waitForStart();
if (isStopRequested()) return;

// move robot across april tags, stop robot when it finds the correct one


while (opModeIsActive()) {

//telemetryAprilTag();
}
visionPortal.close();
}

}
17 changes: 17 additions & 0 deletions teamcode/FieldCentric.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.firstinspires.ftc.teamcode;

import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;

@TeleOp(name="Field Centric")
public class FieldCentric extends OpMode {
@Override
public void init(){

}

@Override
public void loop(){

}
}
86 changes: 86 additions & 0 deletions teamcode/LCore.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package org.firstinspires.ftc.teamcode;

import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.hardware.DcMotor;

import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorSimple;

import org.firstinspires.ftc.robotcore.external.hardware.camera.BuiltinCameraDirection;
import org.firstinspires.ftc.robotcore.external.hardware.camera.WebcamName;
import org.firstinspires.ftc.vision.VisionPortal;
import org.firstinspires.ftc.vision.apriltag.AprilTagDetection;
import org.firstinspires.ftc.vision.apriltag.AprilTagProcessor;

import java.util.List;

//@Autonomous(name="Test Core L")
public class LCore extends LinearOpMode {

private static final boolean USE_WEBCAM = true; // true for webcam, false for phone camera

private AprilTagProcessor aprilTag;
public double tag;
public String name;

public VisionPortal visionPortal;
@Override
public void runOpMode() {
}



public void initAprilTag() {

// Create the AprilTag processor the easy way.
aprilTag = AprilTagProcessor.easyCreateWithDefaults();

// Create the vision portal the easy way.
if (USE_WEBCAM) {
visionPortal = VisionPortal.easyCreateWithDefaults(
hardwareMap.get(WebcamName.class, "Webcam 1"), aprilTag);
} else {
visionPortal = VisionPortal.easyCreateWithDefaults(
BuiltinCameraDirection.BACK, aprilTag);
}

} // end method initAprilTag()

public void telemetryAprilTag() {

List<AprilTagDetection> currentDetections = aprilTag.getDetections();
//telemetry.addData("# AprilTags Detected", currentDetections.size());

// Step through the list of detections and display info for each one.
for (AprilTagDetection detection : currentDetections) {
if (detection.metadata != null) {
telemetry.addLine(String.format("\n==== (ID %d) %s", detection.id, detection.metadata.name));
telemetry.addLine(String.format("XYZ %6.1f %6.1f %6.1f (inch)", detection.ftcPose.x, detection.ftcPose.y, detection.ftcPose.z));
telemetry.addLine(String.format("PRY %6.1f %6.1f %6.1f (deg)", detection.ftcPose.pitch, detection.ftcPose.roll, detection.ftcPose.yaw));
telemetry.addLine(String.format("RBE %6.1f %6.1f %6.1f (inch, deg, deg)", detection.ftcPose.range, detection.ftcPose.bearing, detection.ftcPose.elevation));
}
else {
telemetry.addLine(String.format("\n==== (ID %d) Unknown", detection.id));
telemetry.addLine(String.format("Center %6.0f %6.0f (pixels)", detection.center.x, detection.center.y));
}

tag = detection.id;
name = detection.metadata.name;
telemetry.addData("id: ", tag);
if (tag == 2){
stop();
}
}




// Add "key" information to telemetry
telemetry.addLine("\nkey:\nXYZ = X (Right), Y (Forward), Z (Up) dist.");
telemetry.addLine("PRY = Pitch, Roll & Yaw (XYZ Rotation)");
telemetry.addLine("RBE = Range, Bearing & Elevation");

} // end method telemetryAprilTag()
}
31 changes: 31 additions & 0 deletions teamcode/RedBoardSide.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.firstinspires.ftc.teamcode;

import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import org.firstinspires.ftc.robotcore.external.hardware.camera.BuiltinCameraDirection;
import org.firstinspires.ftc.robotcore.external.hardware.camera.WebcamName;
import org.firstinspires.ftc.vision.VisionPortal;
import org.firstinspires.ftc.vision.apriltag.AprilTagDetection;
import org.firstinspires.ftc.vision.apriltag.AprilTagProcessor;

import java.util.List;

@Autonomous(name="Red, Board Side")
public class RedBoardSide extends LCore {

@Override
public void runOpMode() {

waitForStart();
if (isStopRequested()) return;

// move robot across april tags, stop robot when it finds the correct one


while (opModeIsActive()) {

//telemetryAprilTag();
}
visionPortal.close();
}

}
31 changes: 31 additions & 0 deletions teamcode/RedFarSide.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.firstinspires.ftc.teamcode;

import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import org.firstinspires.ftc.robotcore.external.hardware.camera.BuiltinCameraDirection;
import org.firstinspires.ftc.robotcore.external.hardware.camera.WebcamName;
import org.firstinspires.ftc.vision.VisionPortal;
import org.firstinspires.ftc.vision.apriltag.AprilTagDetection;
import org.firstinspires.ftc.vision.apriltag.AprilTagProcessor;

import java.util.List;

@Autonomous(name="Red, Far Side")
public class RedFarSide extends LCore {

@Override
public void runOpMode() {

waitForStart();
if (isStopRequested()) return;

// move robot across april tags, stop robot when it finds the correct one


while (opModeIsActive()) {

//telemetryAprilTag();
}
visionPortal.close();
}

}

0 comments on commit af2031a

Please sign in to comment.