Level down clean up
This commit is contained in:
parent
b595f3be54
commit
929f36dc8c
@ -4,7 +4,7 @@ import requests
|
|||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
from matplotlib.animation import FuncAnimation
|
from matplotlib.animation import FuncAnimation
|
||||||
|
|
||||||
url = 'http://192.168.1.128'
|
url = "http://192.168.1.128"
|
||||||
|
|
||||||
|
|
||||||
class SensorStream:
|
class SensorStream:
|
||||||
@ -19,7 +19,11 @@ class SensorStream:
|
|||||||
def sensor_stream(self, frame):
|
def sensor_stream(self, frame):
|
||||||
try:
|
try:
|
||||||
response = requests.get(url, timeout=1)
|
response = requests.get(url, timeout=1)
|
||||||
except (requests.exceptions.ConnectTimeout, requests.exceptions.ReadTimeout, requests.exceptions.ConnectionError):
|
except (
|
||||||
|
requests.exceptions.ConnectTimeout,
|
||||||
|
requests.exceptions.ReadTimeout,
|
||||||
|
requests.exceptions.ConnectionError,
|
||||||
|
):
|
||||||
print("Waiting...")
|
print("Waiting...")
|
||||||
return
|
return
|
||||||
print(f"Content: {response.content}")
|
print(f"Content: {response.content}")
|
||||||
@ -28,11 +32,11 @@ class SensorStream:
|
|||||||
item = response.json()
|
item = response.json()
|
||||||
|
|
||||||
print(f"Received: {item}")
|
print(f"Received: {item}")
|
||||||
if self.times and item['time'] < self.times[-1]:
|
if self.times and item["time"] < self.times[-1]:
|
||||||
self.reset()
|
self.reset()
|
||||||
self.times.append(item['time'])
|
self.times.append(item["time"])
|
||||||
self.error_values.append(item['last_value'])
|
self.error_values.append(item["last_value"])
|
||||||
self.pid_outputs.append(item['pid_output'])
|
self.pid_outputs.append(item["pid_output"])
|
||||||
|
|
||||||
if len(self.times) > 100:
|
if len(self.times) > 100:
|
||||||
self.times = self.times[-100:]
|
self.times = self.times[-100:]
|
||||||
@ -44,7 +48,7 @@ class SensorStream:
|
|||||||
plt.plot(self.times, self.error_values, label="error")
|
plt.plot(self.times, self.error_values, label="error")
|
||||||
plt.plot(self.times, self.pid_outputs, label="pid")
|
plt.plot(self.times, self.pid_outputs, label="pid")
|
||||||
|
|
||||||
plt.legend(loc='upper right')
|
plt.legend(loc="upper right")
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
# Create the animation. GFC - get current figure. random_stream - callback func.
|
# Create the animation. GFC - get current figure. random_stream - callback func.
|
||||||
@ -52,4 +56,5 @@ class SensorStream:
|
|||||||
plt.tight_layout()
|
plt.tight_layout()
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
SensorStream().start()
|
SensorStream().start()
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import requests
|
|||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
from matplotlib.animation import FuncAnimation
|
from matplotlib.animation import FuncAnimation
|
||||||
|
|
||||||
url = 'http://192.168.1.128'
|
url = "http://192.168.1.128"
|
||||||
|
|
||||||
|
|
||||||
class SensorStream:
|
class SensorStream:
|
||||||
@ -19,7 +19,11 @@ class SensorStream:
|
|||||||
def sensor_stream(self, frame):
|
def sensor_stream(self, frame):
|
||||||
try:
|
try:
|
||||||
response = requests.get(url, timeout=1)
|
response = requests.get(url, timeout=1)
|
||||||
except (requests.exceptions.ConnectTimeout, requests.exceptions.ReadTimeout, requests.exceptions.ConnectionError):
|
except (
|
||||||
|
requests.exceptions.ConnectTimeout,
|
||||||
|
requests.exceptions.ReadTimeout,
|
||||||
|
requests.exceptions.ConnectionError,
|
||||||
|
):
|
||||||
print("Waiting...")
|
print("Waiting...")
|
||||||
return
|
return
|
||||||
print(f"Content: {response.content}")
|
print(f"Content: {response.content}")
|
||||||
@ -28,11 +32,11 @@ class SensorStream:
|
|||||||
item = response.json()
|
item = response.json()
|
||||||
|
|
||||||
print(f"Received: {item}")
|
print(f"Received: {item}")
|
||||||
if self.times and item['time'] < self.times[-1]:
|
if self.times and item["time"] < self.times[-1]:
|
||||||
self.reset()
|
self.reset()
|
||||||
self.times.append(item['time'])
|
self.times.append(item["time"])
|
||||||
self.error_values.append(item['last_value'])
|
self.error_values.append(item["last_value"])
|
||||||
self.pid_outputs.append(item['pid_output'])
|
self.pid_outputs.append(item["pid_output"])
|
||||||
|
|
||||||
if len(self.times) > 100:
|
if len(self.times) > 100:
|
||||||
self.times = self.times[-100:]
|
self.times = self.times[-100:]
|
||||||
@ -44,7 +48,7 @@ class SensorStream:
|
|||||||
plt.plot(self.times, self.error_values, label="error")
|
plt.plot(self.times, self.error_values, label="error")
|
||||||
plt.plot(self.times, self.pid_outputs, label="pid")
|
plt.plot(self.times, self.pid_outputs, label="pid")
|
||||||
|
|
||||||
plt.legend(loc='upper right')
|
plt.legend(loc="upper right")
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
# Create the animation. GFC - get current figure. random_stream - callback func.
|
# Create the animation. GFC - get current figure. random_stream - callback func.
|
||||||
@ -52,4 +56,5 @@ class SensorStream:
|
|||||||
plt.tight_layout()
|
plt.tight_layout()
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
SensorStream().start()
|
SensorStream().start()
|
||||||
|
|||||||
@ -6,9 +6,9 @@ motor_A2 = pwmio.PWMOut(board.GP16)
|
|||||||
motor_B1 = pwmio.PWMOut(board.GP18)
|
motor_B1 = pwmio.PWMOut(board.GP18)
|
||||||
motor_B2 = pwmio.PWMOut(board.GP19)
|
motor_B2 = pwmio.PWMOut(board.GP19)
|
||||||
|
|
||||||
|
|
||||||
def stop():
|
def stop():
|
||||||
motor_A1.duty_cycle = 0
|
motor_A1.duty_cycle = 0
|
||||||
motor_A2.duty_cycle = 0
|
motor_A2.duty_cycle = 0
|
||||||
motor_B1.duty_cycle = 0
|
motor_B1.duty_cycle = 0
|
||||||
motor_B2.duty_cycle = 0
|
motor_B2.duty_cycle = 0
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user