Skip to content

Commit

Permalink
Add Python Example to Swerve Visualization Struct (#2471)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasondaming authored Jan 6, 2024
1 parent 57731c9 commit 1a5477a
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,22 @@ By recording a set of swerve module states using :ref:`NetworkTables <docs/softw
}
};

.. code-block:: python
import ntcore
from wpimath.kinematics import SwerveModuleState
# get the default instance of NetworkTables
nt = ntcore.NetworkTableInstance.getDefault()
# Start publishing an array of module states with the "/SwerveStates" key
topic = nt.getStructArrayTopic("/SwerveStates", SwerveModuleState)
self.pub = topic.publish()
def periodic(self):
# Periodically send a set of module states
self.pub.set([frontLeftState,frontRightState,backLeftState,backRightState])
See the documentation for the `swerve <https://github.com/Mechanical-Advantage/AdvantageScope/blob/main/docs/tabs/SWERVE.md>`__ tab for more details on visualizing this data using AdvantageScope.

.. image:: images/advantagescope-swerve.png
Expand Down

0 comments on commit 1a5477a

Please sign in to comment.