Compare commits
5 Commits
f158e61439
...
c85b45caea
| Author | SHA1 | Date |
|---|---|---|
|
|
c85b45caea | 5 years ago |
|
|
3cb3e52790 | 5 years ago |
|
|
f6f1d09ab4 | 5 years ago |
|
|
4d77cd47fd | 5 years ago |
|
|
2a8e794741 | 5 years ago |
@ -0,0 +1,62 @@
|
|||||||
|
import time
|
||||||
|
from simple_pid import PID
|
||||||
|
from itertools import count
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from matplotlib.animation import FuncAnimation
|
||||||
|
|
||||||
|
import minimalmodbus
|
||||||
|
|
||||||
|
tempSens = minimalmodbus.Instrument('/dev/ttyUSB1', 1)
|
||||||
|
tempSens.serial.baudrate = 38400
|
||||||
|
|
||||||
|
OutputDriver = minimalmodbus.Instrument('/dev/ttyUSB1', 1)
|
||||||
|
OutputDriver.serial.baudrate = 38400
|
||||||
|
|
||||||
|
pid = PID(10, 0.01, 0.1, setpoint=100)
|
||||||
|
|
||||||
|
plt.style.use('fivethirtyeight')
|
||||||
|
|
||||||
|
x_values = []
|
||||||
|
y_values = []
|
||||||
|
|
||||||
|
index = count()
|
||||||
|
|
||||||
|
|
||||||
|
def animate(i):
|
||||||
|
try:
|
||||||
|
temp = tempSens.read_float(1, functioncode=4, byteorder=0)
|
||||||
|
y_values.append(temp)
|
||||||
|
x_values.append(next(index))
|
||||||
|
#print(temp)
|
||||||
|
print(tempSens.read_float(11, functioncode=4, byteorder=0))
|
||||||
|
|
||||||
|
# print(temp, end='\t')
|
||||||
|
# control = pid(temp)
|
||||||
|
# if(control>100):
|
||||||
|
# control = 100;
|
||||||
|
# control = (control/1000.0)
|
||||||
|
# if(control < 0):
|
||||||
|
# control = 0
|
||||||
|
# print(control, end='\t')
|
||||||
|
# print(0.1-control)
|
||||||
|
#
|
||||||
|
# if(control > 0):
|
||||||
|
# OutputDriver.write_bit(0, 1, functioncode=15)
|
||||||
|
#
|
||||||
|
# time.sleep(control)
|
||||||
|
#
|
||||||
|
# if(control<0.1):
|
||||||
|
# OutputDriver.write_bit(0, 0, functioncode=15)
|
||||||
|
#
|
||||||
|
# time.sleep(0.1-control)
|
||||||
|
|
||||||
|
plt.cla()
|
||||||
|
plt.scatter(x_values, y_values)
|
||||||
|
except Exception as e: print(e)
|
||||||
|
|
||||||
|
|
||||||
|
ani = FuncAnimation(plt.gcf(), animate, 2000)
|
||||||
|
|
||||||
|
|
||||||
|
plt.tight_layout()
|
||||||
|
plt.show()
|
||||||
Loading…
Reference in New Issue