Skip to content

Commit 0cfa3b4

Browse files
cwstrykervirtuald
authored andcommitted
Created a generatic profiled PID controller var type and applied it to the profiled PID subsystem.
1 parent 710f4b7 commit 0cfa3b4

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

commands2/profiledpidsubsystem.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
# Open Source Software; you can modify and/or share it under the terms of
33
# the WPILib BSD license file in the root directory of this project.
44

5-
from typing import Union, cast
5+
from typing import Generic
66

77
from wpimath.trajectory import TrapezoidProfile
88

99
from .subsystem import Subsystem
10+
from .typing import GenericProfiledPIDController
1011

1112

12-
class ProfiledPIDSubsystem(Subsystem):
13+
class ProfiledPIDSubsystem(Subsystem, Generic[GenericProfiledPIDController]):
1314
"""
1415
A subsystem that uses a :class:`wpimath.controller.ProfiledPIDController`
1516
or :class:`wpimath.controller.ProfiledPIDControllerRadians` to
@@ -19,12 +20,12 @@ class ProfiledPIDSubsystem(Subsystem):
1920

2021
def __init__(
2122
self,
22-
controller,
23+
controller: GenericProfiledPIDController,
2324
initial_position: float = 0,
2425
):
2526
"""Creates a new PIDSubsystem."""
2627
super().__init__()
27-
self._controller = controller
28+
self._controller: GenericProfiledPIDController = controller
2829
self._enabled = False
2930
self.setGoal(initial_position)
3031

@@ -38,7 +39,7 @@ def periodic(self):
3839

3940
def getController(
4041
self,
41-
):
42+
) -> GenericProfiledPIDController:
4243
"""Returns the controller"""
4344
return self._controller
4445

commands2/typing.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from typing import TypeVar
2+
3+
from wpimath.controller import ProfiledPIDController, ProfiledPIDControllerRadians
4+
5+
GenericProfiledPIDController = TypeVar(
6+
"GenericProfiledPIDController", ProfiledPIDControllerRadians, ProfiledPIDController
7+
)

0 commit comments

Comments
 (0)