Skip to content

Commit 7435535

Browse files
authored
Elevator testing (#93)
* elevator testing * changed coral wrist protection * changed coral wrist protection scheme again * use units in wrists * set Algae Wrist to 90 if state unknown
1 parent f2cbd13 commit 7435535

File tree

9 files changed

+61
-43
lines changed

9 files changed

+61
-43
lines changed

src/main/java/frc/lib/AutoSelector.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ private boolean updateAuto() {
9595
/**
9696
* @return Object for binding a command to a change in autonomous mode selection
9797
*/
98-
public Trigger changedAutoSelection = autoSelectionChanged.castTo(Trigger::new);
98+
public Trigger getChangedAutoSelection() {
99+
return autoSelectionChanged.castTo(Trigger::new);
100+
}
99101

100102
/** Schedules the command corresponding to the selected autonomous mode */
101103
public void scheduleAuto() {

src/main/java/frc/robot/Robot.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,14 @@ private void configureOperatorButtonBindings() {
274274
climbTrigger.onTrue(climber.createDeployCommand()
275275
.andThen(climber.createClimbByControllerCommand(operator.getHID(), -ClimberConstants.kMaxVelocityInchesPerSecond)));
276276
}
277-
// spotless:on
278277

279278
private void configureEventBindings() {
280-
autoSelector.changedAutoSelection.onTrue(leds.createChangeAutoAnimationCommand());
281-
lifter.impendingCoralGripperDamage.onTrue(coralWrist.createSetAngleCommand(CoralWristState.L1));
279+
autoSelector.getChangedAutoSelection()
280+
.onTrue(leds.createChangeAutoAnimationCommand());
281+
lifter.tooHighForCoralWrist.and(coralWrist.atRiskOfDamage)
282+
.onTrue(coralWrist.createSetAngleCommand(CoralWristState.AlgaeMode));
282283
}
284+
// spotless:on
283285

284286
private void configureAutoOptions() {
285287
autoSelector.addAuto(new AutoOption(Alliance.Red, 1, new RedL4AlgaeAuto(swerve, elevator)));

src/main/java/frc/robot/auto/BlueL4AlgaeAuto.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public AutoRoutine getAutoRoutine() {
7171
algaeRoller.createOuttakeCommand().withTimeout(0.2),
7272
Commands.parallel(
7373
blueProcessToSource.cmd(),
74-
lifter.createSetHeightCommand(LifterState.Intake))));
74+
lifter.createSetHeightCommand(LifterState.CoralIntake))));
7575
// spotless:on
7676

7777
return blueL4AlgAutoRoutine;

src/main/java/frc/robot/auto/RedL4AlgaeAuto.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public AutoRoutine getAutoRoutine() {
7171
algaeRoller.createOuttakeCommand().withTimeout(0.2),
7272
Commands.parallel(
7373
redProcessToSource.cmd(),
74-
lifter.createSetHeightCommand(LifterState.Intake))));
74+
lifter.createSetHeightCommand(LifterState.CoralIntake))));
7575
// spotless:on
7676

7777
return redL4AlgAutoRoutine;

