Skip to content

Commit c55c89c

Browse files
committed
Rewrite PID article
1 parent f6a014c commit c55c89c

File tree

3 files changed

+8
-186
lines changed

3 files changed

+8
-186
lines changed

.github/workflows/inspector.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@
2626
"latestVersion":"6a5b6352807a8759bd0f012e57695c47f7ef7324"
2727
}
2828
],
29-
"ignoredFiles": ["source/docs/software/commandbased/command-scheduler.rst", "source/docs/software/hardware-apis/pneumatics/pressure.rst", "source/docs/software/hardware-apis/pneumatics/solenoids.rst", "source/docs/software/advanced-controls/state-space/state-space-pose-estimators.rst", "source/docs/software/commandbased/pid-subsystems-commands.rst", "source/docs/software/commandbased/profilepid-subsystems-commands.rst", "source/docs/software/commandbased/subsystems.rst", "source/docs/software/telemetry/writing-sendable-classes.rst", "source/docs/software/advanced-controls/trajectories/troubleshooting.rst", "source/docs/software/hardware-apis/motors/wpi-drive-classes.rst", "source/docs/software/pathplanning/trajectory-tutorial/creating-drive-subsystem.rst", "source/docs/software/pathplanning/trajectory-tutorial/creating-following-trajectory.rst", "source/docs/software/pathplanning/trajectory-tutorial/entering-constants.rst"]
29+
"ignoredFiles": ["source/docs/software/commandbased/command-scheduler.rst", "source/docs/software/hardware-apis/pneumatics/pressure.rst", "source/docs/software/hardware-apis/pneumatics/solenoids.rst", "source/docs/software/advanced-controls/state-space/state-space-pose-estimators.rst", "source/docs/software/commandbased/profilepid-subsystems-commands.rst", "source/docs/software/commandbased/subsystems.rst", "source/docs/software/telemetry/writing-sendable-classes.rst", "source/docs/software/advanced-controls/trajectories/troubleshooting.rst", "source/docs/software/hardware-apis/motors/wpi-drive-classes.rst", "source/docs/software/pathplanning/trajectory-tutorial/creating-drive-subsystem.rst", "source/docs/software/pathplanning/trajectory-tutorial/creating-following-trajectory.rst", "source/docs/software/pathplanning/trajectory-tutorial/entering-constants.rst"]
3030
}
Lines changed: 6 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,18 @@
11
.. include:: <isonum.txt>
22

3-
PID Control through PIDCommands
3+
PID Control in Command-based
44
=================================================
55

66
.. note:: For a description of the WPILib PID control features used by these command-based wrappers, see :ref:`docs/software/advanced-controls/controllers/pidcontroller:PID Control in WPILib`.
77

