5
5
# the WPILib BSD license file in the root directory of this project.
6
6
#
7
7
8
- from typing import Any , Callable , Union
9
-
10
- from .command import Command
11
- from .subsystem import Subsystem
8
+ from typing import Any , Callable , Generic , Union
12
9
13
10
from wpimath .controller import ProfiledPIDController , ProfiledPIDControllerRadians
14
11
from wpimath .trajectory import TrapezoidProfile , TrapezoidProfileRadians
15
12
13
+ from .command import Command
14
+ from .subsystem import Subsystem
15
+ from .typing import TProfiledPIDController , UseOutputFunction
16
+
16
17
17
- class ProfiledPIDCommand (Command ):
18
+ class ProfiledPIDCommand (Command , Generic [ TProfiledPIDController ] ):
18
19
"""A command that controls an output with a :class:`.ProfiledPIDController`. Runs forever by default -
19
20
to add exit conditions and/or other behavior, subclass this class. The controller calculation and
20
21
output are performed synchronously in the command's execute() method.
@@ -24,10 +25,10 @@ class ProfiledPIDCommand(Command):
24
25
25
26
def __init__ (
26
27
self ,
27
- controller ,
28
+ controller : TProfiledPIDController ,
28
29
measurementSource : Callable [[], float ],
29
30
goalSource : Union [float , Callable [[], float ]],
30
- useOutput : Callable [[ float , Any ], Any ] ,
31
+ useOutput : UseOutputFunction ,
31
32
* requirements : Subsystem ,
32
33
):
33
34
"""Creates a new ProfiledPIDCommand, which controls the given output with a ProfiledPIDController. Goal
@@ -40,14 +41,15 @@ def __init__(
40
41
:param requirements: the subsystems required by this command
41
42
"""
42
43
44
+ super ().__init__ ()
43
45
if isinstance (controller , ProfiledPIDController ):
44
46
self ._stateCls = TrapezoidProfile .State
45
47
elif isinstance (controller , ProfiledPIDControllerRadians ):
46
48
self ._stateCls = TrapezoidProfileRadians .State
47
49
else :
48
50
raise ValueError (f"unknown controller type { controller !r} " )
49
51
50
- self ._controller = controller
52
+ self ._controller : TProfiledPIDController = controller
51
53
self ._useOutput = useOutput
52
54
self ._measurement = measurementSource
53
55
if isinstance (goalSource , (float , int )):
0 commit comments