Balancing robot

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.

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.

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.

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

2 thoughts on “Balancing robot

  1. Hi Ben,
    “It still needs some tuning but it’s getting there” – What do you mean ? It runs so smoothly 😀 – quite envious.

    I have been fiddeling with a similar robot for some time .. well until I lost my temper and put it in a corner, from where it now sits and glares at me. 😦

    They’re actually rather similar, except instead of an Arduino I’m using a PSoC. And instead of remote control its supposed to be more or less autonomous and should either follow an object (say a hand for instance) or avoid objects, using ultrasonic sensors.

    I know it might be a big ask, but if you dont have anything against it, I’d love to see your implementation on both arduino and Pi. Is that something you’d consider to allow ?

    Thank you in advance.


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 )

Connecting to %s