Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Python example RLIs #2955

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/inspector.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{
"baseUrl": "https://raw.githubusercontent.com/robotpy/examples/",
"versionScheme": "\\d{4}\\.\\d\\.\\d\\.\\d(?:-(?:alpha|beta)-\\d)?|[0-9a-f]{40}",
"latestVersion": "36c64f286a38478f5e04d60321c57b0a9d1c5f17"
"latestVersion": "4e7b525b47246e55ad617a66f2c3d9fda34484a3"
},
{
"baseUrl": "https://raw.githubusercontent.com/wpilibsuite/vscode-wpilib/",
Expand Down
2 changes: 1 addition & 1 deletion source/docs/contributing/frc-docs/style-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ When possible, instead of using code blocks, an RLI should be used. This pulls
:lines: 50-60
:lineno-match:

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/36c64f286a38478f5e04d60321c57b0a9d1c5f17/GettingStarted/robot.py
.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/4e7b525b47246e55ad617a66f2c3d9fda34484a3/GettingStarted/robot.py
:language: python
:lines: 12-29
:lineno-match:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ A more complete example of ``ProfiledPIDController`` usage is provided in the El
:lines: 5-
:lineno-match:

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/36c64f286a38478f5e04d60321c57b0a9d1c5f17/ElevatorProfiledPID/robot.py
.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/4e7b525b47246e55ad617a66f2c3d9fda34484a3/ElevatorProfiledPID/robot.py
:language: python
:lines: 8-
:lineno-match:
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ A more complete example of ``TrapezoidProfile`` usage is provided in the Elevato
:lines: 5-
:lineno-match:

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/36c64f286a38478f5e04d60321c57b0a9d1c5f17/ElevatorTrapezoidProfile/robot.py
.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/4e7b525b47246e55ad617a66f2c3d9fda34484a3/ElevatorTrapezoidProfile/robot.py
:language: python
:lines: 8-
:lineno-match:
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ The ``LinearSystem`` class contains methods for easily creating state-space syst

.. tab-item:: Python

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/36c64f286a38478f5e04d60321c57b0a9d1c5f17/StateSpaceFlywheelSysId/robot.py
.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/4e7b525b47246e55ad617a66f2c3d9fda34484a3/StateSpaceFlywheelSysId/robot.py
:language: python
:lines: 23-27
:lineno-match:

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/36c64f286a38478f5e04d60321c57b0a9d1c5f17/StateSpaceFlywheelSysId/robot.py
.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/4e7b525b47246e55ad617a66f2c3d9fda34484a3/StateSpaceFlywheelSysId/robot.py
:language: python
:lines: 37-48
:lineno-match:
Expand Down Expand Up @@ -133,14 +133,14 @@ The ``LinearSystem`` class contains methods to easily create a model of a flywhe
.. tab-item:: Python
:sync: python

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/36c64f286a38478f5e04d60321c57b0a9d1c5f17/StateSpaceFlywheel/robot.py
.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/4e7b525b47246e55ad617a66f2c3d9fda34484a3/StateSpaceFlywheel/robot.py
:language: python
:lines: 21-25
:lines: 22-26
:lineno-match:

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/36c64f286a38478f5e04d60321c57b0a9d1c5f17/StateSpaceFlywheel/robot.py
.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/4e7b525b47246e55ad617a66f2c3d9fda34484a3/StateSpaceFlywheel/robot.py
:language: python
:lines: 37-46
:lines: 38-47
:lineno-match:

## Kalman Filters: Observing Flywheel State
Expand Down Expand Up @@ -182,9 +182,9 @@ Because the feedback controller computes error using the :term:`x-hat` estimated
.. tab-item:: Python
:sync: python

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/36c64f286a38478f5e04d60321c57b0a9d1c5f17/StateSpaceFlywheel/robot.py
.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/4e7b525b47246e55ad617a66f2c3d9fda34484a3/StateSpaceFlywheel/robot.py
:language: python
:lines: 48-54
:lines: 49-55
:lineno-match:

Because Kalman filters use our state-space model in the :ref:`docs/software/advanced-controls/state-space/state-space-observers:Predict step`, it is important that our model is as accurate as possible. One way to verify this is to record a flywheel's input voltage and velocity over time, and replay this data by calling only ``predict`` on the Kalman filter. Then, the kV and kA gains (or moment of inertia and other constants) can be adjusted until the model closely matches the recorded data.
Expand Down Expand Up @@ -223,9 +223,9 @@ Much like ``SimpleMotorFeedforward`` can be used to generate feedforward voltage
.. tab-item:: Python
:sync: python

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/36c64f286a38478f5e04d60321c57b0a9d1c5f17/StateSpaceFlywheel/robot.py
.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/4e7b525b47246e55ad617a66f2c3d9fda34484a3/StateSpaceFlywheel/robot.py
:language: python
:lines: 56-66
:lines: 57-67
:lineno-match:

## Bringing it All Together: LinearSystemLoop
Expand Down Expand Up @@ -258,9 +258,9 @@ LinearSystemLoop combines our system, controller, and observer that we created e
.. tab-item:: Python
:sync: python

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/36c64f286a38478f5e04d60321c57b0a9d1c5f17/StateSpaceFlywheel/robot.py
.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/4e7b525b47246e55ad617a66f2c3d9fda34484a3/StateSpaceFlywheel/robot.py
:language: python
:lines: 68-71
:lines: 69-72
:lineno-match:

Once we have our ``LinearSystemLoop``, the only thing left to do is actually run it. To do that, we'll periodically update our Kalman filter with our new encoder velocity measurements and apply new voltage commands to it. To do that, we first set the :term:`reference`, then ``correct`` with the current flywheel speed, ``predict`` the Kalman filter into the next timestep, and apply the inputs generated using ``getU``.
Expand Down Expand Up @@ -291,9 +291,9 @@ Once we have our ``LinearSystemLoop``, the only thing left to do is actually run
.. tab-item:: Python
:sync: python

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/36c64f286a38478f5e04d60321c57b0a9d1c5f17/StateSpaceFlywheel/robot.py
.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/4e7b525b47246e55ad617a66f2c3d9fda34484a3/StateSpaceFlywheel/robot.py
:language: python
:lines: 87-109
:lines: 88-110
:lineno-match:

## Angle Wrap with LQR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ WPILib's Kalman Filter classes' constructors take a linear system, a vector of p

.. tab-item:: Python

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/36c64f286a38478f5e04d60321c57b0a9d1c5f17/StateSpaceFlywheel/robot.py
.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/4e7b525b47246e55ad617a66f2c3d9fda34484a3/StateSpaceFlywheel/robot.py
:language: python
:lines: 48-54
:lines: 49-55
:lineno-match:

## Footnotes
Expand Down
10 changes: 5 additions & 5 deletions source/docs/software/basic-programming/robot-preferences.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ This example shows how to utilize Preferences to change the setpoint of a PID co
.. tab-item:: Python
:sync: Python

.. rli:: https://raw.githubusercontent.com/robotpy/examples/36c64f286a38478f5e04d60321c57b0a9d1c5f17/ArmSimulation/constants.py
.. rli:: https://raw.githubusercontent.com/robotpy/examples/4e7b525b47246e55ad617a66f2c3d9fda34484a3/ArmSimulation/constants.py
:language: python
:lines: 18-23

.. rli:: https://raw.githubusercontent.com/robotpy/examples/36c64f286a38478f5e04d60321c57b0a9d1c5f17/ArmSimulation/subsytems/arm.py
.. rli:: https://raw.githubusercontent.com/robotpy/examples/4e7b525b47246e55ad617a66f2c3d9fda34484a3/ArmSimulation/subsytems/arm.py
:language: python
:lines: 20-23,37-41

Expand Down Expand Up @@ -69,7 +69,7 @@ If using the Command Framework, this type of code could be placed in the constru
.. tab-item:: Python
:sync: Python

.. rli:: https://raw.githubusercontent.com/robotpy/examples/36c64f286a38478f5e04d60321c57b0a9d1c5f17/ArmSimulation/subsytems/arm.py
.. rli:: https://raw.githubusercontent.com/robotpy/examples/4e7b525b47246e55ad617a66f2c3d9fda34484a3/ArmSimulation/subsytems/arm.py
:language: python
:lines: 43-50

Expand Down Expand Up @@ -102,10 +102,10 @@ Depending on the data that is stored in preferences, you can use it when you rea
.. tab-item:: Python
:sync: Python

.. rli:: https://raw.githubusercontent.com/robotpy/examples/36c64f286a38478f5e04d60321c57b0a9d1c5f17/ArmSimulation/robot.py
.. rli:: https://raw.githubusercontent.com/robotpy/examples/4e7b525b47246e55ad617a66f2c3d9fda34484a3/ArmSimulation/robot.py
:language: python
:lines: 22-28
.. rli:: https://raw.githubusercontent.com/robotpy/examples/36c64f286a38478f5e04d60321c57b0a9d1c5f17/ArmSimulation/subsytems/arm.py
.. rli:: https://raw.githubusercontent.com/robotpy/examples/4e7b525b47246e55ad617a66f2c3d9fda34484a3/ArmSimulation/subsytems/arm.py
:language: python
:lines: 52-57

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Note: it is not necessary to create a PowerDistribution object unless you need t
:language: c++
:lines: 28-31

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/36c64f286a38478f5e04d60321c57b0a9d1c5f17/CANPDP/robot.py
.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/4e7b525b47246e55ad617a66f2c3d9fda34484a3/CANPDP/robot.py
:language: python
:lines: 34-37

Expand All @@ -61,7 +61,7 @@ Monitoring the bus voltage can be useful for (among other things) detecting when
:language: c++
:lines: 33-35

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/36c64f286a38478f5e04d60321c57b0a9d1c5f17/CANPDP/robot.py
.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/4e7b525b47246e55ad617a66f2c3d9fda34484a3/CANPDP/robot.py
:language: python
:lines: 39-41

Expand All @@ -80,7 +80,7 @@ Monitoring the temperature can be useful for detecting if the robot has been dra
:language: c++
:lines: 37-49

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/36c64f286a38478f5e04d60321c57b0a9d1c5f17/CANPDP/robot.py
.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/4e7b525b47246e55ad617a66f2c3d9fda34484a3/CANPDP/robot.py
:language: python
:lines: 43-55

Expand All @@ -101,7 +101,7 @@ The PDP/PDH also allows users to monitor the current drawn by the individual dev
:language: c++
:lines: 22-26

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/36c64f286a38478f5e04d60321c57b0a9d1c5f17/CANPDP/robot.py
.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/4e7b525b47246e55ad617a66f2c3d9fda34484a3/CANPDP/robot.py
:language: python
:lines: 28-32

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The following program starts automatic capture of a USB camera like the Microsof
:language: c++
:lines: 7-8, 16-18, 20, 25-31

.. rli:: https://raw.githubusercontent.com/robotpy/examples/36c64f286a38478f5e04d60321c57b0a9d1c5f17/QuickVision/robot.py
.. rli:: https://raw.githubusercontent.com/robotpy/examples/4e7b525b47246e55ad617a66f2c3d9fda34484a3/QuickVision/robot.py
:language: python
:lines: 8-17
:linenos:
Expand Down Expand Up @@ -69,14 +69,14 @@ In the following example a thread created in ``Robot`` constructor gets the Came

Here's what your ``robot.py`` needs to contain to launch the image processing process:

.. rli:: https://raw.githubusercontent.com/robotpy/examples/36c64f286a38478f5e04d60321c57b0a9d1c5f17/IntermediateVision/robot.py
.. rli:: https://raw.githubusercontent.com/robotpy/examples/4e7b525b47246e55ad617a66f2c3d9fda34484a3/IntermediateVision/robot.py
:language: python
:lines: 8-17
:linenos:

The ``launch("vision.py")`` function says to launch ``vision.py`` and call the ``run`` function in that file. Here's what is in ``vision.py``:

.. rli:: https://raw.githubusercontent.com/robotpy/examples/36c64f286a38478f5e04d60321c57b0a9d1c5f17/IntermediateVision/vision.py
.. rli:: https://raw.githubusercontent.com/robotpy/examples/4e7b525b47246e55ad617a66f2c3d9fda34484a3/IntermediateVision/vision.py
:language: python
:lines: 12-55
:linenos:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Now let's look at various parts of the code.

.. tab-item:: Python

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/36c64f286a38478f5e04d60321c57b0a9d1c5f17/GettingStarted/robot.py
.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/4e7b525b47246e55ad617a66f2c3d9fda34484a3/GettingStarted/robot.py
:language: python
:lines: 8-9
:lineno-match:
Expand Down Expand Up @@ -496,7 +496,7 @@ The ``Robot`` constructor for our sample program inverts the right side of the d
:lines: 25-36
:lineno-match:

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/36c64f286a38478f5e04d60321c57b0a9d1c5f17/GettingStarted/robot.py
.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/4e7b525b47246e55ad617a66f2c3d9fda34484a3/GettingStarted/robot.py
:language: python
:lines: 31-43
:lineno-match:
Expand All @@ -519,7 +519,7 @@ The ``AutonomousInit`` method is run once each time the robot transitions to aut
:lines: 38-45
:lineno-match:

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/36c64f286a38478f5e04d60321c57b0a9d1c5f17/GettingStarted/robot.py
.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/4e7b525b47246e55ad617a66f2c3d9fda34484a3/GettingStarted/robot.py
:language: python
:lines: 45-52
:lineno-match:
Expand All @@ -540,7 +540,7 @@ Like in Autonomous, the Teleop mode has a ``TeleopInit`` and ``TeleopPeriodic``
:lines: 45-48
:lineno-match:

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/36c64f286a38478f5e04d60321c57b0a9d1c5f17/GettingStarted/robot.py
.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/4e7b525b47246e55ad617a66f2c3d9fda34484a3/GettingStarted/robot.py
:language: python
:lines: 54-58
:lineno-match:
Expand Down