Skip to content
This repository was archived by the owner on May 19, 2024. It is now read-only.

Commit 8df3560

Browse files
committed
refactor(superstructure): Improve checking at goal.
1 parent ac2f03b commit 8df3560

File tree

2 files changed

+10
-37
lines changed

2 files changed

+10
-37
lines changed

src/main/java/frc/robot/superstructure/Superstructure.java

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,21 @@ public static Superstructure getInstance() {
5858

5959
@Override
6060
public void periodic() {
61-
updateMeasurement();
61+
measurement = new SuperstructureState(arm.getState(), intake.getState(), shooter.getState());
62+
63+
SuperstructureMechanism.getInstance().updateSuperstructure(measurement);
6264
}
6365

6466
@Override
6567
public void addToShuffleboard(ShuffleboardTab tab) {
6668
addStateToShuffleboard(tab, "Measurement", () -> measurement);
6769
addStateToShuffleboard(tab, "Goal", () -> goal);
6870

69-
ShuffleboardLayout state = Telemetry.addColumn(tab, "State");
70-
71-
state.addString(
71+
Telemetry.addColumn(tab, "State").addString(
7272
"State",
7373
() -> this.getCurrentCommand() != null ? this.getCurrentCommand().getName() : "NONE");
7474

75-
ShuffleboardLayout at = Telemetry.addColumn(tab, "At Goal?");
76-
77-
at.addBoolean("At Goal?", () -> at(goal));
75+
Telemetry.addColumn(tab, "At Goal?").addBoolean("At Goal?", this::atGoal);
7876
}
7977

8078
private void addStateToShuffleboard(
@@ -105,16 +103,6 @@ private void addStateToShuffleboard(
105103
() -> state.get().shooterState().serializerVelocityRotationsPerSecond());
106104
}
107105

108-
private void updateMeasurement() {
109-
measurement = new SuperstructureState(arm.getState(), intake.getState(), shooter.getState());
110-
111-
SuperstructureMechanism.getInstance().updateSuperstructure(measurement);
112-
}
113-
114-
public SuperstructureState getState() {
115-
return measurement;
116-
}
117-
118106
public void setPosition(SuperstructureState state) {
119107
arm.setPosition(state.armState());
120108
}
@@ -127,18 +115,18 @@ public void setGoal(SuperstructureState goal) {
127115
shooter.setGoal(goal.shooterState());
128116
}
129117

130-
public boolean at(SuperstructureState goal) {
131-
updateMeasurement();
132-
133-
return measurement.atGoal(goal);
118+
public boolean atGoal() {
119+
return arm.atGoal()
120+
&& intake.atGoal()
121+
&& shooter.atGoal();
134122
}
135123

136124
private Command hold(SuperstructureState goal) {
137125
return run(() -> setGoal(goal));
138126
}
139127

140128
private Command to(SuperstructureState goal) {
141-
return run(() -> setGoal(goal)).until(() -> at(goal));
129+
return run(() -> setGoal(goal)).until(this::atGoal);
142130
}
143131

144132
public Command stow() {

src/main/java/frc/robot/superstructure/SuperstructureState.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package frc.robot.superstructure;
22

3-
import frc.robot.arm.Arm;
43
import frc.robot.arm.ArmState;
5-
import frc.robot.intake.Intake;
64
import frc.robot.intake.IntakeState;
7-
import frc.robot.shooter.Shooter;
85
import frc.robot.shooter.ShooterState;
96
import java.util.Objects;
107

@@ -51,16 +48,4 @@ public record SuperstructureState(
5148
Objects.requireNonNull(intakeState);
5249
Objects.requireNonNull(shooterState);
5350
}
54-
55-
/**
56-
* Returns true if at the superstructure goal.
57-
*
58-
* @param goal
59-
* @return true if at the superstructure goal.
60-
*/
61-
public boolean atGoal(SuperstructureState goal) {
62-
return Arm.getInstance().atGoal()
63-
&& Intake.getInstance().atGoal()
64-
&& Shooter.getInstance().atGoal();
65-
}
6651
}

0 commit comments

Comments
 (0)