-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMecanumTeleOp.java
More file actions
67 lines (44 loc) · 2.27 KB
/
MecanumTeleOp.java
File metadata and controls
67 lines (44 loc) · 2.27 KB
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
package org.ftcinspires.ftc.teamcode;
import com.qualcomm.hardware.rev.RevHubOrientationOnRobot;
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;
import com.qualcomm.robotcore.hardware.IMU;
@TeleOp
public class MecanumTeleOp extends LinearOpMode {
@Override
public void runOpMode() throws InterruptedException {
//initialize motors
DcMotor frontLeft = hardwareMap.dcMotor.get("front_left_motor");
DcMotor backLeft = hardwareMap.dcMotor.get("back_left_motor");
DcMotor frontRight = hardwareMap.dcMotor.get("front_right_motor");
DcMotor backRight = hardwareMap.dcMotor.get("back_right_motor");
//set motor actions
frontLeft.setDirection(DcMotorSimple.Direction.REVERSE);
backLeft.setDirection(DcMotorSimple.Direction.REVERSE);
//initialize imu
IMU imu = hardwareMap.get(IMU.class, "imu" );
// set parameters
IMU.Parameters parameters = new IMU.Parameters(new RevHubOrientationOnRobot(RevHubOrientationOnRobot.LogoFacingDirection.UP, RevHubOrientationOnRobot.UsbFacingDirection.BACKWARD));
imu.initialize(parameters);
//initialize imu
waitForStart();
if (isStopRequested()) return;
while (opModeIsActive()) {
double y = gamepad1.left_stick_y;
double x = gamepad1.left_stick_x * 1.2;
double rx = gamepad1.right_stick_x;;
//yaw is the direction the heading is facing, this code with reset the new yaw, making the new yaw point 0
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);
}
}
}