@@ -31,14 +31,19 @@ public static DoubleJointedArm getInstance() {
31
31
private DoubleJointedArmIOInputsAutoLogged inputs = new DoubleJointedArmIOInputsAutoLogged ();
32
32
33
33
private ArmState state ;
34
+ private ArmState storedState ;
35
+ private boolean intermediate ;
34
36
35
37
public DoubleJointedArm (DoubleJointedArmIO io ) {
36
38
this .io = io ;
37
- this .state = ArmState .STOW ;
39
+ state = ArmState .STOW ;
40
+ storedState = ArmState .STOW ;
41
+ intermediate = false ;
38
42
}
39
43
40
44
public enum ArmState {
41
45
STOW (Rotation2d .fromDegrees (10 ), Rotation2d .fromDegrees (10 )),
46
+ INT (Rotation2d .fromDegrees (90 ), Rotation2d .fromDegrees (90 )),
42
47
L4_FRONT (Rotation2d .fromDegrees (10 ), Rotation2d .fromDegrees (10 )),
43
48
L4_BACK (Rotation2d .fromDegrees (10 ), Rotation2d .fromDegrees (10 )),
44
49
L3_FRONT (Rotation2d .fromDegrees (10 ), Rotation2d .fromDegrees (10 )),
@@ -48,16 +53,16 @@ public enum ArmState {
48
53
L1_FRONT (Rotation2d .fromDegrees (10 ), Rotation2d .fromDegrees (10 )),
49
54
L1_BACK (Rotation2d .fromDegrees (10 ), Rotation2d .fromDegrees (10 ));
50
55
51
- private Rotation2d shoulderAngle ;
52
- private Rotation2d elbowAngle ;
53
-
54
56
private ArmState (Rotation2d shoulderAngle , Rotation2d elbowAngle ){
55
57
this .shoulderAngle = shoulderAngle ;
56
58
this .elbowAngle = elbowAngle ;
57
- }
59
+ }
60
+
61
+ private Rotation2d shoulderAngle ;
62
+ private Rotation2d elbowAngle ;
58
63
59
- public Rotation2d getShoulderTargetAngle () { return shoulderAngle ; }
60
- public Rotation2d getElbowTargetAngle () { return elbowAngle ; }
64
+ public Rotation2d getShoulderTarget () { return shoulderAngle ; }
65
+ public Rotation2d getElbowTarget () { return elbowAngle ; }
61
66
62
67
public ArmState getOpposite () {
63
68
switch (this ) {
@@ -74,43 +79,53 @@ public ArmState getOpposite() {
74
79
}
75
80
76
81
public boolean isFront () {
77
- return this .name ().endsWith ("FRONT" );
82
+ return this .name ().endsWith ("FRONT" ) || this . equals ( ArmState . STOW ) ;
78
83
}
79
84
}
80
85
81
- public void setState (ArmState state ) { this .state = state ; }
82
- public void switchSides () { state = state .getOpposite (); }
86
+ public void setState (ArmState state ) {
87
+ this .state = state ;
88
+ }
89
+
90
+ public void switchSides () {
91
+ if (!intermediate ) {
92
+ intermediate = true ;
93
+ storedState = state .getOpposite ();
94
+ setState (ArmState .INT );
95
+ }
96
+ }
83
97
84
98
@ Override
85
99
public void periodic () {
86
100
io .updateInputs (inputs );
87
101
Logger .processInputs ("DoubleJointedArm" , inputs );
88
-
89
102
Logger .recordOutput ("DoubleJointedArm/CurrentState" , state .name ());
90
- Logger .recordOutput ("DoubleJointedArm/ShoulderTarget" , state .getShoulderTargetAngle ().getDegrees ());
91
- Logger .recordOutput ("DoubleJointedArm/ElbowTarget" , state .getElbowTargetAngle ().getDegrees ());
92
- Logger .recordOutput ("DoubleJointedArm/AtTarget" , isArmAtTarget (state .getElbowTargetAngle (), state .getShoulderTargetAngle ()));
93
-
94
- // PUT ALL CALLS TO CONTROL METHODS HERE
95
- Matrix <N2 , N1 > positions = VecBuilder .fill (
96
- Math .toRadians (inputs .shoulderAngle ),
97
- Math .toRadians (inputs .elbowAngle )
98
- );
99
-
100
- Matrix <N2 , N1 > velocities = VecBuilder .fill (
101
- Math .toRadians (inputs .shoulderAngularVel ),
102
- Math .toRadians (inputs .elbowAngularVel )
103
- );
104
-
105
- Matrix <N2 , N1 > accelerations = VecBuilder .fill (
106
- Math .toRadians (inputs .shoulderAngularAccel ),
107
- Math .toRadians (inputs .elbowAngularAccel )
108
- );
103
+ Logger .recordOutput ("DoubleJointedArm/ShoulderTarget" , state .getShoulderTarget ().getDegrees ());
104
+ Logger .recordOutput ("DoubleJointedArm/ElbowTarget" , state .getElbowTarget ().getDegrees ());
105
+ Logger .recordOutput ("DoubleJointedArm/AtTarget" , isArmAtTarget (state .getElbowTarget (), state .getShoulderTarget ()));
106
+
107
+ double shoulderAngleRad = Math .toRadians (inputs .shoulderAngle );
108
+ double elbowRelativeRad = Math .toRadians (inputs .elbowAngle - inputs .shoulderAngle );
109
109
110
+ double shoulderVelRad = Math .toRadians (inputs .shoulderAngularVel );
111
+ double elbowRelativeVelRad = Math .toRadians (inputs .elbowAngularVel - inputs .shoulderAngularVel );
112
+
113
+ double shoulderAccelRad = Math .toRadians (inputs .shoulderAngularAccel );
114
+ double elbowRelativeAccelRad = Math .toRadians (inputs .elbowAngularAccel - inputs .shoulderAngularAccel );
115
+
116
+ Matrix <N2 , N1 > positions = VecBuilder .fill (shoulderAngleRad , elbowRelativeRad );
117
+ Matrix <N2 , N1 > velocities = VecBuilder .fill (shoulderVelRad , elbowRelativeVelRad );
118
+ Matrix <N2 , N1 > accelerations = VecBuilder .fill (shoulderAccelRad , elbowRelativeAccelRad );
119
+
110
120
Matrix <N2 , N1 > ff = feedforwardVoltage (positions , velocities , accelerations );
121
+
122
+ if (intermediate && atTarget ()) {
123
+ setState (storedState );
124
+ intermediate = false ;
125
+ }
111
126
112
- io .controlShoulder (state .getShoulderTargetAngle (), ff .get (0 , 0 ));
113
- io .controlElbow (state .getElbowTargetAngle (), ff .get (1 , 0 ));
127
+ io .controlShoulder (state .getShoulderTarget (), ff .get (0 , 0 ));
128
+ io .controlElbow (state .getElbowTarget (), ff .get (1 , 0 ));
114
129
}
115
130
116
131
/* GETTERS */
@@ -145,7 +160,7 @@ public Translation2d getEndPosition() { // Forward Kinematics
145
160
146
161
@ AutoLogOutput
147
162
public boolean atTarget () {
148
- return isArmAtTarget (state .getShoulderTargetAngle (), state .getElbowTargetAngle ());
163
+ return isArmAtTarget (state .getShoulderTarget (), state .getElbowTarget ());
149
164
}
150
165
151
166
@ AutoLogOutput
@@ -197,7 +212,7 @@ public boolean isArmAtTarget(Rotation2d shoulderTargetAngle, Rotation2d elbowTar
197
212
private final double ELBOW_GEAR_RATIO = Constants .DoubleJointedArm .Elbow .GEAR_RATIO ;
198
213
199
214
/*
200
- * @param position The angles of the joints, (θ1, θ2). Note that θ2 is relative to the first joint, not the horizontal.
215
+ * @param position The angles of the joints, (θ1, θ2). Note that θ2 is relative to the first joint, not the horizontal
201
216
* @param velocity The velocities of the joints in deg/s
202
217
* @param acceleration The accelerations of the joints in deg/s^2
203
218
*/
0 commit comments