Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Commit dd3efa9

Browse files
authored
added clamp to arm (#43)
* added clamp to arm * spotless
1 parent ae8728e commit dd3efa9

File tree

1 file changed

+47
-16
lines changed

1 file changed

+47
-16
lines changed

src/main/java/frc/robot/arm/ArmSubsystem.java

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,49 +118,75 @@ protected void afterTransition(ArmState newState) {
118118

119119
case CLIMBING_1_LINEUP -> {
120120
leftMotor.setControl(
121-
positionRequest.withPosition(ArmAngle.CLIMBING_1_LINEUP.getRotations()));
121+
positionRequest.withPosition(
122+
Units.degreesToRotations(clamp(ArmAngle.CLIMBING_1_LINEUP.getDegrees()))));
122123
rightMotor.setControl(
123-
positionRequest.withPosition(ArmAngle.CLIMBING_1_LINEUP.getRotations()));
124+
positionRequest.withPosition(
125+
Units.degreesToRotations(clamp(ArmAngle.CLIMBING_1_LINEUP.getDegrees()))));
124126
}
125127
case CLIMBING_2_HANGING -> {
126128
leftMotor.setControl(
127-
positionRequest.withPosition(ArmAngle.CLIMBING_2_HANGING.getRotations()));
129+
positionRequest.withPosition(
130+
Units.degreesToRotations(clamp(ArmAngle.CLIMBING_2_HANGING.getDegrees()))));
128131
rightMotor.setControl(
129-
positionRequest.withPosition(ArmAngle.CLIMBING_2_HANGING.getRotations()));
132+
positionRequest.withPosition(
133+
Units.degreesToRotations(clamp(ArmAngle.CLIMBING_2_HANGING.getDegrees()))));
130134
}
131135

132136
case DROP -> {
133-
leftMotor.setControl(positionRequest.withPosition(ArmAngle.DROP.getRotations()));
134-
rightMotor.setControl(positionRequest.withPosition(ArmAngle.DROP.getRotations()));
137+
leftMotor.setControl(
138+
positionRequest.withPosition(
139+
Units.degreesToRotations(clamp(ArmAngle.DROP.getDegrees()))));
140+
rightMotor.setControl(
141+
positionRequest.withPosition(
142+
Units.degreesToRotations(clamp(ArmAngle.DROP.getDegrees()))));
135143
}
136144

137145
case PODIUM_SHOT -> {
138-
leftMotor.setControl(positionRequest.withPosition(ArmAngle.PODIUM.getRotations()));
139-
rightMotor.setControl(positionRequest.withPosition(ArmAngle.PODIUM.getRotations()));
146+
leftMotor.setControl(
147+
positionRequest.withPosition(
148+
Units.degreesToRotations(clamp(ArmAngle.PODIUM.getDegrees()))));
149+
rightMotor.setControl(
150+
positionRequest.withPosition(
151+
Units.degreesToRotations(clamp(ArmAngle.PODIUM.getDegrees()))));
140152
}
141153
case SUBWOOFER_SHOT -> {
142-
leftMotor.setControl(positionRequest.withPosition(ArmAngle.SUBWOOFER.getRotations()));
143-
rightMotor.setControl(positionRequest.withPosition(ArmAngle.SUBWOOFER.getRotations()));
154+
leftMotor.setControl(
155+
positionRequest.withPosition(
156+
Units.degreesToRotations(clamp(ArmAngle.SUBWOOFER.getDegrees()))));
157+
rightMotor.setControl(
158+
positionRequest.withPosition(
159+
Units.degreesToRotations(clamp(ArmAngle.SUBWOOFER.getDegrees()))));
144160
}
145161

146162
case FEEDING -> {
147-
double newAngle = Units.degreesToRotations(feedSpotDistanceToAngle.get(distanceToFeedSpot));
163+
double newAngle =
164+
Units.degreesToRotations(clamp(feedSpotDistanceToAngle.get(distanceToFeedSpot)));
148165
leftMotor.setControl(positionRequest.withPosition(newAngle));
149166
rightMotor.setControl(positionRequest.withPosition(newAngle));
150167
}
151168
case SPEAKER_SHOT -> {
152-
var newAngle = Units.degreesToRotations(speakerDistanceToAngle.get(distanceToSpeaker));
169+
var newAngle =
170+
Units.degreesToRotations(clamp(speakerDistanceToAngle.get(distanceToSpeaker)));
153171

154172
leftMotor.setControl(positionRequest.withPosition(newAngle));
155173
rightMotor.setControl(positionRequest.withPosition(newAngle));
156174
}
157175
case AMP -> {
158-
leftMotor.setControl(positionRequest.withPosition(ArmAngle.AMP.getRotations()));
159-
rightMotor.setControl(positionRequest.withPosition(ArmAngle.AMP.getRotations()));
176+
leftMotor.setControl(
177+
positionRequest.withPosition(
178+
Units.degreesToRotations(clamp(ArmAngle.AMP.getDegrees()))));
179+
rightMotor.setControl(
180+
positionRequest.withPosition(
181+
Units.degreesToRotations(clamp(ArmAngle.AMP.getDegrees()))));
160182
}
161183
case PASS -> {
162-
leftMotor.setControl(positionRequest.withPosition(ArmAngle.PASS.getRotations()));
163-
rightMotor.setControl(positionRequest.withPosition(ArmAngle.PASS.getRotations()));
184+
leftMotor.setControl(
185+
positionRequest.withPosition(
186+
Units.degreesToRotations(clamp(ArmAngle.PASS.getDegrees()))));
187+
rightMotor.setControl(
188+
positionRequest.withPosition(
189+
Units.degreesToRotations(clamp(ArmAngle.PASS.getDegrees()))));
164190
}
165191
}
166192
}
@@ -193,4 +219,9 @@ public void robotPeriodic() {
193219
setStateFromRequest(ArmState.IDLE);
194220
}
195221
}
222+
223+
private static double clamp(double armAngle) {
224+
return MathUtil.clamp(
225+
armAngle, RobotConfig.get().arm().minAngle(), RobotConfig.get().arm().maxAngle());
226+
}
196227
}

0 commit comments

Comments
 (0)