|
1 | 1 | package frc.robot.subsystems.intake |
2 | 2 |
|
| 3 | +import edu.wpi.first.wpilibj2.command.Command |
| 4 | +import edu.wpi.first.wpilibj2.command.Commands |
3 | 5 | import edu.wpi.first.wpilibj2.command.SubsystemBase |
| 6 | +import frc.robot.RobotState |
4 | 7 |
|
5 | 8 | // By making a subsystem a Kotlin object, we ensure there is only ever one instance of it. |
6 | 9 | // It also reduces the need to have reference variables for the subsystems to be passed around. |
7 | 10 | class IntakeSystem(private val io: IntakeIO) : SubsystemBase() { |
8 | | - /** |
9 | | - * Example command factory method. |
10 | | - * |
11 | | - * @return a command |
12 | | - */ |
13 | | -// fun exampleMethodCommand(): Command = runOnce { |
14 | | -// // Subsystem.runOnce() implicitly add `this` as a required subsystem. |
15 | | -// // TODO: one-time action goes here |
16 | | -// } |
17 | | - |
18 | | - /** |
19 | | - * An example method querying a boolean state of the subsystem (for example, a digital sensor). |
20 | | - * |
21 | | - * @return value of some boolean subsystem state, such as a digital sensor. |
22 | | - */ |
23 | | -// fun exampleCondition(): Boolean { |
24 | | -// // Query some boolean state, such as a digital sensor. |
25 | | -// return false |
26 | | -// } |
| 11 | + private fun setCoralIntakeState(state: CoralIntakeState) = run { io.setCoralIntakeState(state) } |
| 12 | + private fun setAlgaeIntakeState(state: AlgaeIntakeState) = run { io.setAlgaeIntakeState(state) } |
| 13 | + |
| 14 | + private fun awaitCoralState(state: CoralState) = Commands.waitUntil { io.getCoralState() == state } |
| 15 | + private fun awaitAlgaeState(state: AlgaeState) = Commands.waitUntil { io.getAlgaeState() == state } |
| 16 | + |
| 17 | + fun coralIntake() = Commands.sequence( |
| 18 | + setCoralIntakeState(CoralIntakeState.Intaking), |
| 19 | + awaitCoralState(CoralState.Stored), |
| 20 | + setCoralIntakeState(CoralIntakeState.Idle) |
| 21 | + ) |
| 22 | + |
| 23 | + fun coralScore() = Commands.sequence( |
| 24 | + setCoralIntakeState(CoralIntakeState.Scoring), |
| 25 | + awaitCoralState(CoralState.Empty), |
| 26 | + Commands.waitSeconds(IntakeConstants.coralScoreTimeoutSeconds), |
| 27 | + setCoralIntakeState(CoralIntakeState.Idle) |
| 28 | + ) |
| 29 | + |
| 30 | + fun algaeIntake() = Commands.sequence( |
| 31 | + setAlgaeIntakeState(AlgaeIntakeState.Intaking), |
| 32 | + awaitAlgaeState(AlgaeState.Stored), |
| 33 | + setAlgaeIntakeState(AlgaeIntakeState.Holding) |
| 34 | + ) |
| 35 | + |
| 36 | + fun algaeScore() = Commands.sequence( |
| 37 | + setAlgaeIntakeState(AlgaeIntakeState.Scoring), |
| 38 | + awaitAlgaeState(AlgaeState.Empty), |
| 39 | + Commands.waitSeconds(IntakeConstants.algaeScoreTimeoutSeconds), |
| 40 | + setAlgaeIntakeState(AlgaeIntakeState.Idle) |
| 41 | + ) |
| 42 | + |
27 | 43 |
|
28 | 44 | override fun periodic() { |
29 | | - // This method will be called once per scheduler run |
| 45 | + RobotState.coralState = io.getCoralState() |
| 46 | + RobotState.algaeState = io.getAlgaeState() |
30 | 47 | } |
31 | 48 |
|
32 | 49 | override fun simulationPeriodic() { |
33 | | - // This method will be called once per scheduler run during simulation |
34 | | - } |
35 | | - |
36 | | -// fun exampleAction() |
37 | | -// { |
38 | | -// // This action is called by the ExampleCommand |
39 | | -// println("ExampleSubsystem.exampleAction has been called") |
40 | | -// } |
41 | | - |
42 | | - fun getPos(): Double { |
43 | | - TODO("Not yet implemented") |
44 | | - return 0.0; |
45 | | - } |
46 | | - |
47 | | - fun setPos(x: Double) { |
48 | | - TODO("Not yet implemented") |
49 | 50 | } |
50 | 51 | } |
0 commit comments