Skip to content

Commit aaabe02

Browse files
committed
refactor: move & rename ElevatorState enum to ElevatorExtension
Signed-off-by: Dasun Abeykoon <[email protected]>
1 parent af39331 commit aaabe02

File tree

3 files changed

+32
-48
lines changed

3 files changed

+32
-48
lines changed

src/main/java/org/frc6423/robot/subsystems/superstructure/elevator/Elevator.java

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
package org.frc6423.robot.subsystems.superstructure.elevator;
88

9-
import static edu.wpi.first.units.Units.Centimeters;
109
import static edu.wpi.first.units.Units.Inches;
1110
import static edu.wpi.first.units.Units.Meters;
1211
import static edu.wpi.first.units.Units.MetersPerSecond;
@@ -30,9 +29,13 @@
3029

3130
/** Elevator Subsystem */
3231
public class Elevator extends SubsystemBase implements AutoCloseable {
33-
// * CONSTANTS
32+
/** Name of the CAN bus hardware is on */
3433
public static final String CANBUS = "CANCHAN";
34+
35+
/** Parent motor CAN ID */
3536
public static final int PARENT_MOTOR_ID = 14;
37+
38+
/** Child motor CAN ID */
3639
public static final int CHILD_MOTOR_ID = 15;
3740

3841
/** Gear ratio of the elevator gearbox */
@@ -59,6 +62,21 @@ public class Elevator extends SubsystemBase implements AutoCloseable {
5962
/** The acceleration of the elevator's trapezoid profile */
6063
public static final LinearAcceleration MAX_ACCELERATION = MetersPerSecondPerSecond.of(10.0);
6164

65+
/** Represents a height the elevator can extend to */
66+
public static enum ElevatorExtension {
67+
STOWED(Meters.of(0.0)),
68+
INTAKING(Meters.of(0.0)),
69+
L2(Meters.of(4.549)),
70+
L3(Meters.of(12.41)),
71+
L4(Meters.of(24.0));
72+
73+
Distance height;
74+
75+
ElevatorExtension(Distance height) {
76+
this.height = height;
77+
}
78+
}
79+
6280
@Logged(name = "Elevator Hardware Loggables")
6381
private final ElevatorIO hardware;
6482

@@ -104,10 +122,6 @@ public void periodic() {
104122
hardware.periodic();
105123

106124
filteredCurrent = currentFilter.calculate(hardware.getParentStatorCurrentAmps());
107-
108-
/** Set visualizer poses */
109-
visualizer.setCarriageHeight(getCarriageHeight().in(Centimeters));
110-
visualizer.setStageHeight(getStageHeight().in(Centimeters));
111125
}
112126

113127
/**
@@ -177,21 +191,21 @@ public Command runCurrentHoming() {
177191
/**
178192
* Run elevator to specified extension height
179193
*
180-
* @param extension {@link ElevatorState} representing desired extension height
194+
* @param extension {@link Distance} representing desired extension height
181195
* @return {@link Command}
182196
*/
183-
public Command runExtension(ElevatorState extension) {
184-
return this.runExtension(extension.height);
197+
public Command runExtension(Distance extension) {
198+
return this.run(() -> hardware.setPose(extension.in(Meters)));
185199
}
186200

187201
/**
188202
* Run elevator to specified extension height
189203
*
190-
* @param extension {@link Distance} representing desired extension height
204+
* @param extension {@link ElevatorExtension} representing desired extension height
191205
* @return {@link Command}
192206
*/
193-
public Command runExtension(Distance extension) {
194-
return this.run(() -> hardware.setPose(extension.in(Meters)));
207+
public Command runExtension(ElevatorExtension extension) {
208+
return runExtension(extension.height);
195209
}
196210

197211
/**

src/main/java/org/frc6423/robot/subsystems/superstructure/elevator/ElevatorState.java

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/test/java/org/frc6423/robot/ElevatorTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import java.util.ArrayList;
1818
import java.util.stream.Stream;
1919
import org.frc6423.robot.subsystems.superstructure.elevator.Elevator;
20-
import org.frc6423.robot.subsystems.superstructure.elevator.ElevatorState;
20+
import org.frc6423.robot.subsystems.superstructure.elevator.Elevator.ElevatorExtension;
2121
import org.junit.jupiter.api.AfterEach;
2222
import org.junit.jupiter.api.BeforeEach;
2323
import org.junit.jupiter.api.RepeatedTest;
@@ -65,13 +65,13 @@ public void runRandExtension() {
6565
}
6666

6767
/**
68-
* Run all {@link ElevatorState}
68+
* Run all {@link ElevatorExtension}
6969
*
70-
* @param extension {@link ElevatorState}
70+
* @param extension {@link ElevatorExtension}
7171
*/
7272
@ParameterizedTest
7373
@MethodSource("provideExtensionHeights")
74-
public void runExtensions(ElevatorState extension) {
74+
public void runExtensions(ElevatorExtension extension) {
7575
runToCompletion(
7676
elevator
7777
.runExtension(extension)
@@ -80,11 +80,11 @@ public void runExtensions(ElevatorState extension) {
8080
}
8181

8282
/**
83-
* @return {@link Stream} of all {@link ElevatorState}
83+
* @return {@link Stream} of all {@link ElevatorExtension}
8484
*/
8585
private static Stream<Arguments> provideExtensionHeights() {
8686
ArrayList<Arguments> extensions = new ArrayList<>();
87-
for (var extension : ElevatorState.values()) {
87+
for (var extension : ElevatorExtension.values()) {
8888
extensions.add(Arguments.of(extension));
8989
}
9090

0 commit comments

Comments
 (0)