2121
2222
2323class WristComponent :
24- ENCODER_ZERO_OFFSET = 4.011863
25- MAXIMUM_DEPRESSION = math .radians (- 112.0 )
26- MAXIMUM_ELEVATION = math .radians (0 )
24+ ENCODER_ZERO_OFFSET = 3.46463832679
25+ COM_DIFFERENCE = 0.54722467321
26+ MAXIMUM_DEPRESSION = math .radians (- 112.0 ) + COM_DIFFERENCE
27+ MAXIMUM_ELEVATION = math .radians (0 ) + COM_DIFFERENCE
2728 NEUTRAL_ANGLE = math .radians (- 90.0 )
2829
2930 WRIST_MAX_VEL = math .radians (180.0 )
@@ -37,6 +38,10 @@ def __init__(self, mech_root: wpilib.MechanismRoot2d):
3738 "wrist" , length = 0.5 , angle = 0 , color = wpilib .Color8Bit (wpilib .Color .kYellow )
3839 )
3940
41+ self .wrist_COM_ligament = mech_root .appendLigament (
42+ "wrist_COM" , length = 0.5 , angle = 0 , color = wpilib .Color8Bit (wpilib .Color .kBlue )
43+ )
44+
4045 self .wrist_encoder = DutyCycleEncoder (DioChannel .WRIST_ENCODER , math .tau , 0 )
4146 configure_through_bore_encoder (self .wrist_encoder )
4247 self .wrist_encoder .setInverted (False )
@@ -117,6 +122,10 @@ def inclination(self) -> float:
117122 def inclination_deg (self ) -> float :
118123 return math .degrees (self .inclination ())
119124
125+ @feedback
126+ def shooter_FOR_inclination_deg (self ) -> float :
127+ return math .degrees (self .inclination () - self .COM_DIFFERENCE )
128+
120129 @feedback
121130 def shoot_angle_deg (self ) -> float :
122131 return self .inclination_deg () + 90
@@ -134,6 +143,13 @@ def at_setpoint(self) -> bool:
134143 self .desired_state .velocity - self .current_velocity ()
135144 ) < WristComponent .VEL_TOLERANCE
136145
146+ # Tilts to an angle with regards to the shooter frame of reference.
147+ # Shooter FOR takes the arm as in-line with the backplate of the shooter
148+ # Should be called with angles in the shooter FOR
149+ def tilt_to_shooter_FOR (self , pos : float ) -> None :
150+ self .tilt_to (pos + self .COM_DIFFERENCE )
151+
152+ # Tilts to an angle with respect to the COM FOR
137153 def tilt_to (self , pos : float ) -> None :
138154 clamped_angle = clamp (pos , self .MAXIMUM_DEPRESSION , self .MAXIMUM_ELEVATION )
139155
@@ -151,7 +167,7 @@ def _tilt_to(self, pos: float):
151167 )
152168
153169 def go_to_neutral (self ) -> None :
154- self .tilt_to (WristComponent .NEUTRAL_ANGLE )
170+ self .tilt_to_shooter_FOR (WristComponent .NEUTRAL_ANGLE )
155171
156172 @feedback
157173 def at_limit (self ) -> bool :
@@ -169,5 +185,7 @@ def execute(self) -> None:
169185 self .pid .calculate (self .inclination (), tracked_state .position ) + ff
170186 )
171187
172- self .wrist_ligament .setAngle (self .inclination_deg ())
188+ self .wrist_ligament .setAngle (self .shooter_FOR_inclination_deg ())
189+
190+ self .wrist_COM_ligament .setAngle (self .inclination_deg ())
173191 # self.wrist_ligament.setAngle(math.degrees(desired_state.position))
0 commit comments