-
Notifications
You must be signed in to change notification settings - Fork 1
/
Auto.java
89 lines (72 loc) · 3.08 KB
/
Auto.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
81
82
83
84
85
86
87
88
89
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.util.ElapsedTime;
@Autonomous(name="Centerstage Auto")
public class Auto extends LinearOpMode {
/* Declare OpMode members. */
protected DcMotor frontLeft;
protected DcMotor frontRight;
protected DcMotor backLeft;
protected DcMotor backRight;
private ElapsedTime runtime = new ElapsedTime();
static final double FORWARD_SPEED = 0.6;
static final double TURN_SPEED = 0.5;
@Override
public void runOpMode() {
// Initialize the drive system variables.
frontLeft = hardwareMap.get(DcMotor.class, "frontLeft");
frontRight = hardwareMap.get(DcMotor.class, "frontRight");
backLeft = hardwareMap.get(DcMotor.class, "backLeft");
backRight = hardwareMap.get(DcMotor.class, "backRight");
frontLeft.setDirection(DcMotor.Direction.REVERSE);
frontRight.setDirection(DcMotor.Direction.FORWARD);
backLeft.setDirection(DcMotor.Direction.REVERSE);
backRight.setDirection(DcMotor.Direction.FORWARD);
// Send telemetry message to signify robot waiting;
telemetry.addData("Status", "Ready to run"); //
telemetry.update();
// Wait for the game to start (driver presses PLAY)
waitForStart();
// Step through each leg of the path, ensuring that the Auto mode has not been stopped along the way
// Step 1: Drive forward for 3 seconds
frontLeft.setPower(FORWARD_SPEED);
frontRight.setPower(FORWARD_SPEED);
backLeft.setPower(FORWARD_SPEED);
backRight.setPower(FORWARD_SPEED);
runtime.reset();
while (opModeIsActive() && (runtime.seconds() < 3.0)) {
telemetry.addData("Path", "Leg 1: %4.1f S Elapsed", runtime.seconds());
telemetry.update();
}
// Step 2: Spin right for 1.3 seconds
frontLeft.setPower(TURN_SPEED);
frontRight.setPower(-TURN_SPEED);
backLeft.setPower(TURN_SPEED);
backRight.setPower(-TURN_SPEED);
runtime.reset();
while (opModeIsActive() && (runtime.seconds() < 1.3)) {
telemetry.addData("Path", "Leg 2: %4.1f S Elapsed", runtime.seconds());
telemetry.update();
}
// Step 3: Drive Backward for 1 Second
frontLeft.setPower(-FORWARD_SPEED);
frontRight.setPower(-FORWARD_SPEED);
backLeft.setPower(-FORWARD_SPEED);
backRight.setPower(-FORWARD_SPEED);
runtime.reset();
while (opModeIsActive() && (runtime.seconds() < 1.0)) {
telemetry.addData("Path", "Leg 3: %4.1f S Elapsed", runtime.seconds());
telemetry.update();
}
// Step 4: Stop
frontLeft.setPower(0);
frontRight.setPower(0);
backLeft.setPower(0);
backRight.setPower(0);
telemetry.addData("Path", "Complete");
telemetry.update();
sleep(1000);
}
}