From 190052e424b85534cb498e98a14265191409052e Mon Sep 17 00:00:00 2001 From: TCRF Date: Sat, 12 Sep 2026 18:48:40 -0400 Subject: [PATCH 1/2] asdsadsa --- .../ftc/teamcode/MechanumDrive.java | 44 +++++++++++++++++++ .../firstinspires/ftc/teamcode/TeleOp.java | 4 ++ 2 files changed, 48 insertions(+) create mode 100644 TeamCode/src/main/java/org/firstinspires/ftc/teamcode/MechanumDrive.java create mode 100644 TeamCode/src/main/java/org/firstinspires/ftc/teamcode/TeleOp.java diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/MechanumDrive.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/MechanumDrive.java new file mode 100644 index 000000000000..ea603801a9d7 --- /dev/null +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/MechanumDrive.java @@ -0,0 +1,44 @@ +package org.firstinspires.ftc.teamcode; + +import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; +import com.qualcomm.robotcore.eventloop.opmode.TeleOp; +import com.qualcomm.robotcore.hardware.DcMotor; +import com.qualcomm.robotcore.util.ElapsedTime; + +public class MechanumDrive{ + + + public MechanumDrive(double frontLeftPower, double frontRightPower, double backLeftPower, double backRightPower) { + } + + public static MechanumDrive calculatePowers(double gamepad1_left_stick_y, double gamepad1_left_stick_x, double gamepad1_right_stick_x) { + double max; + + // POV Mode uses left joystick to go forward & strafe, and right joystick to rotate. + double axial = -gamepad1_left_stick_y; // Note: pushing stick forward gives negative value + double lateral = gamepad1_left_stick_x; + double yaw = gamepad1_right_stick_x; + + // Set up a variable for each drive wheel to save the power level for telemetry. + double frontLeftPower = axial + lateral + yaw; + double frontRightPower = axial - lateral - yaw; + double backLeftPower = axial - lateral + yaw; + double backRightPower = axial + lateral - yaw; + + // Normalize the values so no wheel power exceeds 100% + // This ensures that the robot maintains the desired motion. + max = Math.max(Math.abs(frontLeftPower), Math.abs(frontRightPower)); + max = Math.max(max, Math.abs(backLeftPower)); + max = Math.max(max, Math.abs(backRightPower)); + + if (max > 1.0) { + frontLeftPower /= max; + frontRightPower /= max; + backLeftPower /= max; + backRightPower /= max; + } + + // Show the elapsed game time and wheel power. + return new MechanumDrive(frontLeftPower, frontRightPower, backLeftPower, backRightPower); + } +} \ No newline at end of file diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/TeleOp.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/TeleOp.java new file mode 100644 index 000000000000..a90ff7a8c85b --- /dev/null +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/TeleOp.java @@ -0,0 +1,4 @@ +package org.firstinspires.ftc.teamcode; + +public class TeleOp { +} From aaacf0908aba878acf1f3193e325da79f6f62486 Mon Sep 17 00:00:00 2001 From: shayden Date: Sun, 13 Sep 2026 16:05:38 -0400 Subject: [PATCH 2/2] Created TeleOp1, class cleaned up and modfied MechanumDrive code, and organized files --- .../ftc/teamcode/MechanumDrive.java | 44 --------------- .../firstinspires/ftc/teamcode/TeleOp.java | 4 -- .../ftc/teamcode/Teleops/TeleOp1.java | 27 ++++++++++ .../teamcode/mechanisms/MechanumDrive.java | 53 +++++++++++++++++++ 4 files changed, 80 insertions(+), 48 deletions(-) delete mode 100644 TeamCode/src/main/java/org/firstinspires/ftc/teamcode/MechanumDrive.java delete mode 100644 TeamCode/src/main/java/org/firstinspires/ftc/teamcode/TeleOp.java create mode 100644 TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Teleops/TeleOp1.java create mode 100644 TeamCode/src/main/java/org/firstinspires/ftc/teamcode/mechanisms/MechanumDrive.java diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/MechanumDrive.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/MechanumDrive.java deleted file mode 100644 index ea603801a9d7..000000000000 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/MechanumDrive.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.firstinspires.ftc.teamcode; - -import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; -import com.qualcomm.robotcore.eventloop.opmode.TeleOp; -import com.qualcomm.robotcore.hardware.DcMotor; -import com.qualcomm.robotcore.util.ElapsedTime; - -public class MechanumDrive{ - - - public MechanumDrive(double frontLeftPower, double frontRightPower, double backLeftPower, double backRightPower) { - } - - public static MechanumDrive calculatePowers(double gamepad1_left_stick_y, double gamepad1_left_stick_x, double gamepad1_right_stick_x) { - double max; - - // POV Mode uses left joystick to go forward & strafe, and right joystick to rotate. - double axial = -gamepad1_left_stick_y; // Note: pushing stick forward gives negative value - double lateral = gamepad1_left_stick_x; - double yaw = gamepad1_right_stick_x; - - // Set up a variable for each drive wheel to save the power level for telemetry. - double frontLeftPower = axial + lateral + yaw; - double frontRightPower = axial - lateral - yaw; - double backLeftPower = axial - lateral + yaw; - double backRightPower = axial + lateral - yaw; - - // Normalize the values so no wheel power exceeds 100% - // This ensures that the robot maintains the desired motion. - max = Math.max(Math.abs(frontLeftPower), Math.abs(frontRightPower)); - max = Math.max(max, Math.abs(backLeftPower)); - max = Math.max(max, Math.abs(backRightPower)); - - if (max > 1.0) { - frontLeftPower /= max; - frontRightPower /= max; - backLeftPower /= max; - backRightPower /= max; - } - - // Show the elapsed game time and wheel power. - return new MechanumDrive(frontLeftPower, frontRightPower, backLeftPower, backRightPower); - } -} \ No newline at end of file diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/TeleOp.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/TeleOp.java deleted file mode 100644 index a90ff7a8c85b..000000000000 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/TeleOp.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.firstinspires.ftc.teamcode; - -public class TeleOp { -} diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Teleops/TeleOp1.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Teleops/TeleOp1.java new file mode 100644 index 000000000000..ed6ccfffe174 --- /dev/null +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Teleops/TeleOp1.java @@ -0,0 +1,27 @@ +package org.firstinspires.ftc.teamcode.Teleops; + +import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; +import com.qualcomm.robotcore.eventloop.opmode.TeleOp; +import org.firstinspires.ftc.teamcode.mechanisms.MechanumDrive; + +@TeleOp(name="TeleOp1", group="Linear OpMode") +public class TeleOp1 extends LinearOpMode { + + MechanumDrive drivetrain = new MechanumDrive(); + + @Override + public void runOpMode() { + //Initializes the motors in our Method aka function + drivetrain.init(hardwareMap); + + waitForStart(); + + while (opModeIsActive()) { + + //runs our movement method with our gamepad parameters + drivetrain.drive(gamepad1.left_stick_y, gamepad1.left_stick_x, gamepad1.right_stick_x); + + + } + } +} \ No newline at end of file diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/mechanisms/MechanumDrive.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/mechanisms/MechanumDrive.java new file mode 100644 index 000000000000..2c696867a6f3 --- /dev/null +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/mechanisms/MechanumDrive.java @@ -0,0 +1,53 @@ +package org.firstinspires.ftc.teamcode.mechanisms; + +import com.qualcomm.robotcore.hardware.DcMotor; +import com.qualcomm.robotcore.hardware.HardwareMap; + +public class MechanumDrive { + + private DcMotor frontLeft; + private DcMotor frontRight; + private DcMotor backLeft; + private DcMotor backRight; + + public void init(HardwareMap hardwareMap) { + frontLeft = hardwareMap.get(DcMotor.class, "front_left_motor"); + frontRight = hardwareMap.get(DcMotor.class, "front_right_motor"); + backLeft = hardwareMap.get(DcMotor.class, "back_left_motor"); + backRight = hardwareMap.get(DcMotor.class, "back_right_motor"); + + + frontLeft.setDirection(DcMotor.Direction.REVERSE); + backLeft.setDirection(DcMotor.Direction.REVERSE); + } + + public void drive(double drive, double strafe, double turn) { + + //Driving sideways usually takes more power than driving forwards + strafe = strafe * 1.25; + + double SpeedMultiplier = 1; + + double flPower = (drive + strafe + turn) * SpeedMultiplier; + double frPower = (drive - strafe - turn) * SpeedMultiplier; + double blPower = (drive - strafe + turn) * SpeedMultiplier; + double brPower = (drive + strafe - turn) * SpeedMultiplier; + + // Normalize the values so no wheel power exceeds 100% + double max = Math.max(Math.abs(flPower), Math.abs(frPower)); + max = Math.max(max, Math.abs(blPower)); + max = Math.max(max, Math.abs(brPower)); + + if (max > 1.0) { + flPower /= max; + frPower /= max; + blPower /= max; + brPower /= max; + } + + frontLeft.setPower(flPower); + frontRight.setPower(frPower); + backLeft.setPower(blPower); + backRight.setPower(brPower); + } +}