2025-12-13 15:01:04 +00:00
|
|
|
import pandas as pd
|
|
|
|
|
import matplotlib.pyplot as plt
|
2025-12-15 00:08:10 +00:00
|
|
|
from pathlib import Path
|
2025-12-13 15:01:04 +00:00
|
|
|
|
2025-12-15 00:08:10 +00:00
|
|
|
# -------- File picker --------
|
|
|
|
|
RESULTS_DIR = Path("results")
|
2025-12-13 15:01:04 +00:00
|
|
|
|
2025-12-15 00:08:10 +00:00
|
|
|
csv_files = sorted(RESULTS_DIR.glob("*.csv"))
|
|
|
|
|
|
|
|
|
|
if not csv_files:
|
|
|
|
|
raise FileNotFoundError("No CSV files found in results/")
|
|
|
|
|
|
|
|
|
|
print("Available result files:")
|
|
|
|
|
for i, f in enumerate(csv_files):
|
|
|
|
|
print(f"[{i}] {f.name}")
|
|
|
|
|
|
|
|
|
|
choice = int(input("Select file number: "))
|
|
|
|
|
csv_path = csv_files[choice]
|
|
|
|
|
|
|
|
|
|
print(f"\nLoading: {csv_path}\n")
|
|
|
|
|
|
|
|
|
|
# -------- Load CSV --------
|
|
|
|
|
df = pd.read_csv(csv_path)
|
|
|
|
|
|
|
|
|
|
# -------- Plot target vs current --------
|
2025-12-13 15:01:04 +00:00
|
|
|
for coord in ["x", "y", "z"]:
|
|
|
|
|
plt.figure()
|
2025-12-15 00:08:10 +00:00
|
|
|
plt.plot(df["time"], df[f"target_{coord}"], label=f"target_{coord}")
|
|
|
|
|
plt.plot(df["time"], df[f"current_{coord}"], label=f"current_{coord}")
|
|
|
|
|
plt.plot(df["time"], df[f"mot_{coord}"].clip(-1, 1), label=f"mot_{coord}")
|
|
|
|
|
plt.plot(df["time"], df[f"dmot_{coord}"].clip(-1, 1), label=f"desired mot_{coord}")
|
|
|
|
|
|
2025-12-13 15:01:04 +00:00
|
|
|
plt.xlabel("Time (s)")
|
2025-12-14 22:04:04 +00:00
|
|
|
plt.ylabel("Angular velocity & Motor Offset")
|
2025-12-15 00:08:10 +00:00
|
|
|
plt.title(f"{csv_path.name} — {coord.upper()} axis")
|
|
|
|
|
plt.legend(loc="upper right")
|
2025-12-13 15:01:04 +00:00
|
|
|
plt.grid(True)
|
2025-12-15 00:08:10 +00:00
|
|
|
|
|
|
|
|
ymin, ymax = plt.ylim()
|
|
|
|
|
plt.ylim(min(ymin, -1), max(ymax, 1))
|
|
|
|
|
|
2025-12-13 15:01:04 +00:00
|
|
|
plt.show()
|
|
|
|
|
|
2025-12-15 00:08:10 +00:00
|
|
|
# -------- Plot error --------
|
2025-12-13 15:01:04 +00:00
|
|
|
plt.figure()
|
|
|
|
|
plt.plot(df["time"], df["error_x"], label="error_x")
|
|
|
|
|
plt.plot(df["time"], df["error_y"], label="error_y")
|
|
|
|
|
plt.plot(df["time"], df["error_z"], label="error_z")
|
2025-12-15 00:08:10 +00:00
|
|
|
|
2025-12-13 15:01:04 +00:00
|
|
|
plt.xlabel("Time (s)")
|
|
|
|
|
plt.ylabel("Error")
|
2025-12-15 00:08:10 +00:00
|
|
|
plt.title(f"PID Error — {csv_path.name}")
|
|
|
|
|
plt.legend(loc="upper right")
|
2025-12-13 15:01:04 +00:00
|
|
|
plt.grid(True)
|
|
|
|
|
plt.show()
|
|
|
|
|
|