-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRunRoller.java
More file actions
80 lines (64 loc) · 2.55 KB
/
RunRoller.java
File metadata and controls
80 lines (64 loc) · 2.55 KB
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.carlmontrobotics.robotcode2023.commands;
import org.carlmontrobotics.robotcode2023.subsystems.Roller;
import org.carlmontrobotics.robotcode2023.Constants.Roller.GameObject;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.CommandBase;
public class RunRoller extends CommandBase {
private final Roller roller;
private final Timer timer = new Timer();
private final Roller.RollerMode mode;
public RunRoller(Roller roller, Roller.RollerMode mode) {
addRequirements(this.roller = roller);
this.mode = mode;
}
@Override
public void initialize() {
System.err.println("=============================RunRoller is Started=============================");
if (mode.speed > 0) { // should not interrupt command to stop rollers
if (roller.hasGamePiece() && isIntake())
cancel();
if (!roller.hasGamePiece() && !isIntake())
cancel();
}
System.err.println("=============================RunRoller is initialized=============================");
timer.reset();
roller.setRollerMode(mode);
}
@Override
public void execute() {
}
@Override
public void end(boolean interrupted) {
// keep it running if its a cone
if (mode.obj != GameObject.CONE && !interrupted) {
mode.speed = 0;
roller.setRollerMode(mode);
}
timer.stop();
System.err.println(
"=============================RunRoller has ended==========================================================");
}
@Override
public boolean isFinished() {
if (mode.speed == 0)
return true;
double time = timer.get();
// TODO: distance sensor detects belt when wrist is spinning (concern)
if (roller.hasGamePiece() == isIntake()) {
timer.start();
} else if (roller.hasGamePiece() != isIntake()) {
timer.stop();
timer.reset();
}
SmartDashboard.putString("Target Piece", mode.obj.toString());
SmartDashboard.putNumber("Time Target", mode.time);
SmartDashboard.putNumber("SetRoller Time Elapsed (s)", time);
return roller.hasGamePiece() == isIntake() && time > mode.time;
}
// The rollerMode indicates what object it is trying to take in
// if the object is NONE, then it is trying to outtake
public boolean isIntake() {
return (mode.obj != GameObject.NONE);
}
}