ch-9 clean

This commit is contained in:
Danny Staple
2022-03-20 22:30:03 +00:00
parent 530f67856d
commit c632222255
13 changed files with 147 additions and 143 deletions
+1 -1
View File
@@ -23,5 +23,5 @@ print("MAC addr:", [hex(i) for i in esp.MAC_address])
# time.sleep(5)
for ap in esp.scan_networks():
print("\t%s\t\tRSSI: %d" % (str(ap['ssid'], 'utf-8'), ap['rssi']))
print("\t%s\t\tRSSI: %d" % (str(ap["ssid"], "utf-8"), ap["rssi"]))
print("Done!")
+4 -5
View File
@@ -5,18 +5,17 @@ from adafruit_wsgi.wsgi_app import WSGIApp
app = WSGIApp()
@app.route("/")
def index(request):
with open("hello.html") as fd:
hello_html = fd.read()
return 200, [('Content-Type',"text/html")], hello_html
return 200, [("Content-Type", "text/html")], hello_html
print("Setting up wifi.")
wifi, esp = robot_wifi.connect_to_wifi()
server = adafruit_esp32spi_wsgiserver.WSGIServer(
80,
application=app
)
server = adafruit_esp32spi_wsgiserver.WSGIServer(80, application=app)
adafruit_esp32spi_wsgiserver.set_interface(esp)
print("Starting server")
+3 -4
View File
@@ -5,16 +5,15 @@ from adafruit_wsgi.wsgi_app import WSGIApp
app = WSGIApp()
@app.route("/")
def index(request):
return 200, [], "Hello world!"
print("Setting up wifi.")
wifi, esp = robot_wifi.connect_to_wifi()
server = adafruit_esp32spi_wsgiserver.WSGIServer(
80,
application=app
)
server = adafruit_esp32spi_wsgiserver.WSGIServer(80, application=app)
adafruit_esp32spi_wsgiserver.set_interface(esp)
print("Starting server")
+3 -3
View File
@@ -54,6 +54,7 @@ send:
assembled = adafruit_pioasm.assemble(program)
class QuadratureEncoder:
def __init__(self, first_pin, second_pin, reversed=False):
"""Encoder with 2 pins. Must use sequential pins on the board"""
@@ -62,10 +63,10 @@ class QuadratureEncoder:
frequency=0,
first_in_pin=first_pin,
jmp_pin=second_pin,
in_pin_count=2
in_pin_count=2,
)
self.reversed = reversed
self._buffer = array.array('i', [0])
self._buffer = array.array("i", [0])
def read(self):
while self.sm.in_waiting:
@@ -74,4 +75,3 @@ class QuadratureEncoder:
return -self._buffer[0]
else:
return self._buffer[0]
+3 -1
View File
@@ -29,6 +29,7 @@ def stop():
motor_B1.duty_cycle = 0
motor_B2.duty_cycle = 0
def set_speed(motor, speed):
# Swap motor pins if we reverse the speed
if speed < 0:
@@ -39,12 +40,13 @@ def set_speed(motor, speed):
speed = min(speed, 1) # limit to 1.0
max_speed = 2 ** 16 - 1
direction[0].duty_cycle = int(max_speed * speed)
direction[1].duty_cycle = 0
def set_left(speed):
set_speed(left_motor, speed)
def set_right(speed):
set_speed(right_motor, speed)
+6 -6
View File
@@ -8,11 +8,13 @@ import robot
app = WSGIApp()
@app.route("/")
def index(request):
with open("sensor.html") as fd:
hello_html = fd.read()
return 200, [('Content-Type',"text/html")], [hello_html]
return 200, [("Content-Type", "text/html")], [hello_html]
@app.route("/sensors")
def sensors(request):
@@ -21,14 +23,12 @@ def sensors(request):
}
robot.left_distance.clear_interrupt()
return 200, [('Content-Type', 'application/json')], [json.dumps(sensor_data)]
return 200, [("Content-Type", "application/json")], [json.dumps(sensor_data)]
print("Setting up wifi.")
wifi, esp = robot_wifi.connect_to_wifi()
server = adafruit_esp32spi_wsgiserver.WSGIServer(
80,
application=app
)
server = adafruit_esp32spi_wsgiserver.WSGIServer(80, application=app)
adafruit_esp32spi_wsgiserver.set_interface(esp)
print("Initialising sensors")
+3 -3
View File
@@ -54,6 +54,7 @@ send:
assembled = adafruit_pioasm.assemble(program)
class QuadratureEncoder:
def __init__(self, first_pin, second_pin, reversed=False):
"""Encoder with 2 pins. Must use sequential pins on the board"""
@@ -62,10 +63,10 @@ class QuadratureEncoder:
frequency=0,
first_in_pin=first_pin,
jmp_pin=second_pin,
in_pin_count=2
in_pin_count=2,
)
self.reversed = reversed
self._buffer = array.array('i', [0])
self._buffer = array.array("i", [0])
def read(self):
while self.sm.in_waiting:
@@ -74,4 +75,3 @@ class QuadratureEncoder:
return -self._buffer[0]
else:
return self._buffer[0]
+3 -1
View File
@@ -29,6 +29,7 @@ def stop():
motor_B1.duty_cycle = 0
motor_B2.duty_cycle = 0
def set_speed(motor, speed):
# Swap motor pins if we reverse the speed
if speed < 0:
@@ -39,12 +40,13 @@ def set_speed(motor, speed):
speed = min(speed, 1) # limit to 1.0
max_speed = 2 ** 16 - 1
direction[0].duty_cycle = int(max_speed * speed)
direction[1].duty_cycle = 0
def set_left(speed):
set_speed(left_motor, speed)
def set_right(speed):
set_speed(right_motor, speed)
+8 -6
View File
@@ -11,16 +11,20 @@ import robot
app = WSGIApp()
class State:
stop_at = 0
state = State()
@app.route("/")
def index(request):
with open("teleop.html") as fd:
hello_html = fd.read()
return 200, [('Content-Type',"text/html")], [hello_html]
return 200, [("Content-Type", "text/html")], [hello_html]
@app.route("/control", methods=["POST"])
def control(request):
@@ -30,7 +34,8 @@ def control(request):
robot.set_left(-movement[1] + movement[0])
robot.set_right(-movement[1] - movement[0])
state.stop_at = time.time() + 1
return 200, [('Content-Type',"application/json")], ["true"]
return 200, [("Content-Type", "application/json")], ["true"]
print("Setting up wifi.")
status_led = DigitalInOut(board.LED)
@@ -39,10 +44,7 @@ status_led.value = False
wifi, esp = robot_wifi.connect_to_wifi()
server = adafruit_esp32spi_wsgiserver.WSGIServer(
80,
application=app
)
server = adafruit_esp32spi_wsgiserver.WSGIServer(80, application=app)
adafruit_esp32spi_wsgiserver.set_interface(esp)
print("Starting server")