-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautoDriveStraight
80 lines (58 loc) · 1.71 KB
/
autoDriveStraight
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.usfirst.frc.team6418.robot.commands;
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.command.Command;
import org.usfirst.frc.team6418.robot.Robot;
/**
*
*/
public class autoDriveStraight extends Command {
protected double numFeet;
protected double encTicsFromFeet;
public autoDriveStraight(double feetToDrive) {
// Use requires() here to declare subsystem dependencies
//requires(Robot.exampleSubsystem);
numFeet = feetToDrive;
encTicsFromFeet = numFeet*12/(6*Math.PI)*360/2400;
requires(Robot.driveTrain);
//it's not a subsystem, so it won't require the driveTrain
//we need the encoder methods and data for this command
requires(Robot.leftEncoder);
requires(Robot.rightEncoder);
}
private void requires(Encoder leftEncoder) {
// TODO Auto-generated method stub
}
private void requires(RobotDrive driveTrain) {
// TODO Auto-generated method stub
}
// Called just before this Command runs the first time
@Override
protected void initialize() {
}
// Called repeatedly when this Command is scheduled to run
@Override
protected void execute() {
if (leftEncoder.getDistance() < encTicsFromFeet) {
//feet:
left.set(.3);
right.set(.3);
}
}
// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return (leftEncoder.getDistance() < encTicsFromFeet);
}
// Called once after isFinished returns true
@Override
protected void end() {
left.set(0);
right.set(0);
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
@Override
protected void interrupted() {
}
}