Building an Open Source Self Balancing Scooter

Malcolm Faed malcolm@faed.name



Copyright: This document may only be reproduced with the author’s permission.

Introduction



Obligatory warning. Build this at your own risk. If you injure yourself or any one else its not my fault.







Parts List

Wheels with motors and reduction gearboxes - Electric Wheelchair - AUD$100



12mm Plywood to stand on and to hold the electronics - Free



Batteries (3 x 12 volts) - Free with Wheelchair



PWM motor controller – Locked Anti-phase for 2 motors - AUD$280



Sensors – Accelerometer and Gyro - USD$114.95



CPU – Atmel ATMega16 - AUD$43.76

Firmware from Geoffrey Bennett's Web Site - Free

Schematic- Interconnect Chart



RC Joystick

Misc cable and connectors.



Chassis



http://www.metalite.com.au/ (Russell Cragg)

Old electric wheelchair, cut chassis with grinder cutting wheel to suit

Has 2x 24v motors already conveniently attached.

Batteries



Conveniently from old electric wheelchair

36 volts total

3 x 24ah, 12volt SLA batteries.

Charged in parallel, run in series.

60A circuit breaker doubles as a switch

Position the batteries in such a way that the scooter is naturally balanced when unpowered.



>

Motor Controller



IBC From RoboWars. http://www.robowars.org/store.html

Two x 50Amp MOSFET controllers

Replaced micro with Atmel ATtiny2313 and firmware to give locked anti phase control instead of default RC PWM inout.. (Bascom Firmware Download)



to give locked anti phase control instead of default RC PWM inout.. (Bascom Firmware Download) Low dropout switching regulator

Regenerative braking (inherent from locked anti phase motor control)

Australian design and open source

Microprocessor



Atmel ATMega16

8 bit

16k Flash

8MHz Clock

512 Bytes EEPROM

JTAG

ISP

3 Timer – Counters

8 channel 10 bit a-d

Hardware USART

32 IO lines

Many other features

Development in AVR-GCC

Prototype board from http://www.futurlec.com.au





Sensors





ADXL203 Precision ±1.7 g Single/Dual Axis Accelerometer 1 v/g



ADXRS401 ±75°/s Single Chip Yaw Rate Gyro with Signal Conditioning

Software



Developed with AVR-GCC

Reads the analogue inputs

Drive the motors

Read from RC receiver

Write and read the serial port for logging and tuning

Download source from Geoffrey D Bennett’s web site

Balancing



If the robot is leaning, drive the wheels in the direction of the lean

f you lean more, go faster

This is a control systems problem:

input variable is the platform angle



output variable is motor speed (PWM). 50% duty cycle is stationary.



by controlling the motor speed and direction, keep the platform horizontal

Attempt to keep the platform angle zero

output = Kp x input + Kd x input’ + Ki x input dt



Proportional — if you lean more, go faster



Derivative — if you lean quickly, go faster



Integral — if you’re still leaning, go faster

Turning

Joystick for input (also RC)

Speed up one wheel one wheel

Slow down the other wheel.

by the same amount, to maintain balance!

Turn faster when stationary. Turn slower when traveling.

Accelerometer and gyro must be in center between the wheels otherwise it senses turning as tipping.

Measuring the platform angle



The Gyro input gives the angular rate but it drifts a lot

input gives the angular rate but it drifts a lot The Accelerometer input gives the acceleration due to gravity and due to the scooter accelerating

input gives the acceleration due to gravity and due to the scooter accelerating When the scooter is not accelerating, the inverse-sine of the accelerometer input gives us angle

This isn’t very precise



It is susceptible to vibration



But it doesn’t drift

How to combine them?

The Gyro input averaged over time should be zero



This lets the software adjust for drift



We assume gyro starts off stationary



We assume initial angle is given by the accelerometer



Track angle changes with the gyro



If the tracked angle is different to the angle from the accelerometer, track towards it slowly



Subtract any acceleration force we apply to the motors from the accelerometer reading



When moving, rely less on the accelerometer reading



sin(x) ~ (for small x) This omits the need for Trigonometry in the software.



Over Speed



At some point, the motors can’t go any faster

Then you fall, because the wheels can’t keep up with you

Solution: before that happens, “push back” on the rider by making the wheels go even faster

Misc.



Soft Start

In the first few seconds of running, slowly ramp up to avoid lurching.

Voltage Reference - ADXRS401 has a 2.5V precision output

Used to measure regulator voltage and scale inputs appropriately

Use a-d to measure battery voltage and scale outputs appropriately to compensate for discharging battery

Tuning

Uses Perl-GTK on Linux with graphical UI in Linux from Geoffrey Bennett.



Tipped

If the platform angle is “too large”, shut down

(Adapted from Geoffrey D Bennett presentation)

Future Improvements



Better Heat sink for MOSFETs

Over current monitoring (LED)

Low battery voltage warning (LED)

Detect when rider not present / Present and adjust balance parameters accordingly

If the kill or dead-man switch is tripped, shut down

Links, credits and inspirational people.

This project would not have been possible without the assistance of the following people.

Geoffrey D Bennett – for the source code and tuning software

http://www.netcraft.com.au/geoffrey/meta

Trevor Blackwell

http://www.tlb.org/scooter.html



