Silaev/3.5.1 auto/plots.py

104 lines
3.1 KiB
Python
Raw Normal View History

2022-12-03 23:44:57 +03:00
import matplotlib.pyplot as plt
import random
2022-12-12 14:44:41 +03:00
import voltmeter
import amperemeter
2022-12-03 23:44:57 +03:00
from numpy import tanh
2022-12-03 23:44:57 +03:00
2022-12-12 14:44:41 +03:00
# Значения part = 1, 2 соответствуют режимам считывания с первой и второй пары приборов соответственно,
# режимы 3 и 4 являются тестовыми и генерируют значения самостоятельно
def start_measure(part):
if part == 1:
global v1, i1
v1 = voltmeter.AKIP('/dev/usbtmc0')
i1 = amperemeter.B7_78('/dev/ttyUSB0')
i1.getCurrentDC()
elif part == 2:
global v2, i2
v2 = voltmeter.AKIP('/dev/usbtmc0')
i2 = amperemeter.B7_78('/dev/ttyUSB1')
i2.getCurrentDC()
elif part == 0:
global i
ir = amperemeter.B7_78('/dev/ttyUSB0')
i = float(ir.getCurrentDC()) * 10 ** 3
i = float(ir.getCurrentDC()) * 10 ** 3
def get_point(part, num):
2022-12-03 23:44:57 +03:00
if part == 1:
2022-12-12 14:44:41 +03:00
vol[0][num].append(v1.getVoltageDC())
cur[0][num].append(i1.getCurrentDC() * 10 ** 3)
2022-12-03 23:44:57 +03:00
elif part == 2:
2022-12-12 14:44:41 +03:00
# global i
vol[1][num].append(v2.getVoltageDC())
cur[1][num].append(i2.getCurrentDC() * 10 ** 6)
# i = amperemeter.B7_78('/dev/ttyUSB0').getCurrentDC() * 10 ** 3
# print(vol[1], cur[1])
elif part == 3:
vol[2][num].append(random.random() * 100)
cur[2][num].append(random.random() * 100)
2022-12-12 14:44:41 +03:00
elif part == 4:
vol[3][num].append(random.random() * 50 - 25)
if experiment % 3 == 0:
cur[3][num].append(
(83 * tanh(15.5 / 83 * vol[3][num][-1]) + 1.7 * vol[3][num][-1]) * (0.98 + random.random() / 25))
elif experiment % 3 == 1:
cur[3][num].append(
(44 * tanh(8.7 / 44 * vol[3][num][-1]) + 0.9 * vol[3][num][-1]) * (0.98 + random.random() / 25))
else:
cur[3][num].append(
(22 * tanh(4.4 / 22 * vol[3][num][-1]) + 0.5 * vol[3][num][-1]) * (0.98 + random.random() / 25))
2022-12-03 23:44:57 +03:00
def saveplot(part):
2022-12-03 23:44:57 +03:00
plt.figure(figsize=(8, 6))
2022-12-12 14:44:41 +03:00
for j in range(len(vol[part - 1])):
# print(vol[part - 1][j], cur[part - 1][j])
plt.scatter(vol[part - 1][j], cur[part - 1][j], marker='o')
2022-12-03 23:44:57 +03:00
plt.grid()
plt.xlabel('Напряжение, В')
2022-12-12 14:44:41 +03:00
if part == 1:
plt.ylabel('Ток, мА')
else:
plt.ylabel('Ток, мкА')
plt.savefig('tmpplots/tmpplot' + str(part) + '.jpg', dpi=200)
2022-12-03 23:44:57 +03:00
plt.close()
2022-12-03 23:44:57 +03:00
def empty_plot(part):
vol[part - 1] = [[]]
cur[part - 1] = [[]]
2022-12-03 23:44:57 +03:00
plt.figure(figsize=(8, 6))
2022-12-12 14:44:41 +03:00
plt.scatter(cur[part - 1][0], vol[part - 1][0], marker='o')
2022-12-03 23:44:57 +03:00
plt.grid()
plt.savefig('tmpplots/tmpplot' + str(part) + '.jpg', dpi=200)
2022-12-03 23:44:57 +03:00
plt.close()
def plus_plot(part):
global experiment
vol[part - 1].append([])
cur[part - 1].append([])
experiment += 1
def minus_plot(part):
vol[part - 1].pop()
cur[part - 1].pop()
if len(vol[part - 1]) == 0:
vol[part - 1].append([])
cur[part - 1].append([])
2022-12-03 23:44:57 +03:00
2022-12-12 14:44:41 +03:00
i = 0
vol = [[[]], [[]], [[]], [[]]]
cur = [[[]], [[]], [[]], [[]]]
experiment = 0