testing
This commit is contained in:
49
plot.py
49
plot.py
@@ -1,5 +1,3 @@
|
|||||||
# python_live_plot.py
|
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from simple_pid import PID
|
from simple_pid import PID
|
||||||
from itertools import count
|
from itertools import count
|
||||||
@@ -11,10 +9,10 @@ import minimalmodbus
|
|||||||
tempSens = minimalmodbus.Instrument('/dev/ttyUSB1', 1)
|
tempSens = minimalmodbus.Instrument('/dev/ttyUSB1', 1)
|
||||||
tempSens.serial.baudrate = 38400
|
tempSens.serial.baudrate = 38400
|
||||||
|
|
||||||
OutputDriver = minimalmodbus.Instrument('/dev/ttyUSB1', 2)
|
OutputDriver = minimalmodbus.Instrument('/dev/ttyUSB1', 1)
|
||||||
OutputDriver.serial.baudrate = 38400
|
OutputDriver.serial.baudrate = 38400
|
||||||
|
|
||||||
pid = PID(1, 0.01, 0, setpoint=60)
|
pid = PID(10, 0.01, 0.1, setpoint=100)
|
||||||
|
|
||||||
plt.style.use('fivethirtyeight')
|
plt.style.use('fivethirtyeight')
|
||||||
|
|
||||||
@@ -26,32 +24,35 @@ index = count()
|
|||||||
|
|
||||||
def animate(i):
|
def animate(i):
|
||||||
try:
|
try:
|
||||||
temp = tempSens.read_float(1)
|
temp = tempSens.read_float(1, functioncode=4, byteorder=0)
|
||||||
y_values.append(temp)
|
y_values.append(temp)
|
||||||
x_values.append(next(index))
|
x_values.append(next(index))
|
||||||
|
#print(temp)
|
||||||
|
print(tempSens.read_float(11, functioncode=4, byteorder=0))
|
||||||
|
|
||||||
print(temp, end='\t')
|
# print(temp, end='\t')
|
||||||
control = pid(temp)
|
# control = pid(temp)
|
||||||
if(control>100):
|
# if(control>100):
|
||||||
control = 100;
|
# control = 100;
|
||||||
control = (control/1000.0)
|
# control = (control/1000.0)
|
||||||
print(control, end='\t')
|
# if(control < 0):
|
||||||
print(0.1-control)
|
# control = 0
|
||||||
|
# print(control, end='\t')
|
||||||
if(control > 0):
|
# print(0.1-control)
|
||||||
OutputDriver.write_bit(0, 1, functioncode=15)
|
#
|
||||||
|
# if(control > 0):
|
||||||
time.sleep(control)
|
# OutputDriver.write_bit(0, 1, functioncode=15)
|
||||||
|
#
|
||||||
if(control<0.1):
|
# time.sleep(control)
|
||||||
OutputDriver.write_bit(0, 0, functioncode=15)
|
#
|
||||||
|
# if(control<0.1):
|
||||||
time.sleep(0.1-control)
|
# OutputDriver.write_bit(0, 0, functioncode=15)
|
||||||
|
#
|
||||||
|
# time.sleep(0.1-control)
|
||||||
|
|
||||||
plt.cla()
|
plt.cla()
|
||||||
plt.scatter(x_values, y_values)
|
plt.scatter(x_values, y_values)
|
||||||
except:
|
except Exception as e: print(e)
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
ani = FuncAnimation(plt.gcf(), animate, 2000)
|
ani = FuncAnimation(plt.gcf(), animate, 2000)
|
||||||
|
|||||||
Reference in New Issue
Block a user