Skip to content

Commit

Permalink
Simplify RLIs with :lineno-match:
Browse files Browse the repository at this point in the history
Don't need to specify the starting line number which is prone to errors
  • Loading branch information
sciencewhiz committed Nov 22, 2024
1 parent 938480f commit 34107c8
Show file tree
Hide file tree
Showing 35 changed files with 249 additions and 498 deletions.
9 changes: 3 additions & 6 deletions source/docs/contributing/frc-docs/style-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,12 @@ When possible, instead of using code blocks, an RLI should be used. This pulls
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2025.1.1-beta-1/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gettingstarted/Robot.java
:language: java
:lines: 19-25
:linenos:
:lineno-start: 19
:lineno-match:
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2025.1.1-beta-1/wpilibcExamples/src/main/cpp/examples/GettingStarted/cpp/Robot.cpp
:language: c++
:lines: 50-60
:linenos:
:lineno-start: 50
:lineno-match:
.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/c6d0540b01e138725fad7366ff4e317e9994b78b/GettingStarted/robot.py
:language: python
Expand All @@ -132,8 +130,7 @@ To create code tabs in an article, you can use the ``.. tab-set-code::`` directi
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2025.1.1-beta-1/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gettingstarted/Robot.java
:language: java
:lines: 19-25
:linenos:
:lineno-start: 19
:lineno-match:
```c++
// Start the timer.
Expand Down
3 changes: 1 addition & 2 deletions source/docs/romi-robot/programming-romi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ To run a Romi program, first, ensure that your Romi is powered on. Next, connect
.. rli:: https://raw.githubusercontent.com/wpilibsuite/vscode-wpilib/v2025.1.1-beta-1/vscode-wpilib/resources/gradle/javaromi/build.gradle
:language: groovy
:lines: 44-47
:linenos:
:lineno-start: 44
:lineno-match:
:emphasize-lines: 2

Now to start your Romi robot code, open the WPILib Command Palette (type :kbd:`Ctrl+Shift+P`) and select "Simulate Robot Code", or press :kbd:`F5`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,14 @@ A more complete example of ``ProfiledPIDController`` usage is provided in the El
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2025.1.1-beta-1/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatorprofiledpid/Robot.java
:language: java
:lines: 5-
:linenos:
:lineno-start: 5
:lineno-match:

.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2025.1.1-beta-1/wpilibcExamples/src/main/cpp/examples/ElevatorProfiledPID/cpp/Robot.cpp
:language: c++
:lines: 5-
:linenos:
:lineno-start: 5
:lineno-match:

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/d89b0587a1e1111239728140466c7dc4324d4005/ElevatorProfiledPID/robot.py
:language: python
:lines: 8-
:linenos:
:lineno-start: 8
:lineno-match:
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,14 @@ A more complete example of ``TrapezoidProfile`` usage is provided in the Elevato
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2025.1.1-beta-1/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatortrapezoidprofile/Robot.java
:language: java
:lines: 5-
:linenos:
:lineno-start: 5
:lineno-match:

.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2025.1.1-beta-1/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/cpp/Robot.cpp
:language: c++
:lines: 5-
:linenos:
:lineno-start: 5
:lineno-match:

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/d89b0587a1e1111239728140466c7dc4324d4005/ElevatorTrapezoidProfile/robot.py
:language: python
:lines: 8-
:linenos:
:lineno-start: 8
:lineno-match:
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ The ``LinearSystem`` class contains methods for easily creating state-space syst
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2025.1.1-beta-1/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespaceflywheelsysid/Robot.java
:language: java
:lines: 32-46
:linenos:
:lineno-start: 33
:lineno-match:


.. tab-item:: C++
Expand All @@ -78,28 +77,24 @@ The ``LinearSystem`` class contains methods for easily creating state-space syst
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2025.1.1-beta-1/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp
:language: c++
:lines: 17
:linenos:
:lineno-start: 17
:lineno-match:

.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2025.1.1-beta-1/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp
:language: c++
:lines: 30-46
:linenos:
:lineno-start: 30
:lineno-match:

.. tab-item:: Python

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/d89b0587a1e1111239728140466c7dc4324d4005/StateSpaceFlywheelSysId/robot.py
:language: python
:lines: 23-27
:linenos:
:lineno-start: 23
:lineno-match:

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/d89b0587a1e1111239728140466c7dc4324d4005/StateSpaceFlywheelSysId/robot.py
:language: python
:lines: 37-48
:linenos:
:lineno-start: 37
:lineno-match:


### Modeling Using Flywheel Moment of Inertia and Gearing
Expand All @@ -120,38 +115,33 @@ The ``LinearSystem`` class contains methods to easily create a model of a flywhe
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2025.1.1-beta-1/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespaceflywheel/Robot.java
:language: java
:lines: 33-46
:linenos:
:lineno-start: 33
:lineno-match:

.. tab-item:: C++
:sync: c++

.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2025.1.1-beta-1/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp
:language: c++
:lines: 17-17
:linenos:
:lineno-start: 17
:lineno-match:

.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2025.1.1-beta-1/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp
:language: c++
:lines: 17,31-46
:linenos:
:lineno-start: 31
:lineno-match:

.. tab-item:: Python
:sync: python

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/d89b0587a1e1111239728140466c7dc4324d4005/StateSpaceFlywheel/robot.py
:language: python
:lines: 21-25
:linenos:
:lineno-start: 21
:lineno-match:

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/d89b0587a1e1111239728140466c7dc4324d4005/StateSpaceFlywheel/robot.py
:language: python
:lines: 37-46
:linenos:
:lineno-start: 37
:lineno-match:

## Kalman Filters: Observing Flywheel State

Expand All @@ -174,32 +164,28 @@ Because the feedback controller computes error using the :term:`x-hat` estimated
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2025.1.1-beta-1/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespaceflywheel/Robot.java
:language: java
:lines: 48-58
:linenos:
:lineno-start: 48
:lineno-match:

.. tab-item:: C++
:sync: c++

.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2025.1.1-beta-1/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp
:language: c++
:lines: 13-13
:linenos:
:lineno-start: 13
:lineno-match:

.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2025.1.1-beta-1/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp
:language: c++
:lines: 48-53
:linenos:
:lineno-start: 48
:lineno-match:

.. tab-item:: Python
:sync: python

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/d89b0587a1e1111239728140466c7dc4324d4005/StateSpaceFlywheel/robot.py
:language: python
:lines: 48-54
:linenos:
:lineno-start: 48
: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 All @@ -219,32 +205,28 @@ Much like ``SimpleMotorFeedforward`` can be used to generate feedforward voltage
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2025.1.1-beta-1/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespaceflywheel/Robot.java
:language: java
:lines: 59-70
:linenos:
:lineno-start: 59
:lineno-match:

.. tab-item:: C++
:sync: c++

.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2025.1.1-beta-1/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp
:language: c++
:lines: 11
:linenos:
:lineno-start: 11
:lineno-match:

.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2025.1.1-beta-1/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp
:language: c++
:lines: 55-75
:linenos:
:lineno-start: 54
:lineno-match:

.. tab-item:: Python
:sync: python

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/d89b0587a1e1111239728140466c7dc4324d4005/StateSpaceFlywheel/robot.py
:language: python
:lines: 56-66
:linenos:
:lineno-start: 56
:lineno-match:

## Bringing it All Together: LinearSystemLoop

Expand All @@ -258,32 +240,28 @@ LinearSystemLoop combines our system, controller, and observer that we created e
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2025.1.1-beta-1/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespaceflywheel/Robot.java
:language: java
:lines: 72-74
:linenos:
:lineno-start: 72
:lineno-match:

.. tab-item:: C++
:sync: c++

.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2025.1.1-beta-1/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp
:language: c++
:lines: 15-15
:linenos:
:lineno-start: 15
:lineno-match:

.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2025.1.1-beta-1/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp
:language: c++
:lines: 71-74
:linenos:
:lineno-start: 71
:lineno-match:

.. tab-item:: Python
:sync: python

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/d89b0587a1e1111239728140466c7dc4324d4005/StateSpaceFlywheel/robot.py
:language: python
:lines: 68-71
:linenos:
:lineno-start: 68
: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 All @@ -295,32 +273,28 @@ Once we have our ``LinearSystemLoop``, the only thing left to do is actually run
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2025.1.1-beta-1/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespaceflywheel/Robot.java
:language: java
:lines: 94-119
:linenos:
:lineno-start: 94
:lineno-match:

.. tab-item:: C++
:sync: c++

.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2025.1.1-beta-1/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp
:language: c++
:lines: 5-17
:linenos:
:lineno-start: 5
:lineno-match:

.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2025.1.1-beta-1/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp
:language: c++
:lines: 92-114
:linenos:
:lineno-start: 92
:lineno-match:

.. tab-item:: Python
:sync: python

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/d89b0587a1e1111239728140466c7dc4324d4005/StateSpaceFlywheel/robot.py
:language: python
:lines: 87-109
:linenos:
:lineno-start: 87
:lineno-match:

## Angle Wrap with LQR

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,30 +94,26 @@ WPILib's Kalman Filter classes' constructors take a linear system, a vector of p
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2025.1.1-beta-1/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespaceflywheel/Robot.java
:language: java
:lines: 48-57
:linenos:
:lineno-start: 48
:lineno-match:

.. tab-item:: C++

.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2025.1.1-beta-1/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp
:language: c++
:lines: 5-18
:linenos:
:lineno-start: 5
:lineno-match:

.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2025.1.1-beta-1/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp
:language: c++
:lines: 48-53
:linenos:
:lineno-start: 48
:lineno-match:

.. tab-item:: Python

.. remoteliteralinclude:: https://raw.githubusercontent.com/robotpy/examples/d89b0587a1e1111239728140466c7dc4324d4005/StateSpaceFlywheel/robot.py
:language: python
:lines: 48-54
:linenos:
:lineno-start: 48
:lineno-match:

## Footnotes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ Here's how to initialize a ``DifferentialDrivePoseEstimator``:
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2024.1.1-beta-4/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/differentialdriveposeestimator/Drivetrain.java
:language: java
:lines: 86-94
:linenos:
:lineno-start: 86
:lineno-match:

.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2024.1.1-beta-4/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/Drivetrain.h
:language: c++
:lines: 158-165
:linenos:
:lineno-start: 158
:lineno-match:

Add odometry measurements every loop by calling ``Update()``.

Expand All @@ -28,14 +26,12 @@ Add odometry measurements every loop by calling ``Update()``.
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2024.1.1-beta-4/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/differentialdriveposeestimator/Drivetrain.java
:language: java
:lines: 227-228
:linenos:
:lineno-start: 227
:lineno-match:

.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2024.1.1-beta-4/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Drivetrain.cpp
:language: c++
:lines: 84-86
:linenos:
:lineno-start: 84
:lineno-match:

Add vision pose measurements occasionally by calling ``AddVisionMeasurement()``.

Expand All @@ -44,14 +40,12 @@ Add vision pose measurements occasionally by calling ``AddVisionMeasurement()``.
.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2024.1.1-beta-4/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/differentialdriveposeestimator/Drivetrain.java
:language: java
:lines: 236-245
:linenos:
:lineno-start: 236
:lineno-match:

.. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2024.1.1-beta-4/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Drivetrain.cpp
:language: c++
:lines: 93-106
:linenos:
:lineno-start: 93
:lineno-match:

## Tuning Pose Estimators

Expand Down
Loading

0 comments on commit 34107c8

Please sign in to comment.