collab/pb-hal

git clone https://git.julia.blue/collab/pb-hal

Joseph RyanMerge pull request #2 from ut-ras/control9cbe263

tof
1.2 KiB43 linesraw
1#!/usr/bin/env python3
2import matplotlib.pyplot as plt
3import numpy as np
4from scipy.interpolate import spline
5import sys
6
7if len(sys.argv) < 2:
8    print("Please pass a log file as input")
9    sys.exit()
10
11f = open(sys.argv[1])
12current = f.readline()
13while current:
14    points = []
15    plt.title(f.readline().strip())
16    current = f.readline()
17    currentTime = 0
18    while current.strip():
19        points.append(list(map(float, current.strip().split(' '))))
20        points[-1][0] += currentTime
21        currentTime = points[-1][0]
22        current = f.readline()
23    if not len(points):
24        continue
25
26    # Removes tail if data stays constant after reaching setpoint
27    while len(points) > 5 and points[-1][1] == points[-3][1]:
28        del(points[-1])
29
30    del points[0]
31    x = np.array([i[0] for i in points])
32    y = []
33    for i in range(1, len(points[0])):
34        y.append([j[i] for j in points])
35    #  Interpolation is fun and pretty but we kind of want exact data for tuning
36    #  prettyX = np.linspace(x.min(), x.max(), 300)  # number of points to interpolate
37    #  prettyY = spline(x, y, prettyX)
38    plt.tight_layout()
39    for i in y:
40        plt.plot(x, i)
41    plt.legend(["P", "I", "D", "Output"])
42    #  plt.plot(prettyX, prettyY)
43    plt.show()