-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEncoderAutoDriver2017.java
126 lines (90 loc) · 4.16 KB
/
EncoderAutoDriver2017.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package org.firstinspires.ftc.teamcode.RobotCoreExtensions;
/**
* Filename: EncoderAutoDriver.java
*
* Description:
* This class contains the methods that use the encoders for predefined autonomous movements.
*
* Methods:
* driveLeftSideToDistance - Drives the left side a specified distance using motor encoders
* driveRightSideToDistance - Drives the right side a specified distance using motor encoders
* driveToDistance - Drives both sides a specified distance using motor encoders
*
* Example: robot.hardwareConfiguration.encoderAutoDriver.driveLeftSideToDistance(double distance)
* Distances in inches.
*
* Requirements:
* - Drive motors with encoders
* - An encoder auto driver is created in a hardware configuration and accessed
* in an autonomous program for use.
*
* Changelog:
* -Edited and tested by Team 3486 on 7/8/2017.
* -Edited file description and documentation 7/22/17
*/
public class EncoderAutoDriver2017 extends TWAAutoDriver
{
public EncoderAutoDriver2017(AutoTWAHardwareConfiguration hw)
{
super(hw);
}
public void driveLeftSideToDistance(double distance)
{
setupMotion("Driving to set distance.");
hw.drivetrain.setPowers(0.3, 0.0);
// Drives the left side converting our inches input to counts while the OpMode is active
while(hw.drivetrain.getLeftEncoderCount() < hw.drivetrain.convertInchesToEncoderCounts(distance)
/*&& opMode.opModeIsActive()*/)
{}
hw.drivetrain.haltDrive();
endMotion();
}
public void driveRightSideToDistance(double distance)
{
setupMotion("Driving to set distance.");
hw.drivetrain.setPowers(0.0, 0.3);
// Drives the Right side converting our inches input to counts while the OpMode is active
while(hw.drivetrain.getRightEncoderCount() < hw.drivetrain.convertInchesToEncoderCounts(distance)
/*&& hw.opMode.opModeIsActive()*/)
{}
hw.drivetrain.haltDrive();
endMotion();
}
public void driveToDistanceForwards(double distance)
{
setupMotion("Driving to set distance.");
// Drives the both sides converting our inches input to counts while the OpMode is active
while(hw.drivetrain.getLeftEncoderCount() < hw.drivetrain.convertInchesToEncoderCounts(distance)
&& hw.drivetrain.getRightEncoderCount() < hw.drivetrain.convertInchesToEncoderCounts(distance)
&& hw.opMode.opModeIsActive()
){
hw.drivetrain.setPowers(0.3, 0.3);
hw.opMode.telemetry.addData("Right Encoder", hw.drivetrain.getRightEncoderCount());
hw.opMode.telemetry.addData("Left Encoder", hw.drivetrain.getLeftEncoderCount());
hw.opMode.telemetry.update();
}
endMotion();
}
public void driveToDistanceBackwards(double distance)
{
setupMotion("Driving to set distance.");
hw.drivetrain.setPowers(-0.3, -0.3);
// Drives the both sides converting our inches input to counts while the OpMode is active
while(hw.drivetrain.getLeftEncoderCount() > hw.drivetrain.convertInchesToEncoderCounts(distance)
&& hw.drivetrain.getRightEncoderCount() > hw.drivetrain.convertInchesToEncoderCounts(distance)
/*&& hw.opMode.opModeIsActive()*/) {}
endMotion();
}
public void spinRight(double leftInches, double rightInches){
setupMotion("Spinning set amount");
hw.drivetrain.setPowers(0.3, -0.3);
while (hw.drivetrain.getLeftEncoderCount() < hw.drivetrain.convertInchesToEncoderCounts(leftInches) && hw.drivetrain.getRightEncoderCount() > hw.drivetrain.convertInchesToEncoderCounts(rightInches) );{}
endMotion();
}
public void spinLeft(double leftInches, double rightInches){
setupMotion("Spinning set amount");
hw.drivetrain.setPowers(-0.3, 0.3);
while (hw.drivetrain.getLeftEncoderCount() > hw.drivetrain.convertInchesToEncoderCounts(leftInches) && hw.drivetrain.getRightEncoderCount()< hw.drivetrain.convertInchesToEncoderCounts(rightInches) );{}
endMotion();
}
}