22
33from magicbot import feedback , tunable
44from rev import LimitSwitchConfig , SparkMax , SparkMaxConfig
5- from wpilib import DigitalInput , DutyCycleEncoder
5+ from wpilib import DigitalInput
66from wpimath .controller import PIDController
77
88from components .led_component import LightStrip
99from ids import DioChannel , SparkId
1010from utilities .functions import constrain_angle
11- from utilities .rev import configure_through_bore_encoder
1211
1312
1413class ClimberComponent :
@@ -18,6 +17,7 @@ class ClimberComponent:
1817 winch_voltage = tunable (12.0 )
1918
2019 def __init__ (self ) -> None :
20+ self .OFFSET = 5.4 / math .tau
2121 self .START_ANGLE = - 30.0
2222 self .DEPLOY_ANGLE = 16.0
2323 self .RETRACT_ANGLE = - 52.0
@@ -28,17 +28,20 @@ def __init__(self) -> None:
2828 self .desired_angle = math .radians (self .START_ANGLE )
2929 self .update_pid = True
3030
31- self .encoder = DutyCycleEncoder (DioChannel .CLIMBER_ENCODER , math .tau , 5.4 )
32- configure_through_bore_encoder (self .encoder )
33- self .encoder .setInverted (False )
34-
3531 self .pid = PIDController (Kp = 40 , Ki = 0 , Kd = 0 )
3632 self .pid .enableContinuousInput (0.0 , math .tau )
3733
3834 self .motor = SparkMax (SparkId .CLIMBER , SparkMax .MotorType .kBrushless )
35+ self .encoder = self .motor .getAbsoluteEncoder ()
36+
3937 motor_config = SparkMaxConfig ()
4038 motor_config .inverted (True )
4139 motor_config .setIdleMode (SparkMaxConfig .IdleMode .kBrake )
40+ motor_config .absoluteEncoder .setSparkMaxDataPortConfig ()
41+ motor_config .absoluteEncoder .positionConversionFactor (math .tau )
42+ motor_config .absoluteEncoder .velocityConversionFactor (math .tau * 1 / 60 )
43+ motor_config .absoluteEncoder .inverted (False )
44+ motor_config .absoluteEncoder .zeroOffset (self .OFFSET )
4245
4346 motor_config .limitSwitch .reverseLimitSwitchType (
4447 LimitSwitchConfig .Type .kNormallyOpen
@@ -86,11 +89,11 @@ def go_to_retract(self) -> None:
8689
8790 @feedback
8891 def raw_encoder_val (self ) -> float :
89- return self .encoder .get ()
92+ return self .encoder .getPosition ()
9093
9194 @feedback
9295 def encoder_angle (self ) -> float :
93- return math .degrees (constrain_angle (self .encoder .get ()))
96+ return math .degrees (constrain_angle (self .encoder .getPosition ()))
9497
9598 @feedback
9699 def is_deployed (self ) -> bool :
0 commit comments