Balancing robot

This is a project that I’ve had on the back-burner for a while, but recently got around to finally 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.

Added some foam to stop him self-destructing when he falls over

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.

A quick render I did when starting out with the body design

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.

I therefore decided to let an Arduino handle the main hardware control loop, and the Pi handle the user controls. This way, the PID loop runs at 200Hz.

Rear of the control board

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. 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.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s