8-
One of the most common control algorithms used in FRC\ |reg| is the :term:`PID` controller. WPILib offers its own :ref:`PIDController <docs/software/advanced-controls/controllers/pidcontroller:PID Control in WPILib>` class to help teams implement this functionality on their robots. To further help teams integrate PID control into a command-based robot project, the command-based library includes a convenience wrapper for the ``PIDController`` class: ``PIDCommand``, which integrates the PID controller into a command.
9-
10-
PIDCommand
11-
----------
12-
13-
The ``PIDCommand`` class allows users to easily create commands with a built-in PIDController.
14-
15-
Creating a PIDCommand
16-
^^^^^^^^^^^^^^^^^^^^^
17-
18-
A ``PIDCommand`` can be created two ways - by subclassing the ``PIDCommand`` class, or by defining the command :ref:`inline <docs/software/commandbased/organizing-command-based:Inline Commands>`. Both methods ultimately extremely similar, and ultimately the choice of which to use comes down to where the user desires that the relevant code be located.
19-
20-
.. note:: If subclassing ``PIDCommand`` and overriding any methods, make sure to call the ``super`` version of those methods! Otherwise, PID functionality will not work properly.
21-
22-
In either case, a ``PIDCommand`` is created by passing the necessary parameters to its constructor (if defining a subclass, this can be done with a `super()` call):
23-
24-
.. tab-set::
25-
26-
.. tab-item:: Java
27-
:sync: Java
28-
29-
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2024.1.1-beta-4/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/PIDCommand.java
30-
:language: java
31-
:lines: 27-41
32-
:linenos:
33-
:lineno-start: 27
34-
35-
.. tab-item:: C++
36-
:sync: C++
37-
38-
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2024.1.1/wpilibNewCommands/src/main/native/include/frc2/command/PIDCommand.h
39-
:language: c++
40-
:lines: 28-42
41-
:linenos:
42-
:lineno-start: 28
43-
44-
controller
45-
~~~~~~~~~~
46-
47-
The ``controller`` parameter is the ``PIDController`` object that will be used by the command. By passing this in, users can specify the PID gains and the period for the controller (if the user is using a nonstandard main robot loop period).
48-
49-
When subclassing ``PIDCommand``, additional modifications (e.g. enabling continuous input) can be made to the controller in the constructor body by calling ``getController()``.
50-
51-
measurementSource
52-
~~~~~~~~~~~~~~~~~
53-
54-
The ``measurementSource`` parameter is a function (usually passed as a :ref:`lambda <docs/software/commandbased/index:Lambda Expressions (Java)>`) that returns the measurement of the process variable.
55-
56-
When subclassing ``PIDCommand``, advanced users may further modify the measurement supplier by modifying the class's ``m_measurement`` field.
57-
58-
setpointSource
59-
~~~~~~~~~~~~~~
60-
61-
The ``setpointSource`` parameter is a function (usually passed as a :ref:`lambda <docs/software/commandbased/index:Lambda Expressions (Java)>`) that returns the current setpoint for the control loop. If only a constant setpoint is needed, an overload exists that takes a constant setpoint rather than a supplier.
62-
63-
When subclassing ``PIDCommand``, advanced users may further modify the setpoint supplier by modifying the class's ``m_setpoint`` field.
64-
65-
useOutput
66-
~~~~~~~~~
67-
68-
The ``useOutput`` parameter is a function (usually passed as a :ref:`lambda <docs/software/commandbased/index:Lambda Expressions (Java)>`) that consumes the output and setpoint of the control loop.
69-
70-
When subclassing ``PIDCommand``, advanced users may further modify the output consumer by modifying the class's ``m_useOutput`` field.
71-
72-
requirements
73-
~~~~~~~~~~~~
74-
75-
Like all inlineable commands, ``PIDCommand`` allows the user to specify its subsystem requirements as a constructor parameter.
76-
77-
Full PIDCommand Example
78-
^^^^^^^^^^^^^^^^^^^^^^^
79-
80-
What does a ``PIDCommand`` look like when used in practice? The following examples are from the GyroDriveCommands example project (`Java <https://github.com/wpilibsuite/allwpilib/tree/main/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyrodrivecommands>`__, `C++ <https://github.com/wpilibsuite/allwpilib/tree/main/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands>`__):
8+
One of the most common control algorithms used in FRC\ |reg| is the :term:`PID` controller. WPILib offers its own :ref:`PIDController <docs/software/advanced-controls/controllers/pidcontroller:PID Control in WPILib>` class to help teams implement this functionality on their robots. The following example is from the RapidReactCommandBot example project (`Java <https://github.com/wpilibsuite/allwpilib/tree/main/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot>`__, `C++ <https://github.com/wpilibsuite/allwpilib/tree/main/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot>`__) and shows how PIDControllers can be used within the command-based framework:
819

8210
.. tab-set::
8311

8412
.. tab-item:: Java
8513
:sync: Java
8614

87-
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2024.1.1/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyrodrivecommands/commands/TurnToAngle.java
15+
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2024.3.2/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/subsystems/Shooter.java
8816
:language: java
8917
:lines: 5-
9018
:linenos:
@@ -93,7 +21,7 @@ What does a ``PIDCommand`` look like when used in practice? The following exampl
9321
.. tab-item:: C++
9422
:sync: C++ (Header)
9523

96-
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2024.1.1/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/commands/TurnToAngle.h
24+
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2024.3.2/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Shooter.h
9725
:language: c++
9826
:lines: 5-
9927
:linenos:
@@ -102,30 +30,10 @@ What does a ``PIDCommand`` look like when used in practice? The following exampl
10230
.. tab-item:: C++ (Source)
10331
:sync: C++ (Source)
10432

105-
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2024.1.1/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/commands/TurnToAngle.cpp
33+
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2024.3.2/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Shooter.cpp
10634
:language: c++
10735
:lines: 5-
10836
:linenos:
10937
:lineno-start: 5
11038

111-
And, for an :ref:`inlined <docs/software/commandbased/organizing-command-based:Inline Commands>` example:
112-
113-
.. tab-set::
114-
115-
.. tab-item:: Java
116-
:sync: Java
117-
118-
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2024.1.1/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyrodrivecommands/RobotContainer.java
119-
:language: java
120-
:lines: 64-79
121-
:linenos:
122-
:lineno-start: 64
123-
124-
.. tab-item:: C++
125-
:sync: C++
126-
127-
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2024.1.1/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/RobotContainer.cpp
128-
:language: c++
129-
:lines: 34-49
130-
:linenos:
131-
:lineno-start: 34
39+
A ``PIDController`` is declared inside the ``Shooter`` subsystem. It is used by ``ShootCommand`` alongside a feedforward to spin the shooter flywheel to the specified velocity. Once the ``PIDController`` reaches the specified velocity, the ``ShootCommand`` runs the feeder.

source/docs/software/commandbased/profile-subsystems-commands.rst

Lines changed: 1 addition & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -7,73 +7,9 @@ Motion Profiling through TrapezoidProfileCommands
77

