-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEncoderAutoDriver.java
81 lines (63 loc) · 2.55 KB
/
EncoderAutoDriver.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
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 EncoderAutoDriver extends AutoDriver
{
public EncoderAutoDriver(HardwareConfiguration 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)
&& hw.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 driveToDistance(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();
}
}