src/main/java/frc/robot/elevator/AlgaeWrist.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import edu.wpi.first.math.MathUtil;
1717
import edu.wpi.first.math.controller.ArmFeedforward;
1818
import edu.wpi.first.math.controller.ProfiledPIDController;
19+
import edu.wpi.first.units.measure.Angle;
1920
import edu.wpi.first.wpilibj.XboxController;
2021
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
2122
import edu.wpi.first.wpilibj2.command.Command;
@@ -79,11 +80,11 @@ public AlgaeWrist() {
7980

8081
@Override
8182
public void periodic() {
82-
SmartDashboard.putNumber("Algae Wrist/Current Angle Degrees", getCurrentAngleDegrees());
83+
SmartDashboard.putNumber("Algae Wrist/Current Angle Degrees", getCurrentAngle().in(Degrees));
8384
SmartDashboard.putNumber("Algae Wrist/Current Angle Radians", encoder.getPosition());
8485
SmartDashboard.putNumber("Algae Wrist/Current Angular Velocity RPS", encoder.getVelocity());
8586
SmartDashboard.putString("Algae Wrist/Target State", getTargetState().name());
86-
SmartDashboard.putNumber("Algae Wrist/Setpoint Angle Degrees", getSetpointAngleDegrees());
87+
SmartDashboard.putNumber("Algae Wrist/Setpoint Angle Degrees", getSetpointAngle().in(Degrees));
8788
SmartDashboard.putNumber("Algae Wrist/Setpoint Angle Radians", feedback.getSetpoint().position);
8889
SmartDashboard.putNumber(
8990
"Algae Wrist/Setpoint Angular Velocity RPS", feedback.getSetpoint().velocity);
@@ -92,12 +93,12 @@ public void periodic() {
9293
SmartDashboard.putBoolean("Algae Wrist/At Goal", feedback.atGoal());
9394
}
9495

95-
private double getCurrentAngleDegrees() {
96-
return Radians.of(encoder.getPosition()).in(Degrees);
96+
private Angle getCurrentAngle() {
97+
return Radians.of(encoder.getPosition());
9798
}
9899

99-
private double getSetpointAngleDegrees() {
100-
return Radians.of(feedback.getSetpoint().position).in(Degrees);
100+
private Angle getSetpointAngle() {
101+
return Radians.of(feedback.getSetpoint().position);
101102
}
102103

103104
public void resetController() {
@@ -139,7 +140,10 @@ public Command createRemainAtCurrentAngleCommand() {
139140
return new FunctionalCommand(
140141
// initialize
141142
() -> {
142-
if (targetState == AlgaeWristState.Unknown) feedback.setGoal(encoder.getPosition());
143+
if (targetState == AlgaeWristState.Unknown) {
144+
targetState = AlgaeWristState.CoralMode;
145+
feedback.setGoal(targetState.angle.in(Radians));
146+
}
143147
},
144148
// execute
145149
() -> control(),

src/main/java/frc/robot/elevator/CoralWrist.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
import edu.wpi.first.math.MathUtil;
1717
import edu.wpi.first.math.controller.ArmFeedforward;
1818
import edu.wpi.first.math.controller.ProfiledPIDController;
19+
import edu.wpi.first.units.measure.Angle;
1920
import edu.wpi.first.wpilibj.XboxController;
2021
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
2122
import edu.wpi.first.wpilibj2.command.Command;
2223
import edu.wpi.first.wpilibj2.command.FunctionalCommand;
2324
import edu.wpi.first.wpilibj2.command.SubsystemBase;
25+
import edu.wpi.first.wpilibj2.command.button.Trigger;
2426
import frc.robot.Constants.RobotConstants;
2527
import frc.robot.elevator.ElevatorConstants.CoralWristConstants;
2628
import frc.robot.elevator.ElevatorConstants.CoralWristConstants.CoralWristState;
@@ -81,11 +83,11 @@ public CoralWrist() {
8183

8284
@Override
8385
public void periodic() {
84-
SmartDashboard.putNumber("Coral Wrist/Current Angle Degrees", getCurrentAngleDegrees());
86+
SmartDashboard.putNumber("Coral Wrist/Current Angle Degrees", getCurrentAngle().in(Degrees));
8587
SmartDashboard.putNumber("Coral Wrist/Current Angle Radians", encoder.getPosition());
8688
SmartDashboard.putNumber("Coral Wrist/Current Angular Velocity RPS", encoder.getVelocity());
8789
SmartDashboard.putString("Coral Wrist/Target State", getTargetState().name());
88-
SmartDashboard.putNumber("Coral Wrist/Setpoint Angle Degrees", getSetpointAngleDegrees());
90+
SmartDashboard.putNumber("Coral Wrist/Setpoint Angle Degrees", getSetpointAngle().in(Degrees));
8991
SmartDashboard.putNumber("Coral Wrist/Setpoint Angle Radians", feedback.getSetpoint().position);
9092
SmartDashboard.putNumber(
9193
"Coral Wrist/Setpoint Angular Velocity RPS", feedback.getSetpoint().velocity);
@@ -94,12 +96,12 @@ public void periodic() {
9496
SmartDashboard.putBoolean("Coral Wrist/At Goal", feedback.atGoal());
9597
}
9698

97-
private double getCurrentAngleDegrees() {
98-
return Radians.of(encoder.getPosition()).in(Degrees);
99+
private Angle getCurrentAngle() {
100+
return Radians.of(encoder.getPosition());
99101
}
100102

101-
private double getSetpointAngleDegrees() {
102-
return Radians.of(feedback.getSetpoint().position).in(Degrees);
103+
private Angle getSetpointAngle() {
104+
return Radians.of(feedback.getSetpoint().position);
103105
}
104106

105107
public void resetController() {
@@ -120,6 +122,14 @@ public CoralWristState getTargetState() {
120122
return this.targetState;
121123
}
122124

125+
public Boolean inState(CoralWristState state) {
126+
return this.targetState.equals(state);
127+
}
128+
129+
public Trigger atRiskOfDamage =
130+
new Trigger(
131+
() -> getCurrentAngle().gt(CoralWristState.AlgaeMode.angle.plus(Degrees.of(3.0))));
132+
123133
public Command createSetAngleCommand(CoralWristState state) {
124134
return new FunctionalCommand(
125135
// initialize

src/main/java/frc/robot/elevator/Elevator.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,35 +44,35 @@ public void resetPositionControllers() {
4444

4545
public Command coralL4PositionCG() {
4646
return Commands.parallel(
47-
lifter.createSetHeightCommand(LifterState.L4),
47+
lifter.createSetHeightCommand(LifterState.CoralL4),
4848
coralWrist.createSetAngleCommand(CoralWristState.L4),
4949
algaeWrist.createSetAngleCommand(AlgaeWristState.CoralMode));
5050
}
5151

5252
public Command coralL3PositionCG() {
5353
return Commands.parallel(
54-
lifter.createSetHeightCommand(LifterState.L3),
54+
lifter.createSetHeightCommand(LifterState.CoralL3),
5555
coralWrist.createSetAngleCommand(CoralWristState.L3),
5656
algaeWrist.createSetAngleCommand(AlgaeWristState.CoralMode));
5757
}
5858

5959
public Command coralL2PositionCG() {
6060
return Commands.parallel(
61-
lifter.createSetHeightCommand(LifterState.L2),
61+
lifter.createSetHeightCommand(LifterState.CoralL2),
6262
coralWrist.createSetAngleCommand(CoralWristState.L2),
6363
algaeWrist.createSetAngleCommand(AlgaeWristState.CoralMode));
6464
}
6565

6666
public Command coralL1PositionCG() {
6767
return Commands.parallel(
68-
lifter.createSetHeightCommand(LifterState.L1),
68+
lifter.createSetHeightCommand(LifterState.CoralL1),
6969
coralWrist.createSetAngleCommand(CoralWristState.L1),
7070
algaeWrist.createSetAngleCommand(AlgaeWristState.CoralMode));
7171
}
7272

7373
public Command coralIntakeCG() {
7474
return Commands.parallel(
75-
lifter.createSetHeightCommand(LifterState.Intake),
75+
lifter.createSetHeightCommand(LifterState.CoralIntake),
7676
coralWrist.createSetAngleCommand(CoralWristState.Intake),
7777
algaeWrist.createSetAngleCommand(AlgaeWristState.CoralMode),
7878
coralRoller.createIntakeCommand().until(coralRoller.hasCoral));
@@ -103,14 +103,14 @@ public Command algaeL2IntakeCG() {
103103

104104
public Command algaeProcessorPositionCG() {
105105
return Commands.parallel(
106-
lifter.createSetHeightCommand(LifterState.Processor),
106+
lifter.createSetHeightCommand(LifterState.AlgaeProcessor),
107107
coralWrist.createSetAngleCommand(CoralWristState.AlgaeMode),
108108
algaeWrist.createSetAngleCommand(AlgaeWristState.Processor));
109109
}
110110

111111
public Command algaeFloorIntakeCG() {
112112
return Commands.parallel(
113-
lifter.createSetHeightCommand(LifterState.Floor),
113+
lifter.createSetHeightCommand(LifterState.AlgaeIntakeFloor),
114114
coralWrist.createSetAngleCommand(CoralWristState.AlgaeMode),
115115
algaeWrist.createSetAngleCommand(AlgaeWristState.Floor),
116116
algaeRoller.createIntakeCommand().until(algaeRoller.hasAlage));

src/main/java/frc/robot/elevator/ElevatorConstants.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static final class LifterConstants {
3131
public static final double kVelocityConversionFactor = kPositionConversionFactor / 60.0;
3232

3333
public static final LinearVelocity kFineVelocity = InchesPerSecond.of(15.0);
34-
public static final LinearVelocity kRapidVelocity = InchesPerSecond.of(50.0);
34+
public static final LinearVelocity kRapidVelocity = InchesPerSecond.of(15.0);
3535
public static final LinearAccelerationUnit inchesPerSecondPerSecond =
3636
InchesPerSecond.per(Second);
3737
public static final LinearAcceleration kRapidAcceleration = inchesPerSecondPerSecond.of(1000);
@@ -48,17 +48,17 @@ public final class LifterController {
4848
public static enum LifterState {
4949
Unknown(0.0),
5050
Min(0.0),
51-
Floor(0.0),
52-
Reset(0.36),
53-
L1(18.0),
54-
L2(21.0),
55-
L3(24.0),
56-
L4(27.0),
57-
Intake(12.0),
58-
Processor(12.0),
51+
AlgaeIntakeFloor(0.0),
52+
EncoderReset(0.36),
53+
CoralL1(18.0),
54+
CoralL2(21.0),
55+
CoralL3(24.0),
56+
CoralL4(27.0),
57+
CoralIntake(12.0),
58+
AlgaeProcessor(12.0),
5959
AlgaeL2(30),
6060
AlgaeL3(46.5),
61-
Max(52.0);
61+
Max(67.8);
6262

6363
public Distance height;
6464

@@ -130,15 +130,15 @@ public static final class CoralWristConstants {
130130
public static final Angle kIZone = Degrees.of(30.0);
131131

132132
public static enum CoralWristState {
133-
Unknown(125),
133+
Unknown(90),
134134
Min(15),
135135
Max(135),
136136
L1(90),
137137
L2(55),
138138
L3(55),
139139
L4(25),
140140
Intake(125),
141-
AlgaeMode(125);
141+
AlgaeMode(90);
142142

143143
public Angle angle;
144144

src/main/java/frc/robot/elevator/Lifter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public Lifter() {
6868
.velocityConversionFactor(LifterConstants.kVelocityConversionFactor);
6969

7070
leaderConfig.softLimit
71-
.reverseSoftLimit(LifterState.Floor.height.in(Inches))
71+
.reverseSoftLimit(LifterState.Min.height.in(Inches))
7272
.reverseSoftLimitEnabled(true)
7373
.forwardSoftLimit(LifterState.Max.height.in(Inches))
7474
.forwardSoftLimitEnabled(true);
@@ -138,12 +138,12 @@ public Boolean inState(LifterState state) {
138138
return this.targetState.equals(state);
139139
}
140140

141-
public Trigger atIntakingHeight = new Trigger(() -> inState(LifterState.Intake));
142-
public Trigger impendingCoralGripperDamage =
143-
new Trigger(() -> getHeight().gt(LifterState.L3.height.plus(Inches.of(2.0))));
141+
public Trigger atIntakingHeight = new Trigger(() -> inState(LifterState.CoralIntake));
142+
public Trigger tooHighForCoralWrist =
143+
new Trigger(() -> getHeight().gt(LifterState.CoralL3.height.plus(Inches.of(2.0))));
144144

145145
private void resetEncoder() {
146-
encoder.setPosition(LifterState.Reset.height.in(Inches));
146+
encoder.setPosition(LifterState.EncoderReset.height.in(Inches));
147147
}
148148

149149
public Command createSetHeightCommand(LifterState state) {

0 commit comments

Comments
 (0)