11import math
22
33import choreo
4+ import wpilib
45from choreo .trajectory import SwerveSample
56from magicbot import AutonomousStateMachine , state
67from wpilib import RobotBase
1617from controllers .reef_intake import ReefIntake
1718from utilities import game
1819
20+ x_controller = PIDController (1.0 , 0.0 , 0.0 )
21+ y_controller = PIDController (1.0 , 0.0 , 0.0 )
22+ heading_controller = PIDController (1.0 , 0 , 0 )
23+ heading_controller .enableContinuousInput (- math .pi , math .pi )
24+
25+ wpilib .SmartDashboard .putData ("Auto X PID" , x_controller )
26+ wpilib .SmartDashboard .putData ("Auto Y PID" , y_controller )
27+ wpilib .SmartDashboard .putData ("Auto Heading PID" , heading_controller )
28+
1929
2030class AutoBase (AutonomousStateMachine ):
2131 algae_shooter : AlgaeShooter
@@ -32,10 +42,6 @@ class AutoBase(AutonomousStateMachine):
3242 def __init__ (self , trajectory_names : list [str ]) -> None :
3343 # We want to parameterise these by paths and potentially a sequence of events
3444 super ().__init__ ()
35- self .x_controller = PIDController (1.0 , 0.0 , 0.0 )
36- self .y_controller = PIDController (1.0 , 0.0 , 0.0 )
37- self .heading_controller = PIDController (1.0 , 0 , 0 )
38- self .heading_controller .enableContinuousInput (- math .pi , math .pi )
3945
4046 self .current_leg = - 1
4147 self .starting_pose = None
@@ -120,12 +126,10 @@ def follow_trajectory(self, sample: SwerveSample):
120126
121127 # Generate the next speeds for the robot
122128 speeds = ChassisSpeeds (
123- sample .vx + self . x_controller .calculate (pose .X (), sample .x ),
124- sample .vy + self . y_controller .calculate (pose .Y (), sample .y ),
129+ sample .vx + x_controller .calculate (pose .X (), sample .x ),
130+ sample .vy + y_controller .calculate (pose .Y (), sample .y ),
125131 sample .omega
126- + self .heading_controller .calculate (
127- pose .rotation ().radians (), sample .heading
128- ),
132+ + heading_controller .calculate (pose .rotation ().radians (), sample .heading ),
129133 )
130134
131135 # Apply the generated speeds
0 commit comments