88
When controlling a mechanism, is often desirable to move it smoothly between two positions, rather than to abruptly change its setpoint. This is called "motion-profiling," and is supported in WPILib through the ``TrapezoidProfile`` class (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/math/trajectory/TrapezoidProfile.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classfrc_1_1_trapezoid_profile.html>`__).
99

10-
To further help teams integrate motion profiling into their command-based robot projects, WPILib includes a convenience wrapper for the ``TrapezoidProfile`` class: ``TrapezoidProfileCommand``, which executes a single user-provided ``TrapezoidProfile``.
11-
12-
TrapezoidProfileCommand
13-
-----------------------
14-
1510
.. note:: In C++, the ``TrapezoidProfileCommand`` class is templated on the unit type used for distance measurements, which may be angular or linear. The passed-in values *must* have units consistent with the distance units, or a compile-time error will be thrown. For more information on C++ units, see :ref:`docs/software/basic-programming/cpp-units:The C++ Units Library`.
1611

17-
The ``TrapezoidProfileCommand`` class (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/wpilibj2/command/TrapezoidProfileCommand.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classfrc2_1_1_trapezoid_profile_command.html>`__) allows users to create a command that will execute a single ``TrapezoidProfile``, passing its current state at each iteration to a user-defined function.
18-
19-
Creating a TrapezoidProfileCommand
20-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21-
22-
A ``TrapezoidProfileCommand`` can be created two ways - by subclassing the ``TrapezoidProfileCommand`` class, or by defining the command :ref:`inline <docs/software/commandbased/organizing-command-based:Inline Commands>`. Both methods are ultimately extremely similar, and ultimately the choice of which to use comes down to where the user desires that the relevant code be located.
23-
24-
.. note:: If subclassing ``TrapezoidProfileCommand`` and overriding any methods, make sure to call the ``super`` version of those methods! Otherwise, motion profiling functionality will not work properly.
25-
26-
In either case, a ``TrapezoidProfileCommand`` is created by passing the necessary parameters to its constructor (if defining a subclass, this can be done with a `super()` call):
27-
28-
.. tab-set::
29-
30-
.. tab-item:: Java
31-
:sync: Java
32-
33-
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/main/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/TrapezoidProfileCommand.java
34-
:language: java
35-
:lines: 28-43
36-
:linenos:
37-
:lineno-start: 28
38-
39-
.. tab-item:: C++
40-
:sync: C++
41-
42-
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/main/wpilibNewCommands/src/main/native/include/frc2/command/TrapezoidProfileCommand.h
43-
:language: c++
44-
:lines: 35-49
45-
:linenos:
46-
:lineno-start: 35
47-
48-
profile
49-
~~~~~~~
50-
51-
The ``profile`` parameter is the ``TrapezoidProfile`` object that will be executed by the command. By passing this in, users specify the motion constraints of the profile that the command will use.
52-
53-
output
54-
~~~~~~
55-
56-
The ``output`` parameter is a function (usually passed as a :ref:`lambda <docs/software/commandbased/index:Lambda Expressions (Java)>`) that consumes the output and setpoint of the control loop.
57-
58-
goal
59-
~~~~
60-
61-
The ``goal`` parameter is a function that supplies the desired state of the motion profile. This can be used to change the goal at runtime if desired.
62-
63-
currentState
64-
~~~~~~~~~~~~
65-
66-
The ``currentState`` parameter is a function that supplies the starting state of the motion profile. Combined with ``goal``, this can be used to dynamically generate and follow any motion profile at runtime.
67-
68-
requirements
69-
~~~~~~~~~~~~
70-
71-
Like all inlineable commands, ``TrapezoidProfileCommand`` allows the user to specify its subsystem requirements as a constructor parameter.
72-
73-
Full TrapezoidProfileCommand Example
74-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
75-
76-
What does a ``TrapezoidProfileCommand`` look like when used in practice? The following examples are taking from the DriveDistanceOffboard example project (`Java <https://github.com/wpilibsuite/allwpilib/tree/main/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/drivedistanceoffboard>`__, `C++ <https://github.com/wpilibsuite/allwpilib/tree/main/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard>`__):
12+
The following examples are taking from the DriveDistanceOffboard example project (`Java <https://github.com/wpilibsuite/allwpilib/tree/main/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/drivedistanceoffboard>`__, `C++ <https://github.com/wpilibsuite/allwpilib/tree/main/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard>`__):
7713

7814
.. tab-set::
7915

@@ -103,25 +39,3 @@ What does a ``TrapezoidProfileCommand`` look like when used in practice? The fo
10339
:lines: 5-
10440
:linenos:
10541
:lineno-start: 5
106-
107-
And, for an :ref:`inlined <docs/software/commandbased/organizing-command-based:Inline Commands>` example:
108-
109-
.. tab-set::
110-
111-
.. tab-item:: Java
112-
:sync: Java
113-
114-
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/main/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/drivedistanceoffboard/RobotContainer.java
115-
:language: java
116-
:lines: 66-85
117-
:linenos:
118-
:lineno-start: 66
119-
120-
.. tab-item:: C++
121-
:sync: C++
122-
123-
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/main/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/RobotContainer.cpp
124-
:language: c++
125-
:lines: 37-60
126-
:linenos:
127-
:lineno-start: 37

0 commit comments

Comments
 (0)