Google Ad

Donate to IanJohnston.com using PayPal here, or pledge a donation via Patreon here.
I like creating electronics related YouTube videos. I mostly buy faulty gear from Ebay and make a repair video of it, but it's expensive and so with your help maybe I can continue to do so. Your support would be greatly appreciated.


Project #012 - Home Built Segway

Updated 03/04/12

DISCLAIMER: This design is experimental, so if you decide to build one yourself then you are on your own, I can't be held responsible for any problems/issues/damage/injury that may occur if you decide to follow this build and make one yourself.

My home made Segway is sold!

INTRO

Running about the streets on a Segway looks like fun but what looks even better is an off-road Segway, something with big chunky tyres and the ability to scoot around the forest trails and at speed! There are some terrific video's on YouTube which motivated me, and I've been looking for something substantial to get my teeth into next.

Having completed a small R&D phase building a balancing robot I've been able to test drive the concept in terms of both the hardware & software requirements.
Hardware = Gyro/accelerometer IMU's, PWM & RC Servo based DC motor drive.
Software = Gyro/Accelerometer DAQ, Kalman Filter, PID loop & DC motor control.

This thread will be updated as the project develops.


PARTS LIST

- Jazzy Wheelchair DC motors c/w wheels.
- 2off 12v 20Ah Ritar sealed lead acid batteries (series up to give 24v).
- Sabertooth 2x60amp Motor Driver (RC Servo control).
- Arduino Nano.
- Analogue version = Acc_Gyro: Accelerometer + Gyro IMU (from GadgetGangster).
- Digital version = Sparkfun Accelerator/Gyro SEN-10121.
- LCD = CatsWhisker TextStar P/N=CW-LCD-02/E

 

TECHNICAL - WIRING

Sabertooth 2x60amp Motor Control Board:
PCB Switch:-
Switch 1 = DOWN = sets RC mode
Switch 2 = UP = sets RC mode
Switch 3 = Lithium cut-off = depends on what type batteries you use.
Switch 4 = UP = sets Mixed mode.
Switch 5 = UP = linear responce.
Switch 6 = DOWN = RC microcotroller mode

Terminals:-
S1 = Motor Speed input
S2 = Motor direction input (steering)
 
NOTE:
With my Sabertooth 2x60amp board I found a bug in the firmware;
When power is applied the board defaults to analogue input mode for a second or two before the board powers up properly. This shows up with the motors activating uncontrollably at startup........You can see this in the "First Test Run" video below.
The answer, until the firmware is fixed, is to hold both S1 & S2 at 2.5vdc at startup which is the halt position for the inputs in analogue mode. This is easily done using a couple of resistors on each input, and luckily it doesn't upset the operation of the Arduino.
This problem only appears with the 2x60amp and not the 2x25amp boards.
 
Download a wiring diagram here, it's not 100% complete but does contain the working basics.
 

TECHNICAL - OPERATION

Put the RUN/STOP switch in RUN position and then you step on the footswitch (or vice versa). The LCD will show the balance point......could be -50 all the way to +50 for example.
Move the Segway to the vertical position and as it reaches around 0 (zero) the motors will be enabled. This is a safety interlock to stop the Segway taking-off when you stand on the footswitch.

If you want to make a brand new balance point position you can save to eeprom using the button.
Note: With a brand new Arduino the data saved for the vertical position could be anything/random......so you can hold down the BALANCE ZERO button when you apply power to the system and a nominal value will be written into the eeprom.


TECHNICAL - IMU/ARDUINO - ANALOGUE VERSION

This version uses an analogue IMU communicating to the Arduino via analogue inputs.

3.3vdc must be applied to the Arduino Vref pin.

IMU = Inertia Measurement Unit - ACC_GYRO (GadgetGangster.com/213)
MCB - Motor Control Board
P/B = Push Button
PID = Proportional, Integral, Derivative Loop Control

Arduino I/O:

Analogue Inputs (0-3.3vdc):
A0 - Ax (from IMU - Accelerometer)
A1 - Balance zero potentiometer
A2 - Az (from IMU - Accelerometer)
A3 - Steering potentiometer
A4 - GY4 (from IMU - Gyro)
A5 - P (PID control) potentiometer
A6 - I (PID control) potentiometer
A7 - D (PID control) potentiometer

