@@ -39,7 +39,10 @@ public class Arm extends Subsystem {
39
39
/** Wrist motor values. */
40
40
private final WristMotorIOValues wristMotorValues = new WristMotorIOValues ();
41
41
42
+ /** Arm goal and setpoint states. */
42
43
private ArmState goal , setpoint ;
44
+
45
+ /** Telemetry for the shoulder and wrist trapezoid profiles. */
43
46
private final TrapezoidProfileTelemetry shoulderProfileTelemetry , wristProfileTelemetry ;
44
47
45
48
/** Creates a new instance of the arm subsystem. */
@@ -54,14 +57,8 @@ private Arm() {
54
57
shoulderMotor .configure ();
55
58
wristMotor .configure ();
56
59
57
- ArmState initialState = ArmState .INIT ;
58
-
59
- setPosition (initialState );
60
-
61
- // Since setPosition also resets goal and setpoint, this is redundant, but will protect from
62
- // nullish errors
63
- goal = initialState ;
64
- setpoint = initialState ;
60
+ setPosition (ArmState .INIT );
61
+ clearProfile ();
65
62
66
63
shoulderProfileTelemetry = new TrapezoidProfileTelemetry ("arm/shoulderProfile" );
67
64
wristProfileTelemetry = new TrapezoidProfileTelemetry ("arm/wristProfile" );
@@ -92,8 +89,6 @@ public void periodic() {
92
89
getMeasuredState ().shoulder (), getSetpoint ().shoulder (), getGoal ().shoulder ());
93
90
wristProfileTelemetry .update (
94
91
getMeasuredState ().wrist (), getSetpoint ().wrist (), getGoal ().wrist ());
95
-
96
- setSetpoint (setpoint .nextSetpoint (goal ));
97
92
}
98
93
99
94
@ Override
@@ -117,15 +112,13 @@ public void addToShuffleboard(ShuffleboardTab tab) {
117
112
() -> Units .rotationsToDegrees (getSetpoint ().shoulder ().position ));
118
113
setpoint .addDouble (
119
114
"Wrist Setpoint (deg)" , () -> Units .rotationsToDegrees (getSetpoint ().wrist ().position ));
120
- setpoint .addBoolean ("At Setpoint?" , this ::atSetpoint );
121
115
122
116
ShuffleboardLayout goal = Telemetry .addColumn (tab , "Goal" );
123
117
124
118
goal .addDouble (
125
119
"Shoulder Setpoint (deg)" , () -> Units .rotationsToDegrees (getGoal ().shoulder ().position ));
126
120
goal .addDouble (
127
121
"Wrist Setpoint (deg)" , () -> Units .rotationsToDegrees (getGoal ().wrist ().position ));
128
- goal .addBoolean ("At Goal?" , this ::atGoal );
129
122
130
123
ShuffleboardLayout voltages = Telemetry .addColumn (tab , "Voltages" );
131
124
@@ -146,12 +139,25 @@ public void addToShuffleboard(ShuffleboardTab tab) {
146
139
() -> wristMotorValues .accelerationRotationsPerSecondPerSecond );
147
140
}
148
141
142
+ /**
143
+ * Sets the position of the arm to the supplied state.
144
+ *
145
+ * @param state the state containing the position of the arm.
146
+ */
149
147
public void setPosition (ArmState state ) {
150
148
shoulderMotor .setPosition (state .shoulder ().position );
151
149
wristMotor .setPosition (state .wrist ().position );
150
+ }
152
151
153
- goal = state ;
154
- setpoint = state ;
152
+ /**
153
+ * Resets the goal and setpoints of the arm to the arm's current position. Commands the arm to
154
+ * hold its current position.
155
+ */
156
+ public void clearProfile () {
157
+ ArmState position = getMeasuredState ().position ();
158
+
159
+ goal = position ;
160
+ setpoint = position ;
155
161
}
156
162
157
163
/**
@@ -173,62 +179,124 @@ public ArmState getMeasuredState() {
173
179
return new ArmState (measuredShoulderState , measuredWristState );
174
180
}
175
181
176
- public ArmState getGoal () {
177
- return goal ;
182
+ /**
183
+ * Returns true if the arm is at a given state.
184
+ *
185
+ * @param state the state to compare to.
186
+ * @return true if the arm is at a given state.
187
+ */
188
+ public boolean at (ArmState state ) {
189
+ return getMeasuredState ().at (state );
178
190
}
179
191
180
- public boolean atGoal () {
181
- return atSetpoint () && setpoint .at (goal );
192
+ /**
193
+ * Returns the arm's goal.
194
+ *
195
+ * @return the arm's goal.
196
+ */
197
+ public ArmState getGoal () {
198
+ return this .goal ;
182
199
}
183
200
201
+ /**
202
+ * Sets the arm's goal.
203
+ *
204
+ * <p>Calling this method does not alter the arm's motion; it simply updates a value used for
205
+ * telemetry.
206
+ *
207
+ * @param goal the arm's goal.
208
+ */
184
209
public void setGoal (ArmState goal ) {
185
210
this .goal = goal ;
186
211
}
187
212
213
+ /**
214
+ * Returns the arm's setpoint.
215
+ *
216
+ * @return the arm's setpoint.
217
+ */
188
218
public ArmState getSetpoint () {
189
- return setpoint ;
219
+ return this . setpoint ;
190
220
}
191
221
192
- public boolean atSetpoint () {
193
- return getMeasuredState ().at (setpoint );
194
- }
195
-
196
- private void setSetpoint (ArmState setpoint ) {
222
+ /**
223
+ * Sets the arm's setpoint.
224
+ *
225
+ * <p>Calling this method does not alter the arm's motion; it simply updates a value used for
226
+ * telemetry.
227
+ *
228
+ * @param setpoint the arm's setpoint.
229
+ */
230
+ public void setSetpoint (ArmState setpoint ) {
197
231
this .setpoint = setpoint ;
232
+ }
198
233
234
+ /**
235
+ * Applies a setpoint to the arm's controllers.
236
+ *
237
+ * <p>Calling this method alters the arm's motion.
238
+ *
239
+ * @param setpoint the arm's setpoint.
240
+ */
241
+ public void applySetpoint (ArmState setpoint ) {
199
242
shoulderMotor .setSetpoint (setpoint .shoulder ().position , setpoint .shoulder ().velocity );
200
243
wristMotor .setSetpoint (setpoint .wrist ().position , setpoint .wrist ().velocity );
201
244
}
202
245
203
- private MoveShoulderCommand moveShoulder (ArmState goal ) {
246
+ /**
247
+ * Returns a command that moves the shoulder to a goal's shoulder position.
248
+ *
249
+ * @param goal the goal position to move to.
250
+ * @return a command that moves the shoulder to a goal's shoulder position.
251
+ */
252
+ private Command shoulderTo (ArmState goal ) {
204
253
return new MoveShoulderCommand (goal );
205
254
}
206
255
207
- public MoveWristCommand moveWrist (ArmState goal ) {
256
+ /**
257
+ * Returns a command that moves the wrist to a goal's wrist position.
258
+ *
259
+ * @param goal the goal position to move to.
260
+ * @return a command that moves the wrist to a goal's wrist position.
261
+ */
262
+ public Command wristTo (ArmState goal ) {
208
263
return new MoveWristCommand (goal );
209
264
}
210
265
211
- public Command moveShoulderThenWrist (ArmState goal ) {
212
- return moveShoulder (goal ).andThen (moveWrist (goal ));
213
- }
214
-
215
- public Command moveWristThenShoulder (ArmState goal ) {
216
- return moveWrist (goal ).andThen (moveShoulder (goal ));
266
+ /**
267
+ * Returns a command that moves the arm to the amp position.
268
+ *
269
+ * @return a comamnd that moves the arm to the amp position.
270
+ */
271
+ public Command amp () {
272
+ return shoulderTo (ArmState .AMP ).andThen (wristTo (ArmState .AMP ));
217
273
}
218
274
219
- public Command amp () {
220
- return moveShoulderThenWrist (ArmState .AMP );
275
+ /**
276
+ * Returns a command that moves the arm to the stow position.
277
+ *
278
+ * @return a command that moves the arm to the stow position.
279
+ */
280
+ public Command stow () {
281
+ return wristTo (ArmState .STOW ).andThen (shoulderTo (ArmState .STOW ));
221
282
}
222
283
284
+ /**
285
+ * Returns a command that moves the arm to the stow position and resets the position of the arm.
286
+ *
287
+ * <p>When the limit switch detects that the arm is in the stow position, the arm position is
288
+ * reset to be equal to the stow position.
289
+ *
290
+ * @return a command that moves the arm to the stow position and resets the position of the arm.
291
+ */
223
292
public Command home () {
224
- return moveWrist (ArmState .STOW )
225
- .andThen (moveShoulder (ArmState .STOW ).until (() -> limitSwitchValues .isPressed ))
293
+ return wristTo (ArmState .STOW )
294
+ .andThen (shoulderTo (ArmState .STOW ).until (() -> limitSwitchValues .isPressed ))
226
295
.finallyDo (
227
296
interrupted -> {
228
297
if (!interrupted ) {
229
298
setPosition (ArmState .STOW );
230
299
}
231
- })
232
- .withTimeout (3.0 );
300
+ });
233
301
}
234
302
}
0 commit comments