-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMotorEncoders.java
More file actions
62 lines (47 loc) · 2.49 KB
/
MotorEncoders.java
File metadata and controls
62 lines (47 loc) · 2.49 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
/*
This example code was found on game manuel zero
at https://gm0.org/en/latest/docs/software/tutorials/mecanum-drive.html
*/
package org.firstinspires.ftc.teamcode.reference.gm0_examples;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.hardware.IMU;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorSimple;
import com.qualcomm.hardware.rev.RevHubOrientationOnRobot;
import org.firstinspires.ftc.robotcore.external.navigation.AngleUnit;
@Autonomous
public class MotorEncoders extends LinearOpMode {
@Override
public void runOpMode() throws InterruptedException {
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);
frontLeftMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
frontLeftMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
frontRightMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
frontRightMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
backLeftMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
backLeftMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
backRightMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
backRightMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
waitForStart();
// Encoders only work if they are plugged in! Make sure that your robot's encoders are plugged into your robot.
frontRightMotor.setTargetPosition(200);
frontRightMotor.setPower(1);
frontLeftMotor.setTargetPosition(200);
frontLeftMotor.setPower(1);
backRightMotor.setTargetPosition(200);
backRightMotor.setPower(1);
backLeftMotor.setTargetPosition(200);
backLeftMotor.setPower(1);
frontLeftMotor.setMode(DcMotor.RunMode.RUN_TO_POSITION);
frontRightMotor.setMode(DcMotor.RunMode.RUN_TO_POSITION);
backLeftMotor.setMode(DcMotor.RunMode.RUN_TO_POSITION);
backRightMotor.setMode(DcMotor.RunMode.RUN_TO_POSITION);
if (isStopRequested()) return;
}
}