Skip to content

Commit 4d3dd76

Browse files
authored
Add run and commands to Index subsystem (#12)
1 parent c1cc989 commit 4d3dd76

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/main/java/frc/robot/subsystems/Index.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
import com.revrobotics.spark.SparkLowLevel;
77
import com.revrobotics.spark.config.SparkBaseConfig;
88
import com.revrobotics.spark.config.SparkFlexConfig;
9+
import edu.wpi.first.wpilibj2.command.Command;
910
import edu.wpi.first.wpilibj2.command.SubsystemBase;
1011
import frc.robot.Constants;
12+
import java.util.function.DoubleSupplier;
1113

1214
// initializes index and funnel motors
1315
public class Index extends SubsystemBase {
@@ -48,4 +50,28 @@ public void setIndexSpeed(double speed) {
4850
public void setFunnelSpeed(double speed) {
4951
this.funnelMotor.set(speed);
5052
}
53+
54+
private void run() {
55+
setIndexSpeed(Constants.Index.INDEX_SPEED);
56+
setFunnelSpeed(Constants.Index.FUNNEL_SPEED);
57+
}
58+
59+
private void stop() {
60+
setIndexSpeed(0);
61+
setFunnelSpeed(0);
62+
}
63+
64+
public Command runCommand() {
65+
return startEnd(() -> run(), () -> stop());
66+
}
67+
68+
public Command runCommand(DoubleSupplier speedSupplier) {
69+
return runEnd(
70+
() -> {
71+
double speed = speedSupplier.getAsDouble();
72+
setIndexSpeed(speed);
73+
setFunnelSpeed(speed);
74+
},
75+
() -> stop());
76+
}
5177
}

0 commit comments

Comments
 (0)