This is a project that I’ve had on the back-burner for a while, but recently got around to finishing. It still needs some tuning but it’s getting there.
Since I wanted to be able to control it from my phone, it uses a Raspberry Pi Zero W to handle WiFi communications. For a cheap, easily embeddable linux box with inbuilt WiFi and Bluetooth, there’s nothing like it at less than £10.
To sense the angle of the robot I used an MPU6050, configured to use its internal DMP (Digital Motion Processor) to combine the gyroscope and accelerometer. It spits out the current orientations as quaternions – the maths of which I don’t really understand yet. I just know that I got less noisy results using the internal DMP instead of implementing my own Kalman filter. Thanks as always to Jeff Rowberg and i2cdevlib.
I had initially tried to run the main PID control loop on the Raspberry Pi. However, this proved to be an awful idea, as I couldn’t get anywhere near the loop frequency I needed. Due to the fact that it was running on top of Raspbian, I was struggling to hit 40Hz, and the period between iterations was inconsistent.
Therefore, I decided to let an Arduino handle the main hardware control loop, and the Pi handle the user controls. This way, the PID loop can run at 200Hz.
The system is powered from 2 Li-ion batteries in series. These are USB chargeable with 2 TP4056 boards. The battery voltage is DC-DC bucked down to 5V to power the Pi and Arduino. It also supplies the logic for the A4988 stepper drivers, but the motors themselves run off the battery voltage.
The wheels were kindly 3D-printed by my friend Eric. The enclosure is laser cut from blue acrylic and has a touchscreen for the Pi on the front – I haven’t quite decided what to get it to display yet as it currently just shows the user commands which is a bit boring.
The control “app” (website masquerading as chrome web app) is just a simple joystick with a few buttons. It runs as a lightweight Flask app and uses SocketIO to send the user’s joystick input back to the Pi at 10Hz.