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
|
|
|
|
|
2022-12-04 09:33:18 +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
|
|
|
|
|
|
|
|
|
|
|
2022-12-04 08:16:51 +03:00
|
|
|
|
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])
|
|
|
|
|
|
2022-12-04 08:16:51 +03:00
|
|
|
|
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
|
|
|
|
|
2022-12-04 08:16:51 +03:00
|
|
|
|
elif part == 4:
|
2022-12-04 09:33:18 +03:00
|
|
|
|
vol[3][num].append(random.random() * 50 - 25)
|
|
|
|
|
if experiment % 3 == 0:
|
2022-12-04 10:01:58 +03:00
|
|
|
|
cur[3][num].append(
|
|
|
|
|
(83 * tanh(15.5 / 83 * vol[3][num][-1]) + 1.7 * vol[3][num][-1]) * (0.98 + random.random() / 25))
|
2022-12-04 09:33:18 +03:00
|
|
|
|
elif experiment % 3 == 1:
|
2022-12-04 10:01:58 +03:00
|
|
|
|
cur[3][num].append(
|
|
|
|
|
(44 * tanh(8.7 / 44 * vol[3][num][-1]) + 0.9 * vol[3][num][-1]) * (0.98 + random.random() / 25))
|
2022-12-04 09:33:18 +03:00
|
|
|
|
else:
|
2022-12-04 10:01:58 +03:00
|
|
|
|
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
|
|
|
|
|
2022-12-04 08:16:51 +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()
|
2022-12-04 09:33:18 +03:00
|
|
|
|
plt.xlabel('Напряжение, В')
|
2022-12-12 14:44:41 +03:00
|
|
|
|
if part == 1:
|
|
|
|
|
plt.ylabel('Ток, мА')
|
|
|
|
|
else:
|
|
|
|
|
plt.ylabel('Ток, мкА')
|
2022-12-04 08:16:51 +03:00
|
|
|
|
plt.savefig('tmpplots/tmpplot' + str(part) + '.jpg', dpi=200)
|
2022-12-03 23:44:57 +03:00
|
|
|
|
plt.close()
|
|
|
|
|
|
2022-12-04 10:01:58 +03:00
|
|
|
|
|
2022-12-03 23:44:57 +03:00
|
|
|
|
def empty_plot(part):
|
2022-12-04 08:16:51 +03:00
|
|
|
|
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()
|
2022-12-04 08:16:51 +03:00
|
|
|
|
plt.savefig('tmpplots/tmpplot' + str(part) + '.jpg', dpi=200)
|
2022-12-03 23:44:57 +03:00
|
|
|
|
plt.close()
|
|
|
|
|
|
2022-12-04 10:01:58 +03:00
|
|
|
|
|
2022-12-04 08:16:51 +03:00
|
|
|
|
def plus_plot(part):
|
2022-12-04 09:33:18 +03:00
|
|
|
|
global experiment
|
2022-12-04 08:16:51 +03:00
|
|
|
|
vol[part - 1].append([])
|
|
|
|
|
cur[part - 1].append([])
|
2022-12-04 09:33:18 +03:00
|
|
|
|
experiment += 1
|
2022-12-04 08:16:51 +03:00
|
|
|
|
|
2022-12-04 10:01:58 +03:00
|
|
|
|
|
2022-12-04 08:16:51 +03:00
|
|
|
|
def minus_plot(part):
|
|
|
|
|
vol[part - 1].pop()
|
|
|
|
|
cur[part - 1].pop()
|
2022-12-04 09:33:18 +03:00
|
|
|
|
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 = [[[]], [[]], [[]], [[]]]
|
2022-12-04 10:01:58 +03:00
|
|
|
|
experiment = 0
|