Simulated Gyroscope

I’ve attached some code for a simulated gyroscope for a SwerveDrive. I’m looking for feedback .

I’ve been using the new fromDiscrete method for ChassisSpeeds and was expecting to use an elapsed time of 0.020s for drift reduction. I found that using 0.058s was benefitting us more. Being that this is all in the simulator I was wondering where the issue could be and I’m sure it’s probably in the simulated gyroscope.

The issue being that I’m using roughly 3 times the frame rate for drift reduction. This could be another issue, but I think all of my modules are in good shape. (2.4 KB)

I recommend making some x-y plots and pose vs time plots to diagnose the issue.

Are you thinking X-Y plots of joystick versus output ChassisSpeeds?

No, of pose.

So PoseX versus time and PoseY versus time?

What should I be looking for in these plots to the potential cause?

No, pose y vs pose x for constant joystick inputs. The time domain plots are separate.

I got you. Know of good graphing utilities that I can integrate into the coding environment?

Glass can do time domain plots, but I’ve had to use matplotlib or Excel for x-y plots.

I can just feed out the x-y plots into a JSON file. Is there a library for JSON files already in the deploy or is there one you recommend.

JSON is a weird format to use for that. CSV is more straightforward.

#!/usr/bin/env python3

import csv
import matplotlib.pyplot as plt

x = []
y = []
with open("xy.csv") as f:
    for row in csv.reader(f, delimiter=","):

plt.plot(x, y)
plt.xlabel("x position (m)")
plt.ylabel("y position (m)")

AdvantageScope might also support the plots you need, but I haven’t used the tool.

AdvantageScope 3D Field tab shows a robot pose through Network Tables and similarly the Odometry tab shows a top-down 2D Field. I use the 3D a lot but haven’t used the 2D yet.



So a graph of PoseY vs PoseX

A graph of PoseY vs time and one for X vs time the ?

How do I get started with this. Does it directly integrate or will I still have to export data from the program

I tried AdvantageScope Odometry tab now and it shows a robot pose in 2-D (or 3-D). It isn’t a true X-Y plot as it is intended to show just one point - the current pose of the robot. For the trajectory option it does show a few seconds of a “comet tail” following the robot but that isn’t much of a history if that’s what you need. The 3D Field tab shows the current pose of the robot in 3-D, of course.

AdvantageScope is a standalone program that you install on a PC. It easily connects to your robot’s Network Tables where it gets the robot pose data that you have to publish from your robot.

I hacked up some code to try this out. If you are still interested (since it lacks the historical aspect of a true X-Y plot) I can repost my changes back into Github.

Let me get my wings on with Advantage Scope first

AdvantageScope is not seeing my SmartDashboard data. Is there a special way I have to send stuff to the network tables.

Maybe! If you mean the left side of AdvantageScope doesn’t show all the names that are supposedly in your network table then verify those names show in a WPILib tool such as OutlineViewer. My AdvantageScope list of fields matches my Outline Viewer. I have no special troubleshooting skills if the lists of fields don’t match.

If you see the SmartDashboard table and your fields but they don’t drag or don’t show on a line graph that’s also a problem I don’t have and don’t know how to troubleshoot.

For the Odometry tab and the 3D Field tab the poses have to been in particular formats as documented in AdvantageScope.

The Odometry must be a 3 element array for X, Y, Theta.

The 3D Field must be a 7 element array for X, Y, Z, quaternion W,X,Y,Z (I think, didn’t check my memory and I’m called to eat a few minutes ago).

If this was not enough help let me know and I’ll post my test program. The 3D Field part is already in Github
Look at the tagstable variable.
If you want the Odometry example, I can send you that after dinner.

Make sure to click “File” > “Connect to Robot/Simulator”. Unlike the WPILib tools, AdvantageScope does not connect to NT automatically since it supports viewing both live data and log files. If you’re having other issues I can try to help diagnose.

Thanks for all of the information. I will try and put it to good use.

I just realized something. Though. I’m really stupid apparently. I was just expecting the number to show in a drop down like the sims dashboard. I wasn’t dragging into the right place :disappointed: