So I’m trying to understand why this code doesn’t work. I’m using a Raspberry Pi with Python SDK and trying to create a web-based interface so someone can control the RVR from a web browser. I’ve tried this using both Flask and Bottle and it works, but only one time. In other words, the first time I load the web page, it drives the RVR, but no more times after that. If I start and restop the script, it may or may not work until I reboot the Pi.
This makes no sense at all.
from bottle import Bottle, run from sphero_sdk import SpheroRvrObserver from time import sleep robot = SpheroRvrObserver() app = Bottle() left = 270 right = 90 forward = 0 backward = 180 def move(seconds, myspeed, myheading): robot.wake() sleep(2) robot.drive_control.reset_heading() robot.drive_control.drive_forward_seconds( speed = myspeed, heading=myheading, time_to_drive=seconds ) robot.close() @app.route('/') def forward(): move(2, 10, 0) sleep(1) return 'Moving forward' run(app, host='0.0.0.0', port=8080)