Control a RaspberryPi Robot using Python and a mobile browser

Usually I use some physical buttons or joystick attached to my electronics in order to quickly test or control components like motors, relais or LEDs. I was searching for a better way, but could not really find one. In this article, I describe how I built a RESTful webserver with websockets, and a javascript-based based interface in form of a website. That way, any linux-based robot-controller can be controlled using a cellphone or a tablet. The code needed can be found here: https://github.com/TobiasWeis/robotcontrol-javascript

Interactive, low-latency javascript-based websocket-GUI for touch-devices with a python-flask backend that interfaces to robotic components. It provides virtual 2-axis joysticks (inspired by nipple.js but without the multitouch issues) and buttons that all work simulatenously. Due to the two-way websocket connection, status-messages from the robot can be displayed in the text-area.

After several iterations I arrived at below, simple architecture. The core is our flask-server (server-websocket/main.py). This both serves the website, and has endpoints for the websocket connection to this website. The robot-modules (currently controllers for actuators like stepper- and servo-motors, as well as two toggles for LEDs) are located in the ./robot folder. Each of these is a separate multiprocess and communicates with the server using multiprocess.queue.

The schematic of the used hardware is below. It consists of a RaspberryPi 3 B+, an A988 stepper driver carrier (https://www.pololu.com/product/1182), a Nema14 stepper motor, a 9G mini servo motor, a slightly bigger no-name servo (Sportline Sport Best.Nr.313-0001), and two LEDs.

TobiasWeis | 22. Juli 2018

Leave a Reply