forked from FIRST-Tech-Challenge/FtcRobotController
-
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.
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
TeamCode/src/main/java/org/firstinspires/ftc/teamcode/MecanumTeleOp.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,43 @@ | ||
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.hardware.DcMotorSimple; | ||
|
||
@TeleOp | ||
public class MecanumTeleOp extends LinearOpMode { | ||
@Override | ||
public void runOpMode() { | ||
DcMotor frontLeft = hardwareMap.dcMotor.get("frontLeft"); | ||
DcMotor backLeft = hardwareMap.dcMotor.get("backLeft"); | ||
DcMotor frontRight = hardwareMap.dcMotor.get("frontRight"); | ||
DcMotor backRight = hardwareMap.dcMotor.get("backRight"); | ||
|
||
frontLeft.setDirection(DcMotorSimple.Direction.REVERSE); | ||
backLeft.setDirection(DcMotorSimple.Direction.REVERSE); | ||
|
||
waitForStart(); | ||
if (isStopRequested()) return; | ||
|
||
while (opModeIsActive()) { | ||
double y = -gamepad1.left_stick_y; | ||
double x = gamepad1.left_stick_x * 1.1; | ||
double rx = gamepad1.right_stick_x; | ||
|
||
// Denominator is the largest motor power (absolute value) or 1 | ||
// This ensures all the powers maintain the same ratio, | ||
// but only if at least one is out of the range [-1, 1] | ||
double denominator = Math.max(Math.abs(y) + Math.abs(x) + Math.abs(rx), 1); | ||
double frontLeftPower = (y + x + rx) / denominator; | ||
double backLeftPower = (y - x + rx) / denominator; | ||
double frontRightPower = (y - x - rx) / denominator; | ||
double backRightPower = (y + x - rx) / denominator; | ||
|
||
frontLeft.setPower(frontLeftPower); | ||
backLeft.setPower(backLeftPower); | ||
frontRight.setPower(frontRightPower); | ||
backRight.setPower(backRightPower); | ||
} | ||
} | ||
} |