Self Balancing One Wheeled Electric Skateboard
by XenonJohn in Outside > Skateboarding
148431 Views, 493 Favorites, 0 Comments
Self Balancing One Wheeled Electric Skateboard
NOTE:
May 2011: This instructable is now quite old (relatively) and I could now rebuild this project more simply with an Arduino as the controller.
I am currently working on a unicycle with the same OSMC motor controller and an Arduino. When I get that to work I will also add the code to this instructable as the principles will be almost the same (one wheel one motor).
NOTE 2016: All my self balancing projects are now also documented on my Youtube channel here: Click
NOTE Jan 2013: I now have WORKING ARDUINO CODE that works well with an OSMC. The main points are outlined here:
https://sites.google.com/site/onewheeledselfbalancing/Home/twin-wheel-self-balancing-skateboard-lightweight-version/code4
JUNE 2014: I am entering the Hackaday Competition with Nick Thatcher and another friend. The entry is the Medicycle, yes it will have one wheel and yes it will be really cool. Best project yet hopefully. If you want to follow us, and we would very much like you to, here is the link:
http://hackaday.io/project/1156-Medicycle---Urban-...
After reading a Make magazine article on the self balancing unicycle of Trevor Blackwell I thought about trying to build a one wheeled skateboard style device. I then found a self balancing skateboard on the net built by Ben Smithers and decided I would definitely have a go at this.
For more information and pictures of my earlier designs please go to:
http://sites.google.com/site/onewheeledselfbalancing
Also:
Trevor Blackwell unicycle and SegwayTM clone: http://tlb.org/scooter.html
Ben Smithers skateboard which inspired me to build this one:
http://www.youtube.com/watch?v=HGbbag9dklU
Also check out this self balancing unicycle:
http://www.enicycle.com/media.html
and this video of same machine from the Gadget Show (wait for the sponsor message to pass)
http://fwd.five.tv/gadget-show/blog/anywhere-anytime-enicycle
Also, many people have tried to build self balancing robots with 2 wheels. There are many on the web. If you do this using a gyroscope, accelerometer, microcontroller and geared motors from a robotics store, you will spend almost the same amount of money as this machine cost to make. The mechanical parts are kart based and often available on ebay. Some robotics mechanical parts are pretty expensive. I thought if I was going to do the "self balancing" thing then I might as well make a robot I could ride!
VIDEO 3/1/09 below.
Video shwing stability and ability to cope with small obstacles. I have since lowered the ride height to make it more controllable in terms of steering at speed.
This is the latest (March 09) lighter weight version with same power as the monowheel but split between 2 motors + same battery power using lighter LiFePO4 battery. Now based on a real skateboard and has 2 wheels so can turn on the spot. Also only 30lb so you can pick it up easily:
Intro (2)
Parts and Resources Guide
1) Control system: ATmega32 controller on a development board. This is one of a family of processors made by Atmel called the AVR series. The ones from robot project suppliers are ideal:
http://www.active-robots.com/products/controllr/active-boards.shtml
Note the "AVR isp downloader" on the same page. Get this to allow you to transfer your program from your PC to the microcontroller. Software comes with these on a CD. Google "AVRStudio4" and download a free copy of the software from Atmel website that you will run on your PC to write the program whic you will eventually transfer to the memory of your AVR microprocessor.
2) A solid state accelerometer and solid state gyroscope. Since I built the project, they can now be both obtained pre-soldered to a board. This is what I would use if doing it again:
IMU Combo Board - 2 Degrees of Freedom - ADXL320/ADXRS150
http://www.active-robots.com/products/sensors/sparkfun/imu-gyros.shtml
The accelerometer I actually used was:
Accelerometer Interface Board ADXL202JE �un)
and the gyro I actually used was the Silicon Sensing Systems CRS-03 gyro: http://www.siliconsensing.com/CRS03packaged
3) Motor. This is the motor I used, 24Volt 420 Watt. It was a reasonable price but quite heavy. There are others with better power and lighter weight (but cost more) also cheaper ones from China on ebay for electric scooters (google "electric scooter motor" and you will find a selection of alternatives). My motor was the 2.8Nm one at the bottom of this page:
http://www.motioncontrolproducts.co.uk/index.php?cPath=25&osCsid=1905800baa1799fc97c0a97697db22fa
4) Motor controller. Takes signals from microcontroller and uses them to control how much power it transmits from batteries to motor. Has to be capable of handling high currents. Several exist for control of heavyweight combat robots (google around the "robot wars" type websites and you will see what I mean). The OSMC one I used is high power, has extra circuits to stop you breaking it, and is actually a reasonable price for the current it can handle (it still is not exactly cheap though)- see the OSMC towards the bottom of this page:
http://www.robotpower.com/catalog/
5) When you buy the motor, you need to look at the diameter of the spindle. Over this spindle you need to fit a small sprocket (wheel with teeth for a chain to go around). I knew nothing about karting before I built this, this is what the internet is for, finding out the things you do not know. I found (one of many) kart spares websites and I ordered a sprocket with as few teeth as possible to fit my particular motor spindle diameter:
Azusa engineering in the US do about every sprocket size and spindle size imaginable: http://www.azusaeng.com/Sprockets/AzSDno219.pdf
6) Chain: I used 219 chain, this is a thin chain size more often used in karts in Europe than the US. There are others that in the US might be easier to get. If you put 219 kart chain into ebay you will find loads of suppliers. To shorten it to the length you want, take it your local bike shop, they do this all the time.
7) The big sprocket on the main axle: Any online kart shop sells these in many sizes. They bolt to a standard sized carrier (the red thing in centre of my axle in following photos) with 6 bolts. Therefore you can buy a few different diameter sprockets and experiment. Just one sprocket carrier will do for all of them. These are example links only:
Big sprockets for 219 chain: http://www.talon-eng.co.uk/talon-karts.asp?c_urn=&bike=&show=
Sprocket carrier for 30mm axle: http://cgi.ebay.co.uk/ws/eBayISAPI.dll?ViewItem&item=280227333529&cguid=d7fe085c11c0a0aad24491c4ffeeb887
Bear in mind karts have axles in various diameters. You might well choose a smaller diameter axle. The only reason I chose 30mm was that I managed to buy a single kart wheel second hand on ebay and it happened to have a 30mm axle requirement.
8) Wheel: Biggest rear kart wheel you can find on ebay or kart shop in your town: Example: http://www.kartingnortheast.com/kart-shop/wheels-tyres-and-accessories.htm
These are UK examples but there are online karting shops in the US too. For one single wheel I would definitely try ebay. You do not need the latest magnesium wheel hub, just a cheap battered used one will do fine.
9) Get a kart axle, about $40 online. Diameter does not matter just make sure it is same as the hub for your wheel and the sprocket carrier is also designed for the same diameter axle. This can all be done via the net and ebay. Do an afternoons worth of research online, find best suppliers and prices in your area, then order everthing so they all match up as a set.
10) Finally you need bearings for your lets us say 30mm axle. Example of a US supplier who could probably supply you with all you need (cheaper to root around on ebay though):
http://www.mfgsupply.com/GoMiniAxlesKits.html
11) Laser cut steel side panels: First of all you can do this just as well with a hacksaw but it will require more effort! Any machine shop near you can copy a cardboard template for you in steel. Offer to pay cash. Another option is to go to a metal sheet supplier and offer them cash for their offcuts lying in a heap behind their big sheet cutting machines. Take home a few sheets and experiment.
Failing everything, mock up your entire frame in cardboard, take it to a metal fabrication business ( the sort of company that make steel shelving etc and advertise in local directories) and simply ask if they can copy it for you in sheet steel. Again offer some cash. Don't be afraid to look silly, otherwise you never learn anything.
12) Batteries. Mine were lead-acid 12V each, 12 Amp-hour. However have a read about big motors and big batteries for combat robots here and work out which combination would be best for you (and your wallet):
Here is a link to a US website/shop which has loads of info on battery packs, motors etc for large combat robots - read and learn:
http://www.robotcombat.com/products/batteries_battlepacks_nimh.html
13) Don't know how to program in "C" or how to program a microcontroller? Well neither did I. Check out the links to other projects on my website (link on page 1 of this instructable). Some have downloadable code - study it. For free downloadable tutorials on "C" hit the web again. Here is one example: http://winavr.scienceprog.com/short-introduction-to-c/
This website is also one of many on so called "AVR programming" i.e. how to program the Atmel series of AVR processors, of which the ATmega32 is but one. There are forums (full of robot builders) for AVR programming. e.g. "AVRFreaks" for example.
On page 1 of this instructable you will find a link to my website. this site has links to every segwayTM clone others have built, self balancing model robots, other skateboard projects from around the world and some unicycle designs. Each of these sites has more information you can dig into. I have also described my (imperfect) software with explanatory notes on what each line of code is for. Some of the fixes I suggest took me weeks to solve. I have saved you hours and hours of stress! This site represents months of research on the web. It may not contain everything you need but I humbly suggest it will give you a very good start. This instructable is intended as a guide to get you past a few of the main stumbling blocks and blind avenues that kept me puzzled for very long periods. It is not a nut and bolt guide otherwise it would have 200 pages. It is however probably one of the best guides to DIY one wheeled vehicles out in the ether so far.
You almost certainly will NOT have all the skills at present you need to build this project. Few people if any have ever been "formally" trained in ALL of; i) Metalwork, ii)Mech engineering, iii)Electrics iv)Electronics (v) Microcontroller programming, vi) "C" programming. I am not an engineer of any type and am not a computer programmer. If your deficiencies put you off at this early stage then do not bother. On the other hand I work by the maxim that "anyone can learn anything to a basic standard after about 50 hours of work" if you believe this to be true then you can do this project and it will also help you in life. This project will stretch your mind and patience. Are you someone who gets things done or one who says "I could have done this if only for X or Y"? I am not saying this is easy by any means but do not give up because there is some aspect you do not (yet) understand......hit the internet and find out. That is what it is there for. If you are good at the mechanical side you may have no idea how to program the microcontroller and those who may find the programming dead easy may struggle with the mechanical parts. This is why it is such a good challenge and why colleges sometimes get groups of students, rather than individuals, to build segwaysTM copies as projects.
Break the task down into smaller sections and have a go. The cost can be spread because this will take weeks or months to complete if just using odd periods of spare time.
Best of luck, have a go!
Overview
From right to left: Box containing an Atmel ATmega32 microcontroller (small computer in a chip), plus an accelerometer, plus a solid state gyroscope. This takes voltage inputs from accel and gyro then decides how much power to send to motor to keep level if tipping over. A signal is sent to a motor controller in box on far left, which then sends the appropriate amount of power to the motor (to right of the central wheel). Motor is 420W golf cart motor and drives wheel by a chain. Wheel is widest available kart rear wheel that is sold.
First Step Metalwork and Construction
I started by mocking up the 2 steel side panels in cardboard. Although these were made as shown in the image initially, I later removed the raised sections at each end to permit a flat deck across the top.
Note regarding batteries: Lithium batteries give most power for their size and weight followed by Nickel Hydride followed by lead-acid. I used lead acid batteries because (a) cheap, (b) can give large current for small periods if needed when hitting obstacle for example, (c) complex chargers not required.
Fabrication
The red object is a carrier for the big sprocket (toothed wheel) that will attach to the axle of the main wheel. Wheel, chain, sprockets, go kart axle all acquired cheap or second hand from ebay. Note: These projects work much better if there is an EXCESS of power in reserve. Use a motor bigger than you think you might get away with. If computer "tells" motor to deliver more power quick as falling over, you want it to react instantly without struggling in any way. False economy to under power your vehicle.
Fabrication
I used a 30mm axle but other sizes exist for karts. Make sure your sprocket carrier, wheel mounting, bearings etc are all correct for your chosen axle size before you buy them!
Fabrication
Once top deck bolted down this will also add strength.
Fabrication
One side of the chassis is rivetted on while the other is held on by lots of small nuts and bolts. This allows one side to be removed in about 10 minutes to get at axle components etc later (or indeed to inflate the tire).
Fabrication
The high gear ratio means that the board will not go too fast while I am learning to ride it and it will go up hills. The way to burn out a motor controller is to stall the motor. The computer will tell the controller to put full power through to the motor, this is fine for short burst but not if motor unable to turn, i.e respond, because wheel is stuck against an obstacle for any length of time. As well as having biggest motor you can fit, you need a beefy motor controller to cope with it too.
Control System
To get my head around the microcontroller and interfacing it to the accelerometer, gyro and motor controller I temporarily mounted them onto a piece of wood which also had a plug in development board on it for testing various wiring arrangements. Also, by tilting the wooden base, it was then easy to test out various gyro/accelerometer software responses, simulating movement of the finished skateboard.
Control System
Control System
Control System
For more on computer code consult my website (see link on page 1). Briefly, the ATmega32 is programmed via a serial cable from your PC. Software written in "C" and compiled using "AVRStudio4" which can be downloaded for free. This converts it to a form in which it can be sent to the little computer on the microcontroller board where it then sits in its memory, even when skateboard is turned off. The software that was actually used to load it from PC to the microcontroller board was called "PonyProg" and is again a general purpose program designed to do this job. It took me ages to get this worked out but only because I was new to all this. The info is all on the web, but to save you weeks of stress I have collected them all in a links page on my website.
Control System
Control System
Again, see my website (link on page 1) for more info on control software principles etc.
The basic idea is this:
gyroangledt=amount of tilt from gyro since last reading was taken
newangle(of tilt from vertical)=(0.99*(oldangle+gyroangledt)) + (0.01 * accelerometerTilt)
This gives the new angle of tilt from vertical. Note how 1% of accelerometer signal is inserted each time with 99% of the gyro-derived short-term angle change calculation. This smooths out variations in accelerometer reading with time (averages out the noise so it self cancels), slowly corrects any zero-point drift in the gyro BUT still allows the gyro to handle the instantaneous short term changes in tilt.
linearvelocity = linearvelocity + (0.00004*angle)
This means "are we STILL tipping?" and if so slowly increase power to the motor. This is how you control the speed manually; if you keep the board continually tilted, it will slowly accelerate in the direction you are tilting it.
level=((k1*angle) + (k2*anglerate) + linearvelocity) * overallgain
"anglerate" is from gyro i.e. is the immediate short term "rate of tipping"
Level controls POWER to be sent to motor (the PWM duty cycle).
k1 is about 4.5
k2 is about 0.5
Overallgain is just that - sort of an "accelerator" knob on control panel - if set too low board feels sloppy, too high and it oscillates wildly!
Finally, the whole thing only works because this program is looping about 100 times per second.
Control System
It is very easy to wire up and/or mount your gyro and accelerometer back to front making motor behave in mysterious ways. This is why it is worth working out such simple "bugs" before putting it all into the frame.
Here we have the microcontroller in the box on top left with plug on side to allow it to be reprogrammed while in the frame, gyro and accelerometer in small box and OSMC in grey box.
For early testing I made a hand controller which had potentiometers for K1, K2, program cycle time interval, overallgain so I could, by manually changing voltages from 0-5V being sent to the microcontroller inputs, manually control the key parameters in the balance algorithm while actually riding the board.
Control System
Control System
The problem with my very clever hand controller was that it was too complex. With a 10 core cable to the board, display LED's (top) etc there was just too much to go wrong with real world use. Therefore after using this to develop the algorithm I removed it and replaced it later with a much simpler control unit that just had one single potentiometer for "overallgain" and a dead-man cut-out button only. The other variables were hard coded into the software.
Final Assembly
Left to right: OSMC, Motor, Wheel, 2 Batteries, Box with microcontroller + gyro + accelerometer in it.
Note frame now modified to take a flat wooden deck.
Final Assembly
This is an early effort at packaging the internals, where the smaller original batteries were used.
Battery connections soldered (use big soldering iron or two normal ones together). If a battery connection comes loose while whizzing along, you will know it as machine stops dead and you keep moving.
There is enough to worry about with software glitches early on without having unreliable electrical connections on top. Try to construct everything so connections are reliable, cannot be pulled loose etc.
Final Assembly
Final Assembly
Final Assembly
Final Assembly
You can also see a foot grip (as found on kiteboards) to help control when you are riding it. You steer by tilting board to one side and deforming the tire. The footgrip helps you do this. It also stops you sliding off when it is tilted when you first start to ride it. This grip is set to a loose grip as if I fall off I do not want my ankle broken (think of skis).
I had a rounded surfboard style top originally but this new angular one matches the angularity of the metal frame better.
The main (high current) on/off switch simply connects the two batteries together in the middle as they are wired in series.
When off they are therefore disconnected from each other so allowing each battery to be separately charged from a 12V (not 24V) charger.
There is also an LED battery charge indicator you can see glowing as a row of red/green LED's protected by a clear polycarbonate cover. This gives a rough idea of how much power you have left in the batteries and is simple to wire up. They come from a robotics kit supplier in 12V, 24V, 36V forms.
Final Assembly
Top deck is made from quite thin marine ply. This is good because, low weight, stiff, electrical insulator (stops batteries shorting out with metal deck), adds extra stiffness to overall structure as bolted down all the way around with very small nuts and bolts.
Final Assembly
You might think it would just tip over and stop on anything other than a smooth surface. This was true early on when just getting it to balance was the overriding issue.
However now it will easily go over a 1 inch high obstruction and stay level. Have not tested it with anything larger yet. The term in the equation "how fast am I tipping?" from the gyro, goes very high very fast as soon as you meet an obstacle. The power to the motor then also goes very high very fast. Assuming you have the power excess I spoke of earlier plus a hefty power controller, then the board will do a slight wobble and just power over the obstruction. The response time in this circumstance obviously needs to be very short, which is another reason why you need the program to loop at 100 times per second. It would otherwise probably balance OK on level ground if looping slower than this, say 25 times per second.
The term that asked "are we STILL tipping?" is what makes it move along: If you deliberately hold the board tipped, this term will slowly increase like an accelerator, moving you along. The thing on the far end is an LED headlight.
Video (slightly Old)
Here is an old video taken when the machine first balanced last summer (2008). The new machine responds a lot faster and stays level. The latest video is on the first page.
Have Fun!
Teenagers may scoff that you cannot do "tricks" with it but that is not the point. This is always going to be a heavy machine. The point is the challenge and satisfaction of getting something "impossible" to work, the skills I have learned along the way and simply doing something completely out of the ordinary.
When you finally get it to balance after struggling away for ages there is a real feeling of achievement.
It is also great fun to ride. This is hard to explain in words but it feels as if you are riding on something that is "alive" and constantly intelligently adapting to your input rather than following it blindly. It should do about 7 or 8 mph in this configuration. When I am confident enough I will fit a smaller sprocket on the main axle (karts come with multiple sprocket sizes) to increase the speed. You steer it by the way by tilting it to one side, the tyre deforms and you gradually turn. To turn sharply, you stop or slow right down, tilt onto tyre edge and twist body to flick it round.
Remember if you build one of these it is at your own risk. There are no safety features or redundant sytems as in a SegwayTM for example. However one advantage over a SegwayTM clone may be that you can easily jump off, especially if you keep the top speed down early on while you are learning.
Have fun! You will never learn anything practical or innovative unless you just have a go.