2025-12-13 15:01:04 +00:00
|
|
|
import pandas as pd
|
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
|
|
|
|
# Load the CSV exported by the PID controller
|
2025-12-14 22:04:04 +00:00
|
|
|
df = pd.read_csv("data.csv")
|
2025-12-13 15:01:04 +00:00
|
|
|
|
|
|
|
|
# --- Plot target vs current ---
|
|
|
|
|
for coord in ["x", "y", "z"]:
|
|
|
|
|
plt.figure()
|
|
|
|
|
plt.plot(df["time"], df["target_" + coord], label="target_" + coord)
|
|
|
|
|
plt.plot(df["time"], df["current_" + coord], label="current_" + coord)
|
2025-12-14 22:04:04 +00:00
|
|
|
plt.plot(df["time"], df["mot_" + coord].clip(-1,1), label="mot_" + coord)
|
|
|
|
|
plt.plot(df["time"], df["dmot_" + coord].clip(-1,1), label="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")
|
|
|
|
|
plt.title(f"Target vs Current Angular Velocity with Motor Diff ({coord})")
|
|
|
|
|
plt.legend(loc='upper right')
|
2025-12-13 15:01:04 +00:00
|
|
|
plt.grid(True)
|
|
|
|
|
plt.show()
|
|
|
|
|
|
2025-12-14 22:04:04 +00:00
|
|
|
# for coord in ["x", "y", "z"]:
|
|
|
|
|
# plt.figure()
|
|
|
|
|
# plt.plot(df["time"], df["target_" + coord], label="target_" + coord)
|
|
|
|
|
# plt.plot(df["time"], df["current_" + coord], label="current_" + coord)
|
|
|
|
|
# plt.xlabel("Time (s)")
|
|
|
|
|
# plt.ylabel("Angular velocity")
|
|
|
|
|
# plt.title(f"Target vs Current Angular Velocity ({coord})")
|
|
|
|
|
# plt.legend()
|
|
|
|
|
# plt.grid(True)
|
|
|
|
|
# plt.show()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# plt.figure()
|
|
|
|
|
# plt.plot(df["time"], df["target_x"], label="target_x")
|
|
|
|
|
# plt.plot(df["time"], df["current_x"], label="current_x")
|
|
|
|
|
# plt.plot(df["time"], df["target_y"], label="target_y")
|
|
|
|
|
# plt.plot(df["time"], df["current_y"], label="current_y")
|
|
|
|
|
# plt.plot(df["time"], df["target_z"], label="target_z")
|
|
|
|
|
# plt.plot(df["time"], df["current_z"], label="current_z")
|
|
|
|
|
# plt.xlabel("Time (s)")
|
|
|
|
|
# plt.ylabel("Angular velocity")
|
|
|
|
|
# plt.title("Target vs Current Angular Velocity")
|
|
|
|
|
# plt.legend()
|
|
|
|
|
# plt.grid(True)
|
|
|
|
|
# plt.show()
|
2025-12-13 15:01:04 +00:00
|
|
|
# --- Plot error over time ---
|
|
|
|
|
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")
|
|
|
|
|
plt.xlabel("Time (s)")
|
|
|
|
|
plt.ylabel("Error")
|
|
|
|
|
plt.title("PID Error Over Time")
|
2025-12-14 22:04:04 +00:00
|
|
|
plt.legend(loc='upper right')
|
2025-12-13 15:01:04 +00:00
|
|
|
plt.grid(True)
|
|
|
|
|
plt.show()
|
|
|
|
|
|