forked from IsaacRatliff/FTC-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParkingRed.java
88 lines (72 loc) · 3 KB
/
ParkingRed.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
package workspace_;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.util.ElapsedTime;
@Autonomous(name="5 Point Parking (Red)", group="Linear Opmode")
public class ParkingRed extends LinearOpMode {
/* Declare OpMode members. */
private ElapsedTime runtime = new ElapsedTime();
private DcMotor leftDrive_0 = null;
private DcMotor rightDrive_0 = null;
private DcMotor leftDrive_1 = null;
private DcMotor rightDrive_1 = null;
private void leftWheels(double spd){
leftDrive_0.setPower(spd);
leftDrive_1.setPower(spd);
}
private void rightWheels(double spd){
rightDrive_0.setPower(spd);
rightDrive_1.setPower(spd);
}
@Override
public void runOpMode() {
double speed = 6.15 /4; // it took 6.45 sec to go 4 tiles at full spd
double turn90 = 1.5;
// Send telemetry message to signify robot waiting;
telemetry.addData("Status", "Ready to run"); //
telemetry.update();
leftDrive_0 = hardwareMap.get(DcMotor.class, "leftDrive_0");
rightDrive_0 = hardwareMap.get(DcMotor.class, "rightDrive_0");
leftDrive_1 = hardwareMap.get(DcMotor.class, "leftDrive_1");
rightDrive_1 = hardwareMap.get(DcMotor.class, "rightDrive_1");
leftDrive_0.setDirection(DcMotor.Direction.FORWARD);
rightDrive_0.setDirection(DcMotor.Direction.REVERSE);
leftDrive_1.setDirection(DcMotor.Direction.FORWARD);
rightDrive_1.setDirection(DcMotor.Direction.REVERSE);
// 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 0.5 tiles
leftWheels(1.0);
rightWheels(1.0);
runtime.reset();
while (opModeIsActive() && (runtime.seconds() < 0.5*speed)) {
telemetry.addData("Path", "Leg 1: %2.5f S Elapsed", runtime.seconds());
telemetry.update();
}
// Step 2: Spin right 90 degrees
leftWheels(1.0);
rightWheels(-1.0);
runtime.reset();
while (opModeIsActive() && (runtime.seconds() < turn90)) {
telemetry.addData("Path", "Leg 2: %2.5f S Elapsed", runtime.seconds());
telemetry.update();
}
// Step 3: Drive Forward 2.0 tiles
leftWheels(1.0);
rightWheels(1.0);
runtime.reset();
while (opModeIsActive() && (runtime.seconds() < 1.5*speed)) {
telemetry.addData("Path", "Leg 3: %2.5f S Elapsed", runtime.seconds());
telemetry.update();
}
// Step 4: Stop.
leftWheels(0);
rightWheels(0);
telemetry.addData("Path", "Complete");
telemetry.update();
sleep(1000);
}
}