From 097e763fa0f06860acb54f023663f27bd93e580a Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Wed, 17 Jan 2024 11:06:43 -0800 Subject: [PATCH] [sysid] Document using AdvantageScope for troubleshooting Fixes #6187. --- sysid/README.md | 14 ++++++ sysid/scripts/time_plots.py | 89 ------------------------------------- 2 files changed, 14 insertions(+), 89 deletions(-) create mode 100644 sysid/README.md delete mode 100755 sysid/scripts/time_plots.py diff --git a/sysid/README.md b/sysid/README.md new file mode 100644 index 00000000000..842f3bec684 --- /dev/null +++ b/sysid/README.md @@ -0,0 +1,14 @@ +# SysId: System Identification for Robot Mechanisms + +## Building and Running SysId + +See [here](../README.md#Requirements) for build requirements. + +Run the following in the monorepo root. +```bash +./gradlew sysid:run +``` + +## Troubleshooting + +Use [AdvantageScope](https://docs.wpilib.org/en/stable/docs/software/dashboards/advantagescope.html) (shipped with the WPILib installer) to view .wpilog files for troubleshooting when SysId fails to generate plots. diff --git a/sysid/scripts/time_plots.py b/sysid/scripts/time_plots.py deleted file mode 100755 index 6878126af2c..00000000000 --- a/sysid/scripts/time_plots.py +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/env python3 - -import json -import pathlib - -import matplotlib.pyplot as plt -import pandas as pd -import sys - -# Load data -filename = pathlib.Path(sys.argv[1]) - -UNIT_TO_ABBREVIATION = { - "Meters": "m", - "Feet": "ft", - "Inches": "in", - "Degrees": "deg", - "Rotations": "rot", - "Radians": "rad", -} - -# Make DataFrame to facilitate plotting -if filename.suffix == ".json": - raw_data = json.loads(filename.read_text()) - unit = raw_data["units"] - - # Get Unit - try: - abbreviation = UNIT_TO_ABBREVIATION[unit] - except KeyError: - raise ValueError("Invalid Unit") - - # Make Columns - columns = ["Timestamp (s)", "Test"] - if "Drive" in raw_data["test"]: - columns.extend( - [ - "Left Volts (V)", - "Right Volts (V)", - f"Left Position ({abbreviation})", - f"Right Position ({abbreviation})", - f"Left Velocity ({abbreviation}/s)", - f"Right Velocity ({abbreviation}/s)", - "Gyro Position (deg)", - "Gyro Rate (deg/s)", - ] - ) - unit_columns = columns[4:8] - else: - columns.extend( - ["Volts (V)", f"Position ({abbreviation})", f"Velocity ({abbreviation}/s)"] - ) - unit_columns = columns[3:] - - prepared_data = pd.DataFrame(columns=columns) - for test in raw_data.keys(): - if "-" not in test: - continue - formatted_entry = [[pt[0], test, *pt[1:]] for pt in raw_data[test]] - prepared_data = pd.concat( - [prepared_data, pd.DataFrame(formatted_entry, columns=columns)] - ) - - units_per_rot = raw_data["unitsPerRotation"] - - for column in unit_columns: - prepared_data[column] *= units_per_rot -else: - prepared_data = pd.read_csv(filename) - -# First 2 columns are Timestamp and Test -for column in prepared_data.columns[2:]: - # Configure Plot Labels - plt.figure() - plt.xlabel("Timestamp (s)") - plt.ylabel(column) - - # Configure title without units - print(column) - end = column.find("(") - plt.title(f"{column[:end].strip()} vs Time") - - # Plot data for each test - for test in pd.unique(prepared_data["Test"]): - test_data = prepared_data[prepared_data["Test"] == test] - plt.plot(test_data["Timestamp (s)"], test_data[column], label=test) - plt.legend() - -plt.show()