Skip to content

Commit 74a72fb

Browse files
committed
Added docstring to ProfiledPIDSubsystem. Add profiledpidsubsysem to __all__. Removed '_m' prefix from a couple of variables. Renamed get_controller() to getController() for consistency. Fixed mypy issue / bug. Reformatted file with Black.
1 parent 965564f commit 74a72fb

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

commands2/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"PIDCommand",
7171
"PIDSubsystem",
7272
"PrintCommand",
73+
"ProfiledPIDSubsystem",
7374
"ProxyCommand",
7475
"ProxyScheduleCommand",
7576
"RepeatCommand",

commands2/profiledpidsubsystem.py

+22-14
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,38 @@
88

99

1010
class ProfiledPIDSubsystem(Subsystem):
11+
"""
12+
A subsystem that uses a ProfiledPIDController to control an output. The controller
13+
is run synchronously from the subsystem's periodic() method.
14+
"""
15+
1116
def __init__(self, controller: ProfiledPIDController, initial_position: float = 0):
17+
"""Creates a new PIDSubsystem."""
1218
super().__init__()
13-
self._m_controller = controller
14-
self._m_enabled = False
19+
self._controller = controller
20+
self._enabled = False
1521
self.setGoal(initial_position)
1622

1723
def periodic(self):
1824
"""Updates the output of the controller."""
19-
if self._m_enabled:
20-
self._useOutput(self._m_controller.calculate(self._getMeasurement()),
21-
self._m_controller.getSetpoint())
25+
if self._enabled:
26+
self._useOutput(
27+
self._controller.calculate(self._getMeasurement()),
28+
self._controller.getSetpoint(),
29+
)
2230

23-
def get_controller(self) -> ProfiledPIDController:
31+
def getController(self) -> ProfiledPIDController:
2432
"""Returns the ProfiledPIDController."""
25-
return self._m_controller
33+
return self._controller
2634

2735
def setGoal(self, goal: TrapezoidProfile.State | float):
2836
"""
2937
Sets the goal state for the subsystem.
3038
"""
31-
if isinstance(goal, TrapezoidProfile):
32-
self._m_controller.setGoal(goal)
39+
if isinstance(goal, TrapezoidProfile.State):
40+
self._controller.setGoal(goal)
3341
else:
34-
self._m_controller.setGoal(TrapezoidProfile.State(goal, 0))
42+
self._controller.setGoal(TrapezoidProfile.State(goal, 0))
3543

3644
def _useOutput(self, output: float, setpoint: TrapezoidProfile.State):
3745
"""
@@ -47,16 +55,16 @@ def _getMeasurement(self) -> float:
4755

4856
def enable(self):
4957
"""Enables the PID control. Resets the controller."""
50-
self._m_enabled = True
51-
self._m_controller.reset(self._getMeasurement())
58+
self._enabled = True
59+
self._controller.reset(self._getMeasurement())
5260

5361
def disable(self):
5462
"""Disables the PID control. Sets output to zero."""
55-
self._m_enabled = False
63+
self._enabled = False
5664
self._useOutput(0, TrapezoidProfile.State())
5765

5866
def isEnabled(self) -> bool:
5967
"""
6068
Returns whether the controller is enabled.
6169
"""
62-
return self._m_enabled
70+
return self._enabled

0 commit comments

Comments
 (0)