-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmotorSysID.py
52 lines (40 loc) · 1.1 KB
/
motorSysID.py
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
43
44
45
46
47
48
49
50
51
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 05 23:46:48 2018
@author: Jesse
"""
import serial
import matplotlib.pyplot as plt
from scipy import signal
import numpy as np
def show_plot(figure_id=None):
if figure_id is None:
fig = plt.gcf()
else:
# do this even if figure_id == 0
fig = plt.figure(num=figure_id)
plt.show()
plt.pause(1e-9)
fig.canvas.manager.window.activateWindow()
fig.canvas.manager.window.raise_()
pos = []
time = []
ser = serial.Serial('COM5', 115200)
while (not time) or (time[-1] < 50000):
data = ser.readline().decode('utf-8').split(" ")
if len(data) >= 2:
pos.append(int(data[0]))
time.append(int(data[1]))
ser.close()
pos = np.divide(pos,1320.)
time = np.divide(time,10000.)
#vel = signal.savgol_filter(pos, 49, 6, deriv=1, delta = 0.001)
hann = np.hanning(40)
vel_raw = np.divide(np.diff(pos),map(float,np.diff(time)))
vel = signal.filtfilt(hann/sum(hann),1,vel_raw, method='gust')
fig = plt.figure(figsize = (20,15))
plt.subplot(211)
plt.plot(time,pos)
plt.subplot(212)
plt.plot(time[:-1],vel_raw)
plt.plot(fig)