File tree Expand file tree Collapse file tree 3 files changed +22
-4
lines changed Expand file tree Collapse file tree 3 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 1313from wpimath .trajectory import TrapezoidProfile
1414
1515from ids import DioChannel , SparkId , TalonId
16+ from utilities .rev import configure_through_bore_encoder
1617
1718
1819class IntakeComponent :
@@ -38,8 +39,7 @@ def __init__(self, intake_mech_root: wpilib.MechanismRoot2d) -> None:
3839
3940 self .arm_motor = SparkMax (SparkId .INTAKE_ARM , SparkMax .MotorType .kBrushless )
4041 self .encoder = DutyCycleEncoder (DioChannel .INTAKE_ENCODER , math .tau , 0 )
41- self .encoder .setAssumedFrequency (975.6 )
42- self .encoder .setDutyCycleRange (1 / 1025 , 1024 / 1025 )
42+ configure_through_bore_encoder (self .encoder )
4343 self .encoder .setInverted (True )
4444
4545 spark_config = SparkMaxConfig ()
Original file line number Diff line number Diff line change 2323from components .chassis import ChassisComponent
2424from utilities .caching import HasPerLoopCache , cache_per_loop
2525from utilities .game import APRILTAGS , apriltag_layout
26+ from utilities .rev import configure_through_bore_encoder
2627from utilities .scalers import scale_value
2728
2829
@@ -88,8 +89,7 @@ def __init__(
8889 super ().__init__ ()
8990 self .camera = PhotonCamera (name )
9091 self .encoder = wpilib .DutyCycleEncoder (encoder_id , math .tau , 0 )
91- self .encoder .setAssumedFrequency (975.6 )
92- self .encoder .setDutyCycleRange (1 / 1025 , 1024 / 1025 )
92+ configure_through_bore_encoder (self .encoder )
9393 # Offset of encoder in radians when facing forwards (the desired zero)
9494 # To find this value, manually point the camera forwards and record the encoder value
9595 # This has nothing to do with the servo - do it by hand!!
Original file line number Diff line number Diff line change 11import rev
2+ import wpilib
23
34
45def configure_spark_ephemeral (motor : rev .SparkBase , config : rev .SparkBaseConfig ):
@@ -17,3 +18,20 @@ def configure_spark_reset_and_persist(
1718 rev .SparkBase .ResetMode .kResetSafeParameters ,
1819 rev .SparkBase .PersistMode .kPersistParameters ,
1920 )
21+
22+
23+ def configure_through_bore_encoder (
24+ enc : wpilib .DutyCycleEncoder , freq : float = 975.6
25+ ) -> None :
26+ """Configure a REV Through Bore Encoder absolute pulse output.
27+
28+ This avoids the roboRIO duty cycle frequency computation, which will
29+ be inaccurate at startup.
30+
31+ Args:
32+ enc: The DutyCycleEncoder to configure.
33+ freq: The assumed frequency of the encoder in Hz. Defaults to
34+ the encoder's nominal frequency per the datasheet.
35+ """
36+ enc .setAssumedFrequency (freq )
37+ enc .setDutyCycleRange (1 / 1025 , 1024 / 1025 )
You can’t perform that action at this time.
0 commit comments