-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColetaPRBS.py
More file actions
69 lines (54 loc) · 1.46 KB
/
ColetaPRBS.py
File metadata and controls
69 lines (54 loc) · 1.46 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Bibliotecas
from scipy import signal as sg
import matplotlib.pyplot as plt
import numpy as np
import serial
import time as tempo
Ts = 20e-3
setpoint = 8.0
# PRBS:
u = 2.0*(sg.max_len_seq(8)[0]-0.5)[0:200]
u = np.repeat(u,4) + setpoint
NA = len(u)
y = np.zeros(NA).astype(float)
toc = np.zeros(NA)
u = u[:NA]
tempo_medido = np.zeros(len(y)).astype(float)
# Coleta
print('\n Conexão')
conexao = serial.Serial(port='COM8',
baudrate=115200,
timeout=0.005)
tempo.sleep(1)
print('\n Coleta')
for n in range(NA):
tic = tempo.time()
sinal_pwm = (u[n]*255)/15
conexao.write(str(round(sinal_pwm)).encode())
if (conexao.inWaiting()>0):
y[n] = conexao.readline().decode()
tempo.sleep(Ts)
tempo_medido[n] = tempo.time()-tic
conexao.write('0'.encode())
print('\nFim da coleta.')
conexao.close()
# Gráficos
t = Ts*np.arange(0,len(u))
plt.figure(figsize=(10,10))
plt.subplot(211)
plt.step(t,u,'-b',linewidth=1.2)
plt.xlabel('Tempo(s)')
plt.ylabel('Sinal de Entrada')
plt.grid()
plt.legend(loc='lower right')
plt.subplot(212)
plt.plot(t,y,'-r',linewidth=1.2)
plt.xlabel('Tempo(s)')
plt.ylabel('sinal de saida')
plt.grid()
plt.legend(loc='lower right', labels=('Tempo','Sinal de saida'))
plt.savefig('coleta_dados_2.png', bbox_inches='tight')
plt.show()
# Salva Dados:
Dados = np.stack((tempo_medido,u,y), axis=-1)
np.save(r"DadosMG.npy",Dados)