Digital I/O:
D0 -
D1 - LCD RS232 (Tx)
D2 - Encoder 1 (Motor) - not currently implemented
D3 - Encoder 2 (Motor) - not currently implemented
D4 - LED Red (power up motor drive inhibit)
D5 - LED Yellow (X-axis balance indication)
D6 - Motors enable Run/Stop from relay (footswitch)
D7 - Motors enable Run/Stop toggle switch
D8 - EEprom Save P/B switch
D9 - Buzzer (multi-purpose function, including power up motor drive inhibit indication)
D10 -
D11 - Motor Drive (RC Servo) to Motor Control Board
D12 - Motor Steering (RC Servo) to Motor Control Board
D13 -

 

TECHNICAL - IMU/ARDUINO - DIGITAL VERSION

This version uses a digital IMU communicating to the Arduino via I2C comms.

3.3vdc must be applied to the Arduino Vref pin.

IMU = Inertia Measurement Unit - Sparkfun SEN-10121
MCB - Motor Control Board
P/B = Push Button
PID = Proportional, Integral, Derivative Loop Control

Arduino I/O:

Analogue Inputs (0-3.3vdc):
A0 - D (PID control) potentiometer
A1 - Balance zero set potentiometer
A2 -
A3 - Steering potentiometer
A4 - I2C SDA
A5 - I2C SCL
A6 - I (PID control) set potentiometer
A7 - P (PID control) set potentiometer

Digital I/O:
D0 -
D1 - LCD RS232 (Tx)
D2 - Encoder 1 (Motor) - not currently implemented
D3 - Encoder 2 (Motor) - not currently implemented
D4 - LED Red (power up motor drive inhibit)
D5 - LED Yellow (X-axis balance indication)
D6 - Motors enable Run/Stop from relay (footswitch)
D7 - Motors enable Run/Stop toggle switch
D8 - EEprom Save P/B switch
D9 - Buzzer (multi-purpose function, including power up motor drive inhibit indication)
D10 -
D11 - Motor Drive (RC Servo) to Motor Control Board
D12 - Motor Steering (RC Servo) to Motor Control Board
D13 -


TECHNICAL - ARDUINO CODE

21/01/12 - Current Software Versions:

There are currently two versions, one for the analogue IMU and another for the digital IMU. At the moment both versions have the same level of functionality.

Analogue IMU
Version 1.15
Must use Arduino IDE 0022 (may work with 0023 but definitely not with 1,0 or later).
Download the Segway code here, and it's libraries here.

Digital IMU
Version 2.0 (not yet fully tested/optimized).
Must use Arduino IDE 1.0 (may work with 1.5 but definitely not with 0023 or earlier).
Download the Segway code here and it's libraries here.

Note on installing the Libraries:-
Unzip the library file and copy the two folders to \libraries folder where your Arduino IDE is located. A common problem is the Segway code not compiling properly due to incorrectly installed libraries.

Mods to date since V1.0 (latest towards bottom):
- Added EEprom for saving Balance Zero point.
- Code optimized a bit.
- Ability to force update of EEProm settings (when installing a new Arduino board for example).
- Better audible indication of power-up and aquired balance point.
- Indication on LCD during startup of good balance point before enable motors
- Bug fix on motor output: Torque range is actually -255 to 255.
- Tweaked the ADC clock on the Arduino to speed up AnalogRead's.
- Modified the main loop time, trying out values from 3mS to 20mS.....settled at 5mS.
- Optimized the code a bit in terms of the Control Panel.
- Tweaked the Karmin Filter setting to speed it up significantly.
- Remove the Balance Zero P/B and re-assigned it as EEprom Save.
- Added digital input to monitor external relay/footswitch.
- Added an averaging filter a to help combat oscillations & allow more PID gain.
- Speed up the reading of the sensors.
- Some more optimization & added full speed indication (buzzer).
- Fixed bug in sensor aquisition.
- Created a new digital IMU version 2.0 based on analogue IMU version 1.15. Uses Sparkfun SEN-10121 IMU.

 



VIDEO - (LATEST AT THE TOP)

15/01/12 - Test with large wheels.

With the knobbly tyres she runs a good bit better on the grass (frozen!).

 

YouTube version here.


 

07/01/12 - First back yard test of my Segway!

Still some code tweaks (loop scan time, PID, Kalman filter etc) to do, also some hardware to sort out.
No steering at the moment, the alloy shafted potentiometer broke!

