This repository has been archived by the owner on Nov 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMecanumDriveIII.java
80 lines (70 loc) · 3.02 KB
/
MecanumDriveIII.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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(name="Mecanum Drive III")
public class MecanumDriveIII extends LinearOpMode {
@Override
public void runOpMode() throws InterruptedException {
// Declare our motors
// Make sure your ID's match your configuration
DcMotor motorFrontLeft = hardwareMap.dcMotor.get("front_left");
DcMotor motorBackLeft = hardwareMap.dcMotor.get("back_left");
DcMotor motorFrontRight = hardwareMap.dcMotor.get("front_right");
DcMotor motorBackRight = hardwareMap.dcMotor.get("back_right");
// Reverse the right side motors
// Reverse left motors if you are using NeveRests
motorFrontLeft.setDirection(DcMotor.Direction.REVERSE);
motorBackLeft.setDirection(DcMotor.Direction.REVERSE);
// Set motors to brake when not in use
motorFrontLeft.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
motorFrontRight.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
motorBackLeft.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
motorBackRight.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
waitForStart();
if (isStopRequested()) return;
while (opModeIsActive()) {
double rx = -gamepad1.left_stick_y; // Remember, this is reversed!
double x = gamepad1.left_stick_x * 1.1; // Counteract imperfect strafing
double y = gamepad1.right_stick_x;
double frontLeftPower = y + x + rx;
double backLeftPower = y - x + rx;
double frontRightPower = y - x - rx;
double backRightPower = y + x - rx;
// Put powers in the range of -1 to 1 only if they aren't already
// Not checking would cause us to always drive at full speed
if (Math.abs(frontLeftPower) > 1 || Math.abs(backLeftPower) > 1 ||
Math.abs(frontRightPower) > 1 || Math.abs(backRightPower) > 1) {
// Find the largest power
double max = 0;
max = Math.max(Math.abs(frontLeftPower), Math.abs(backLeftPower));
max = Math.max(Math.abs(frontRightPower), max);
max = Math.max(Math.abs(backRightPower), max);
// Divide everything by max (it's positive so we don't need to worry
// about signs)
frontLeftPower /= max;
backLeftPower /= max;
frontRightPower /= max;
backRightPower /= max;
}
if(gamepad1.right_bumper){
motorFrontLeft.setPower(frontLeftPower * 0.25);
motorBackLeft.setPower(backLeftPower * 0.25);
motorFrontRight.setPower(frontRightPower * 0.25);
motorBackRight.setPower(backRightPower * 0.25);
}
else if(gamepad1.left_bumper){
motorFrontLeft.setPower(frontLeftPower * 0.75);
motorBackLeft.setPower(backLeftPower * 0.75);
motorFrontRight.setPower(frontRightPower * 0.75);
motorBackRight.setPower(backRightPower * 0.75);
}else{
motorFrontLeft.setPower(frontLeftPower);
motorBackLeft.setPower(backLeftPower);
motorFrontRight.setPower(frontRightPower);
motorBackRight.setPower(backRightPower);
}
}
}
}