Skip to content

Commit 1a5477a

Browse files
authored
Add Python Example to Swerve Visualization Struct (#2471)
1 parent 57731c9 commit 1a5477a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

source/docs/software/kinematics-and-odometry/swerve-drive-kinematics.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,22 @@ By recording a set of swerve module states using :ref:`NetworkTables <docs/softw
312312
}
313313
};
314314

315+
.. code-block:: python
316+
317+
import ntcore
318+
from wpimath.kinematics import SwerveModuleState
319+
320+
# get the default instance of NetworkTables
321+
nt = ntcore.NetworkTableInstance.getDefault()
322+
323+
# Start publishing an array of module states with the "/SwerveStates" key
324+
topic = nt.getStructArrayTopic("/SwerveStates", SwerveModuleState)
325+
self.pub = topic.publish()
326+
327+
def periodic(self):
328+
# Periodically send a set of module states
329+
self.pub.set([frontLeftState,frontRightState,backLeftState,backRightState])
330+
315331
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.
316332

317333
.. image:: images/advantagescope-swerve.png

0 commit comments

Comments
 (0)