Repository navigation
Expand file tree
/
Copy pathAutomode1.java
More file actions
73 lines (48 loc) · 1.65 KB
/
Copy pathAutomode1.java
File metadata and controls
73 lines (48 loc) · 1.65 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
68
69
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;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
@Autonomous(name = "Automode1")
public class Automode1 extends LinearOpMode {
private final ElapsedTime runtime = new ElapsedTime();
private DcMotor leftFrontDrive;
private DcMotor rightFrontDrive;
@Override
public void runOpMode() {
leftFrontDrive = hardwareMap.get(DcMotor.class, "FL");
rightFrontDrive = hardwareMap.get(DcMotor.class, "FR");
// Wait for motors to start
waitForStart();
// turn the motors on.
startMotors();
// go forward for 1 seconds.
double targetEnd = runtime.milliseconds() + 500;
while (runtime.milliseconds() < targetEnd) {
// do nothing.
}
// ElapsedTime endtime = runtime.
// Duration additionalTime = Duration.ofMillis(3000);
// turn the motors off.
stopMotors();
}
public static void waitSeconds(double seconds) {
try {
Thread.sleep(Math.round(seconds * 1000.0));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
private void startMotors() {
leftFrontDrive.setPower(-0.5);
rightFrontDrive.setPower(0.5);
return;
}
private void stopMotors() {
leftFrontDrive.setPower(0.0);
rightFrontDrive.setPower(0.0);
return;
}
}