-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpid_vis.py
More file actions
42 lines (38 loc) · 1.81 KB
/
pid_vis.py
File metadata and controls
42 lines (38 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from pathlib import Path
import csv
from collections import defaultdict
from matplotlib import pyplot as plt
with Path('pid_test.csv').open('r') as f:
reader = csv.DictReader(filter(lambda line: not line.startswith('#'), f))
lists = defaultdict(list)
# header = "EncoderLeft,EncoderRight,DesiredVelocityLeft,DesiredVelocityRight,CurrentVelocityLeft,CurrentVelocityRight,LeftPower,RightPower,EncoderTargetLeft,EncoderTargetRight"
header = "LeftSetpoint,LeftVelocity,LeftError,RightSetpoint,RightVelocity,RightError"
keys = header.split(",")
for row in reader:
for k in keys:
val = int(row[k]) if "." not in row[k] else float(row[k])
# if "Left" in k:
# val *= -1 # Correct for rotation test
lists[k].append(val)
# power_deadzone = [0.15] * len(lists["EncoderLeft"])
# neg_power_deadzone = [-0.15] * len(lists["EncoderLeft"])
# fig, (ax_enc, ax_vel, ax_pow) = plt.subplots(3, 1)
# ax_enc.set_title("Encoder Values")
# ax_enc.plot(
# lists["EncoderLeft"], "-b",
# lists["EncoderRight"], "-r",
# lists["EncoderTargetLeft"], "--c",
# lists["EncoderTargetRight"], "--m",
# )
# ax_vel.set_title("Velocity Values")
# ax_vel.plot(
# lists["CurrentVelocityLeft"], "-b",
# lists["CurrentVelocityRight"], "-r",
# lists["DesiredVelocityLeft"], "--c",
# lists["DesiredVelocityRight"], "--m",
# )
# ax_pow.set_title("Motor Powers")
# ax_pow.plot(power_deadzone, "--k", neg_power_deadzone, "--k", lists["LeftPower"], "-g", lists["RightPower"], "-y")
# plt.show()
plt.plot(lists["LeftSetpoint"], "-b", lists["LeftVelocity"], "-r", lists["LeftError"], "-g", lists["RightSetpoint"], "--c", lists["RightVelocity"], "--m", lists["RightError"], "--y")
plt.show()