@@ -118,49 +118,75 @@ protected void afterTransition(ArmState newState) {
118
118
119
119
case CLIMBING_1_LINEUP -> {
120
120
leftMotor .setControl (
121
- positionRequest .withPosition (ArmAngle .CLIMBING_1_LINEUP .getRotations ()));
121
+ positionRequest .withPosition (
122
+ Units .degreesToRotations (clamp (ArmAngle .CLIMBING_1_LINEUP .getDegrees ()))));
122
123
rightMotor .setControl (
123
- positionRequest .withPosition (ArmAngle .CLIMBING_1_LINEUP .getRotations ()));
124
+ positionRequest .withPosition (
125
+ Units .degreesToRotations (clamp (ArmAngle .CLIMBING_1_LINEUP .getDegrees ()))));
124
126
}
125
127
case CLIMBING_2_HANGING -> {
126
128
leftMotor .setControl (
127
- positionRequest .withPosition (ArmAngle .CLIMBING_2_HANGING .getRotations ()));
129
+ positionRequest .withPosition (
130
+ Units .degreesToRotations (clamp (ArmAngle .CLIMBING_2_HANGING .getDegrees ()))));
128
131
rightMotor .setControl (
129
- positionRequest .withPosition (ArmAngle .CLIMBING_2_HANGING .getRotations ()));
132
+ positionRequest .withPosition (
133
+ Units .degreesToRotations (clamp (ArmAngle .CLIMBING_2_HANGING .getDegrees ()))));
130
134
}
131
135
132
136
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 ()))));
135
143
}
136
144
137
145
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 ()))));
140
152
}
141
153
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 ()))));
144
160
}
145
161
146
162
case FEEDING -> {
147
- double newAngle = Units .degreesToRotations (feedSpotDistanceToAngle .get (distanceToFeedSpot ));
163
+ double newAngle =
164
+ Units .degreesToRotations (clamp (feedSpotDistanceToAngle .get (distanceToFeedSpot )));
148
165
leftMotor .setControl (positionRequest .withPosition (newAngle ));
149
166
rightMotor .setControl (positionRequest .withPosition (newAngle ));
150
167
}
151
168
case SPEAKER_SHOT -> {
152
- var newAngle = Units .degreesToRotations (speakerDistanceToAngle .get (distanceToSpeaker ));
169
+ var newAngle =
170
+ Units .degreesToRotations (clamp (speakerDistanceToAngle .get (distanceToSpeaker )));
153
171
154
172
leftMotor .setControl (positionRequest .withPosition (newAngle ));
155
173
rightMotor .setControl (positionRequest .withPosition (newAngle ));
156
174
}
157
175
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 ()))));
160
182
}
161
183
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 ()))));
164
190
}
165
191
}
166
192
}
@@ -193,4 +219,9 @@ public void robotPeriodic() {
193
219
setStateFromRequest (ArmState .IDLE );
194
220
}
195
221
}
222
+
223
+ private static double clamp (double armAngle ) {
224
+ return MathUtil .clamp (
225
+ armAngle , RobotConfig .get ().arm ().minAngle (), RobotConfig .get ().arm ().maxAngle ());
226
+ }
196
227
}
0 commit comments