1616from phoenix6 .hardware import CANcoder , Pigeon2 , TalonFX
1717from phoenix6 .signals import InvertedValue , NeutralModeValue
1818from wpimath .controller import (
19- ProfiledPIDControllerRadians ,
19+ PIDController ,
2020 SimpleMotorFeedforwardMeters ,
2121)
2222from wpimath .estimator import SwerveDrive4PoseEstimator
2727 SwerveModulePosition ,
2828 SwerveModuleState ,
2929)
30- from wpimath .trajectory import TrapezoidProfileRadians
3130
3231from ids import CancoderId , TalonId
3332from utilities .ctre import FALCON_FREE_RPS
@@ -246,13 +245,13 @@ class ChassisComponent:
246245 swerve_lock = magicbot .tunable (False )
247246
248247 # TODO: Read from positions.py once autonomous is finished
249-
250248 def __init__ (
251249 self , track_width : float , wheel_base : float , swerve_config : SwerveConfig
252250 ) -> None :
253251 self .imu = Pigeon2 (0 )
254- self .heading_controller = ProfiledPIDControllerRadians (
255- 3 , 0 , 0 , TrapezoidProfileRadians .Constraints (100 , 100 )
252+ self .heading_controller = PIDController (3.0 , 0.0 , 0.0 )
253+ wpilib .SmartDashboard .putData (
254+ "Chassis heading_controller" , self .heading_controller
256255 )
257256 self .heading_controller .enableContinuousInput (- math .pi , math .pi )
258257 self .snapping_to_heading = False
@@ -384,7 +383,7 @@ def drive_local(self, vx: float, vy: float, omega: float) -> None:
384383 def snap_to_heading (self , heading : float ) -> None :
385384 """set a heading target for the heading controller"""
386385 self .snapping_to_heading = True
387- self .heading_controller .setGoal (heading )
386+ self .heading_controller .setSetpoint (heading )
388387
389388 def stop_snapping (self ) -> None :
390389 """stops the heading_controller"""
@@ -399,9 +398,7 @@ def execute(self) -> None:
399398 self .get_rotation ().radians ()
400399 )
401400 else :
402- self .heading_controller .reset (
403- self .get_rotation ().radians (), self .get_rotational_velocity ()
404- )
401+ self .heading_controller .reset ()
405402
406403 desired_speed_translation = Translation2d (
407404 self .chassis_speeds .vx , self .chassis_speeds .vy
@@ -529,7 +526,7 @@ def get_rotation(self) -> Rotation2d:
529526
530527 @feedback
531528 def at_desired_heading (self ) -> bool :
532- return self .heading_controller .atGoal ()
529+ return abs ( self .heading_controller .getError ()) <= self . HEADING_TOLERANCE
533530
534531 def set_coast_in_neutral (self , coast_mode : bool = True ) -> None :
535532 mode = NeutralModeValue .COAST if coast_mode else NeutralModeValue .BRAKE
0 commit comments