Skip to content

Commit 3182cf8

Browse files
james-wardDannyPomeranian
authored andcommitted
Use pure PID controller for heading lock
1 parent a2b01e0 commit 3182cf8

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

components/chassis.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from phoenix6.hardware import CANcoder, Pigeon2, TalonFX
1717
from phoenix6.signals import InvertedValue, NeutralModeValue
1818
from wpimath.controller import (
19-
ProfiledPIDControllerRadians,
19+
PIDController,
2020
SimpleMotorFeedforwardMeters,
2121
)
2222
from wpimath.estimator import SwerveDrive4PoseEstimator
@@ -27,7 +27,6 @@
2727
SwerveModulePosition,
2828
SwerveModuleState,
2929
)
30-
from wpimath.trajectory import TrapezoidProfileRadians
3130

3231
from ids import CancoderId, TalonId
3332
from utilities.ctre import FALCON_FREE_RPS
@@ -251,9 +250,7 @@ def __init__(
251250
self, track_width: float, wheel_base: float, swerve_config: SwerveConfig
252251
) -> None:
253252
self.imu = Pigeon2(0)
254-
self.heading_controller = ProfiledPIDControllerRadians(
255-
3, 0, 0, TrapezoidProfileRadians.Constraints(100, 100)
256-
)
253+
self.heading_controller = PIDController(3.0, 0.0, 0.0)
257254
self.heading_controller.enableContinuousInput(-math.pi, math.pi)
258255
self.snapping_to_heading = False
259256
self.heading_controller.setTolerance(self.HEADING_TOLERANCE)
@@ -384,7 +381,7 @@ def drive_local(self, vx: float, vy: float, omega: float) -> None:
384381
def snap_to_heading(self, heading: float) -> None:
385382
"""set a heading target for the heading controller"""
386383
self.snapping_to_heading = True
387-
self.heading_controller.setGoal(heading)
384+
self.heading_controller.setSetpoint(heading)
388385

389386
def stop_snapping(self) -> None:
390387
"""stops the heading_controller"""
@@ -399,9 +396,7 @@ def execute(self) -> None:
399396
self.get_rotation().radians()
400397
)
401398
else:
402-
self.heading_controller.reset(
403-
self.get_rotation().radians(), self.get_rotational_velocity()
404-
)
399+
self.heading_controller.reset()
405400

406401
desired_speed_translation = Translation2d(
407402
self.chassis_speeds.vx, self.chassis_speeds.vy
@@ -529,7 +524,7 @@ def get_rotation(self) -> Rotation2d:
529524

530525
@feedback
531526
def at_desired_heading(self) -> bool:
532-
return self.heading_controller.atGoal()
527+
return abs(self.heading_controller.getError()) <= self.HEADING_TOLERANCE
533528

534529
def set_coast_in_neutral(self, coast_mode: bool = True) -> None:
535530
mode = NeutralModeValue.COAST if coast_mode else NeutralModeValue.BRAKE

0 commit comments

Comments
 (0)