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