implement basic HTTP API using flask
This commit is contained in:
parent
e117177b9b
commit
3d5a084b47
|
@ -0,0 +1,2 @@
|
|||
|
||||
*.pyc
|
|
@ -0,0 +1,57 @@
|
|||
from telemetrix_rpi_pico import telemetrix_rpi_pico
|
||||
import kuukar_leds
|
||||
import kuukar_collision
|
||||
import kuukar_motion
|
||||
import kuukar_lcd
|
||||
import kuukar_sensors
|
||||
import kuukar_environment
|
||||
from flask import Flask, request
|
||||
|
||||
from kuukar_config import SERIAL_AUX_BOARD, SERIAL_DRIVER_BOARD
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
aux_board = telemetrix_rpi_pico.TelemetrixRpiPico(com_port=SERIAL_AUX_BOARD)
|
||||
driver_board = telemetrix_rpi_pico.TelemetrixRpiPico(com_port=SERIAL_DRIVER_BOARD)
|
||||
sensors = kuukar_sensors.sensors(aux_board, driver_board)
|
||||
leds = kuukar_leds.leds(aux_board=aux_board)
|
||||
lcd = kuukar_lcd.lcd()
|
||||
environment = kuukar_environment.environment(lcd, leds, sensors)
|
||||
collision = kuukar_collision.collision(aux_board, lcd, leds)
|
||||
motion = kuukar_motion.motion(driver_board=driver_board, leds=leds, sensors=sensors)
|
||||
|
||||
|
||||
@app.route('/drive')
|
||||
def drive():
|
||||
speed = int(request.args.get('speed'))
|
||||
motion.drive(speed)
|
||||
|
||||
|
||||
@app.route("/stop")
|
||||
def stop():
|
||||
motion.stop()
|
||||
|
||||
|
||||
@app.route('/turn')
|
||||
def turn():
|
||||
speed = int(request.args.get('speed'))
|
||||
duration = int(request.args.get('duration'))
|
||||
motion.turn(speed, duration)
|
||||
|
||||
|
||||
@app.route('/set_ambient_leds')
|
||||
def set_ambient_leds():
|
||||
r = int(request.args.get('r'))
|
||||
g = int(request.args.get('g'))
|
||||
b = int(request.args.get('b'))
|
||||
leds.set_ambient_led(r, g, b)
|
||||
|
||||
|
||||
@app.route('/set_mode')
|
||||
def set_mode():
|
||||
mode = str(request.args.get('mode'))
|
||||
if mode == "AI":
|
||||
motion.roam_start()
|
||||
elif mode == "MANUAL":
|
||||
motion.roam_stop()
|
||||
|
19
kuukar.py
19
kuukar.py
|
@ -1,19 +0,0 @@
|
|||
from telemetrix_rpi_pico import telemetrix_rpi_pico
|
||||
import kuukar_leds
|
||||
import kuukar_collision
|
||||
import kuukar_motion
|
||||
import kuukar_lcd
|
||||
import kuukar_sensors
|
||||
import kuukar_environment
|
||||
|
||||
from kuukar_config import SERIAL_AUX_BOARD, SERIAL_DRIVER_BOARD
|
||||
|
||||
if __name__ == '__main__':
|
||||
aux_board = telemetrix_rpi_pico.TelemetrixRpiPico(com_port=SERIAL_AUX_BOARD)
|
||||
driver_board = telemetrix_rpi_pico.TelemetrixRpiPico(com_port=SERIAL_DRIVER_BOARD)
|
||||
sensors = kuukar_sensors.sensors(aux_board, driver_board)
|
||||
leds = kuukar_leds.leds(aux_board=aux_board)
|
||||
lcd = kuukar_lcd.lcd()
|
||||
environment = kuukar_environment.environment(lcd, leds, sensors)
|
||||
collision = kuukar_collision.collision(aux_board, lcd, leds)
|
||||
motion = kuukar_motion.motion(driver_board=driver_board, leds=leds, sensors=sensors)
|
|
@ -1,2 +1,3 @@
|
|||
telemetrix-rpi-pico
|
||||
pyaudio
|
||||
pyaudio
|
||||
flask
|
Loading…
Reference in New Issue