-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutonomousFunctions.java
81 lines (66 loc) · 3.21 KB
/
AutonomousFunctions.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
//these are functions from 2018's robot autonomous
public class autonomousFunction{
public void resetEncoder(){
LF.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
RF.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
LB.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
RB.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
LF.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
RF.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
LB.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
RB.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
}
//enables the bot to drive, putting in speed, left and right inches to move, and a timeout length
public void encoderDrive(double speed,
double leftInches, double rightInches,
double timeout) {
int newLFTarget;
int newRFTarget;
int newLBTarget;
int newRBTarget;
if (opModeIsActive()) {
newLFTarget = LF.getCurrentPosition() + (int)(leftInches * COUNTS_PER_INCH);
newRFTarget = RF.getCurrentPosition() + (int)(rightInches * COUNTS_PER_INCH);
newLBTarget = LB.getCurrentPosition() + (int)(leftInches * COUNTS_PER_INCH);
newRBTarget = RB.getCurrentPosition() + (int)(rightInches * COUNTS_PER_INCH);
LF.setTargetPosition(newLFTarget);
RF.setTargetPosition(newRFTarget);
LB.setTargetPosition(newLBTarget);
RB.setTargetPosition(newRBTarget);
LF.setMode(DcMotor.RunMode.RUN_TO_POSITION);
RF.setMode(DcMotor.RunMode.RUN_TO_POSITION);
LB.setMode(DcMotor.RunMode.RUN_TO_POSITION);
RB.setMode(DcMotor.RunMode.RUN_TO_POSITION);
// reset the timeout time and start motion.
runtime.reset();
LF.setPower(Math.abs(speed));
RF.setPower(Math.abs(speed));
LB.setPower(Math.abs(speed));
RB.setPower(Math.abs(speed));
while (opModeIsActive() &&
(runtime.seconds() < timeout) &&
(LF.isBusy() || RF.isBusy()) && (LB.isBusy() || RB.isBusy() )) {
telemetry.addData("Path1", "Running to %7d :%7d", newLFTarget, newRFTarget);
telemetry.addData("Path2", "Running at %7d :%7d",LF.getCurrentPosition(), RF.getCurrentPosition());
telemetry.update();
}
LF.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
RF.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
LB.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
RB.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
sleep(250); // optional pause after each move
}
}
//allows the robot to turn a fixed ammount. As of 11-5-19 we have a much more useful and efficent turning function
public void turn(){
encoderDrive(.3, -4, -4.5, 5);
sleep(1000);
encoderDrive(.3, -6, 6, 5);
sleep(1000);
encoderDrive(.3, 13, 13, 5);
sleep(1000);
encoderDrive(.3, -6, 6, 5);
sleep(1000);
encoderDrive(.3, 4, 4, 5);
}
}