This repository has been archived by the owner on Jul 10, 2019. It is now read-only.
/
ConveyAutomatic.java
77 lines (65 loc) · 2.26 KB
/
ConveyAutomatic.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
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.stuy.commands;
/**
*
* @author Kevin Wang
*/
public class ConveyAutomatic extends CommandBase {
/**
* Don't shoot until the ball has been sitting at the top of the conveyor
* for at least this much time.
* Prevents ball from being shot with extra energy due to the conveyor.
* Longer / shorter conveyor runs can kill our consistency.
*/
boolean hasTimeout = false;
double timeout;
public ConveyAutomatic() {
// Use requires() here to declare subsystem dependencies
// eg. requires(chassis);
requires(conveyor);
}
public ConveyAutomatic(double timeout) {
this();
hasTimeout = true;
this.timeout = timeout;
}
// Called just before this Command runs the first time
protected void initialize() {
setTimeout(timeout);
}
// Called repeatedly when this Command is scheduled to run
protected void execute() {
if (flywheel.isSpeedGood() && flywheel.isSpinning() && // flywheel's at correct speed
flywheel.isSpeedSettled() && // flywheel's been stable at correct speed for long enough
conveyor.ballSettled) { // conveyor's not accelerating ball
conveyor.convey();
// Restart ball delay, only after ball exits the top sensor zone
// Without this check, this algorithm would continuously halt the
// ball as it passes through the sensor's line of sight
if (!conveyor.curBallAtTop) {
conveyor.startBallDelayTime = -1;
}
}
else {
conveyor.stop();
}
}
// Make this return true when this Command no longer needs to run execute()
protected boolean isFinished() {
if (hasTimeout) {
return isTimedOut();
}
return false;
}
// Called once after isFinished returns true
protected void end() {
conveyor.stop();
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
protected void interrupted() {
}
}