NOTES:
There's a footswitch to enable the 24vdc throughout the system (safety feature) via a large relay, and one bug in the Motor Control Board is that when it powers up one of the motors turns about one wheel rotation, so I'll have to fix that.
The beeping you hear at startup is part of the power up cycle. The motors aren't enabled until the system knows the Segway is upright and at balance point. If it's not then you tilt the Segway back/forward until it is.

One other thing I noticed is that the Steering arm is a bit too far out infront of me so will have to fix that.

 

YouTube version .


 

PHOTOS - METALWORK (LATEST AT THE TOP)

04/06/12 - Orientation of IMU's. Orientated with steering column to front as if standing on Segway.

Analogue IMU:-

 

Digital IMU:


 

12/01/12 - Fitted the wheel adaptors properly today. Aluminium billet cut to size & drilled to allow removal as normal from the outside. M8 steel bolts hold it together so it should be strong enough, and hopefully not too much more stress on the motor shafts.


 

09/01/12 - Test fitted the large wheels today.


 

06/01/12 - The new wheels arrived so a quick photo comparison.

The old & new both weigh exactly the same, 5.2kg so thats a bonus, however, I will need to make up a boss to get them to fit the DC motors.


 

05/01/12 - She's assembled!.........and just awaiting an alloy J/Box to house the electronics.

 

The batteries are fitted underneath via a couple of clamps. The centre of gravity is about as low as I could make it.

 

The potentiometer fitted to the steering arm along with a couple of spring loaded shock absorbers.
Truth be told I'm not impressed with the pot as it's got an alloy shaft. Whilst this will do for now I'd much rather have a steel shafted one so am on the lookout.

 

A heavy duty light action footswitch fitted which will control the master power via a relay.

 

Have ordered these puppies cheap via Ebay. Size = 16" dia, 8" wide. The original wheels are 12" dia, 3" wide.
The hubs look to be around the same mounting, just got the offset to worry about.


 

03/01/12 - Fitted labels to the Control Panel.


 

1/1/12 - Spent New Years Day in the shed!

Made up the T-bar c/w a small control panel. There's a 16x2 LCD, 3off LEDs, PID adjustment pots, balance zero adj. pot and a run/stop switch.
Note: The T-bar is only mocked-up on the base as yet. Still waiting on a long shaft potentiometer arriving for  the T-bar steering.


 

29/12/11 - I've started work on the metalwork with the main platform.

Here's me demo'ing my build so far. A key feature is the low centre of gravity, note the actual platform is below the axles.
Next to do will be to work on the battery mounts (under the base plate) and the T-bar steering mechanism.
(PS. No, the platform isn't bending under my weight.....it's camera lens distortion).

 

The wheelchair motors bolted on. If the truth be told the motors would be better standing upwards, but at this stage I need the space above the motors (via a wee platform) for the batteries, one per side. The electronics will go between my feet in the middle.
The wheels came with the motors and I plan to change them out for slightly bigger more chunky off-road types later on. The good thing is the hubs unbolt from the wheels so should be easy to retrofit on other wheels as and when.

 

Steel box section for the platform all welded up awaiting the 3mm alu plate.

 

Here's a mock of the steering mechanism. The vertical bar will pivot on a potentiometer shaft (long), and the spring return dampers ensure a return to centre. Note: The dampers came from Homebase, some parts I never used when I assembled a large plastic garden box!

 

This is a mock up of the pivot/mounting brackets which will be mounted at the front of the platform. They've still to be bent slightly to have the T-bar lean forward.


 

PHOTOS - IMU/ARDUINO (LATEST AT THE TOP)

26/12/11 - Started the IMU/Arduino board & enclosure.

 

 



PHOTOS/VIDEO - MOTORS (LATEST AT THE TOP)

27/12/11 - First test of the IMU hooked up to the MCB and with a wheelchair motor attached.
I've started to modify the motor drive software so that it's suitable for the MCB since the balancing robot uses a different PWM method of control.

 


 

20/08/11 - Removed the solenoid brake (lock) and revealed a nice shaft from which I can attach a shaft encoder if need be.

15/05/11 - Jazzy 1103 Wheelchair DC motor. The wheel is from the original wheelchair and will do for testing, but the final wheel will have to be wider and chunkier for off-road use.