Skip to content

Commit 4f57ad9

Browse files
authored
Merge pull request #242 from thedropbears/globalise_auto_controllers
2 parents 0cc7086 + 1e59c7f commit 4f57ad9

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

autonomous/auto_base.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import math
22

33
import choreo
4+
import wpilib
45
from choreo.trajectory import SwerveSample
56
from magicbot import AutonomousStateMachine, state
67
from wpilib import RobotBase
@@ -16,6 +17,15 @@
1617
from controllers.reef_intake import ReefIntake
1718
from 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

2030
class 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

Comments
 (0)