Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Seg...stick.
by scolton on December 22, 2010 Table of Contents Seg...stick. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Intro: Seg...stick. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Step 1: Physics says it's easier to build a full-size self-balancing thing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Step 2: Gathering. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Step 3: Drive motors, choosing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Step 4: Drive motors, modding. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Step 5: Drive wheels. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Step 6: It's starting to look like a...something. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Step 7: And now, the hard part. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Step 8: Software overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Step 9: Two sensors, one angle. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2 2 3 4 5 6 7 8 9 9 9
Step 10: A very flattering filter. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Step 11: The control part of the controller. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Step 12: Steering, and other loose ends. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Step 13: Sticking it all together. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Step 14: Links to better self-balancing things. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
http://www.instructables.com/id/Segstick/
Intro: Seg...stick.
Do-it-yourself self-balancing...things...have been around almost as long as commercial self-balancing things. Obviously the homemade versions are not as smooth, reliable, or failsafe as the real thing, but they are still pretty captivating. And they make great mechanical/electrical builds with some interesting control theory mixed in. In the final step, I provide a few references to good DIY self-balancing...whatever...builds. In 2007, I helped with this other self-balancing scooter build at the MIT Edgerton Center, and since then we've gotten many interesting questions by email about how it works. Baseline self-balancing functionality is actually surprisingly simple, and maybe the purpose of this Instructable is to take this simplicity to the extreme. To that end, I present: Seg...stick. Segstick is a self-balancing...well, literally some kind of broomstick I found in the MITERS workshop. It is powered directly by two DeWalt cordless drills chucked to two 6" wheels. The controller is an Arduino. Additional supporting devices include an Inertial Measurement Unit (IMU) from Sparkfun and two motor drivers from Pololu. Is it the best DIY self-balancing vehicle ever? No, not even close. But it only took about two days to build, and it is stripped down to the bare necessities. Thus, I hope to point out the modules and concepts involved in making any self-balancing vehicle rather than the specifics of this one. To start with, some physics...
http://www.instructables.com/id/Segstick/
Image Notes 1. The longer the inverted pendulum, the slower the exponential fall.
Step 2: Gathering.
Having decided to build a full-sized self-balancing vehicle, there are a number of essential components and modules to acquire. Here is a complete list of parts used to build the Segstick. Details of and alternatives to several components will be presented in later steps. Big-Ticket Items ($411): 2x DeWalt DC759 18V Cordless Drill (eBay, $60ea new w/o battery or case) 1x DeWalt DC9096 18V Battery (eBay, $40) 2x Polulu High-Power 18v25 Motor Driver ($50ea) 1x Gravitech Arduino Nano 3.0 ($35) 1x Sparkfun Razor 6DOF IMU ($60) 2x AndyMark 6" FIRST Wheel ($13ea) 2x AndyMark 1/2" Keyed Hub ($15ea) McMaster-Type Stuff: 2x Mounted 1/2" Bearings (5913K61) 4x 1/2" Shaft Collar (9414T11) 1x Precision 1/2" Keyed Shaft (1497K131) 1x 1/8" Key Stock (98535A130) Scrounge-ables: - Plywood (3/4", 1/2") - Hose Clamps or Extremely Large Zip Ties. - 1/4-20 Bolts and Nuts - Breadboard or Protoboard - Wire, Heat Shrink, Solder - 5k or 10k Potentiometer. - Polarized 2-Pin Power Connectors (e.g. Deans) - Heat Sink Material And Most Importantly: - A Stick.
http://www.instructables.com/id/Segstick/
http://www.instructables.com/id/Segstick/
Image Notes 1. Trigger speed controller. 2. Gearbox and clutch assembly. 3. Brushed DC motor.
http://www.instructables.com/id/Segstick/
Image Notes 1. Keyed hub. These were 3/8" but I manually converted them to 1/2". 2. To attach the hub, you can either use through-bolts or tap the wheel for 10-24 or 10-32 machine screws.
http://www.instructables.com/id/Segstick/
Image Notes 1. Marked holes where the zip-ties / hose clamps will go.
Image Notes 1. Future drive motor, but for now it's still useful as a tool.
Image Notes 1. The bearings needed a 1/2" spacer, in this case polycarbonate, to be at the same height as the drill chuck.
Image Notes 1. A locking collar spaces the wheel out from the bearing. 2. The key.
http://www.instructables.com/id/Segstick/
Image Notes 1. A second locking collar on the outside prevents the wheel from falling off. 2. Zip tie constraint #1. 3. Zip tie constraint #2. 4. Zip tie constraint #3. 5. Be sure the chuck is extremely tightened.
Image Notes 1. The dots imply a connection between intersecting lines. All other intersecting lines do not connect.
Image Notes 1. LM7808 voltage regulator to power Arduino. 2. High-current wires are soldered directly to the motor driver boards.
http://www.instructables.com/id/Segstick/
Image Notes 1. I added a heat sink to the motor drivers. Make sure to use Kapton or other insulation between the sink and the board. 2. The board is just screwed into the plywood. 3. High-current connectors for power wiring from the battery and to the motors. 4. 14AWG wire.
Image Notes 1. Steering pot is just zip-tied to the top of the stick...
File Downloads
segstick.pde.txt (3 KB) [NOTE: When saving, if you see .tmp as the file ext, rename it to 'segstick.pde.txt']
http://www.instructables.com/id/Segstick/
[(1/s)/0.00333V]*(5V/1024LSB) = 1.466(/s)/LSB This is the value by which to multiply the raw analog input to get an angular velocity in degrees-per-second. Like the accelerometer, the zero offset for the gyro must be subtracted first. It can be found by holding the platform stationary and reading off the analog value. To get from degrees-per-second to degrees, the gyro signal can be integrated. For every step in time, the gyro signal multiplied by the duration of time between steps gives an incremental change in angle. The total angle is the running sum of these increments. This causes a problem, though: If the gyro signal is not exactly zero when the platform isn't rotating (and it never will be) the integration will drift. With no absolute reference, there is no way to correct for this drift with the gyro signal alone. However, for short durations, the gyro provides a very sensitive angle estimate that is immune to noise from horizontal acceleration of the vehicle So one sensor is great for short-term, fast-response angle estimates. The other is great for long term, drift-free absolute angle averages. Are you starting to see where this is going?...
Image Notes 1. These values should be determined experimentally. 2. These values are calculated as above.
Image Notes 1. It's the initial slope that matters for setting the accelerometer gain.
Image Notes 1. The order of subtraction is reversed here to keep the direction for positive angle and positive angular rate consistent. You may have to check this in your implementation. 2. The raw analog values are multiplied by the gains to change to consistent units of degrees [per second].
http://www.instructables.com/id/Segstick/
Image Notes 1. Summing only works if the base units match, which is why everything is first converted to degrees [per second]. 2. The filter outputs sum to one. This is the "complementary" part. 3. The complementary filter can be viewed as a low-pass and a high-pass filter with the same time constant.
Image Notes 1. The proportional gain acts on the filtered angle estimate.
http://www.instructables.com/id/Segstick/
Image Notes 1. Hacker stuff. Image Notes 1. Clip as float to prevent the output from incrementing indefinitely. 2. Differential steering command. 3. Clip again as integer after adding steering to ensure that the values sent with analogWrite() are within range. 4. Why does the Arduino constrain() function not do legit things?
Image Notes 1. For the reverse cases, the output command is inverted so that it is still between 0 and 255.
http://www.instructables.com/id/Segstick/
Related Instructables
Easy build self balancing skateboard/robot/segway platform by Steampunk XenonJohn Segway ( Legway ) by bdring
http://www.instructables.com/id/Segstick/
Comments
41 comments Add Comment
luanlist says:
Hi, I didn't understand how to find A_Zero, G_zero and S-Zero values. Experimentally yes, but how? Thanks
scolton says:
Feb 18, 2011. 11:31 AM REPLY You can use Serial.prinln() to print the analog value of the sensor readings to the Arduino serial terminal. Then, you can zero the three states. (Hold the platform horizontal and stationary, and set the steering potentiometer to zero.) Record these values and you've got the zeros. Very important note: The zeros will change if you run on USB 5V instead of regulated 5V, so I suggest doing it with the external battery power turned on.
ajmontag says:
Feb 14, 2011. 4:12 PM REPLY Am I correct in saying that the angle and rate values should be based at, and stay near zero? Then the output would be around 0, either +/-, and the sign is intended for direction, correct? Thanks!
scolton says:
Feb 14, 2011. 6:33 PM REPLY Yes, all the control equations assume a small angle approximation, which would only be valid within maybe +/-30deg from 0, which is defined as the base being horizontal. After that, you would need some trig to solve for the angle based on the accelerometer readings. (The rate reading doesn't care about the absolute angle.)
skeleton1102 says:
Jan 2, 2011. 4:29 PM REPLY Question: In the else case at the final stage before output. Is the LOW argument turning that motor off? sorry I dont know much about the electrical/physical aspect of the project. And are the splitting of output into right and left for the right and left motors. BTW the white paper was fantastic. Really helped me for what Im trying to do
scolton says:
Jan 2, 2011. 5:31 PM REPLY Thanks! The LOW and HIGH arguments change the polarity of voltage applied to the motor via the DIR pins on the motor controllers. And yes, output_left and output_right are split for the left and right motors, so that a differential steering command can be applied.
XenonJohn says:
Hi Shane,
It was your original ??2007 version of the white paper on how a complimentary filter works that gave me enough confidence to attempt a selfbalancing machine. Great instructable. XenonJohn
skeleton1102 says:
hhmmm so the polarity means that the motor will go the other way? I really no nothing about electrical engineering.
scolton says:
Jan 2, 2011. 8:22 PM REPLY That's correct. The Pololu motor driver boards are H-bridges, so they can drive the motor in either direction, clockwise or counter-clockwise, based on that DIR pin input. It would be the equivalent of reversing the motor leads. The drill controllers can also do this, but they use a mechnical switch that reverses the connections directly, instead of an H-bridge. So, it can't be controlled electronically by the Arduino. Here's a couple good references on how H-bridges can apply forward and reverse polarities: http://en.wikipedia.org/wiki/H-bridge http://www.4qdtec.com/bridge.html
skeleton1102 says:
Jan 3, 2011. 12:15 PM REPLY That helps a lot thank you. The Arduino Constant Refernece says that Low is 0 volts when the pin is configured to output. Wouldn't that mean the no current is leaving that pin? I've never had any sort of physics class so I know nothing about this stuff
scolton says:
Jan 3, 2011. 1:39 PM REPLY Yeah, LOW is 0V and HIGH is 5V. They are just signals, so very little current flows into or out of the pin either way. The motor controller board reads in the signals and then sets the H-bridge accordingly. The H-bridge does all the high-current stuff.
http://www.instructables.com/id/Segstick/
skeleton1102 says:
aaahhhh thats really obvious now that you say it. Thanks a lot youve been a huge help
skeleton1102 says:
Jan 5, 2011. 3:41 PM REPLY Really sorry about all the questions, but do have any good references on how the whole GAIN values are calculated and set. Im very confused about how the whole LSB thing plays into this, and you know theres the whole not knowing any physics to complicate things
scolton says:
Do you mean the P and D gains? I honestly just picked numbers that sounded reasonable:
The motor output command is a value between 0 and 255, which sets the voltage send to the motor by the H-bridge. (Actually, it might be 0-511 because I'm using 9-bit PWM...) Each of these steps from 0 to 255 (or 511) is a "least significant bit" or LSB. So, the P gain is 0.5LSB per degree per loop. The loop runs 50 times per second. So, in one second, it will increment the output 0.5*50 = 25 steps per degree of tilt. If the platform is tilted 10 degrees (a pretty severe lean), this will be 250 steps, or almost the full range of the motor controller output, in one second. From that point, I would normally tweak the value up or down depending on the observed behavior. But actually the first values I chose seemed to work okay.
skeleton1102 says:
Jan 6, 2011. 1:08 PM REPLY I get it now, I see the whole steps thing, just calling it LSB confused me because i wikied it and its seemed to do with the right most bit which didn't make much sense to me.
luisma.suarez says:
Jan 4, 2011. 9:36 PM REPLY ok, its offcial, you rock! congrats. excellent work i'll pour over your math when i have the time- but gyro AND A meter? really nice!
clomok says:
Is that knife on the table home-made as well?
scolton says:
Nope, that's an Allen wrench set I got in Tokyo.
theugleymonkey says:
Do you think a Motor controller such as this one would be sufficient to replace the one you have used? http://www.robotshop.com/robotics-conection-10a-12-24v-dual-motor-controller-1.html
teamtestbot says:
Hi, This will probably work out better for you: http://kellycontroller.com/hpm14701700a144vwith-regen-p-869.html
It'll definitely control the motors in the 18v DeWalt drills. May be a bit large, however, but they're enclosed and waterproof unlike the Pololu boards.
scolton says:
Jan 1, 2011. 3:20 PM REPLY 10A probably is not sufficient to drive the drill motors. It's also only $10 less expensive than the two Pololu controllers, so unless I had one lying around already I wouldn't really be tempted to buy it. Dec 31, 2010. 5:16 PM REPLY
theugleymonkey says:
So I was wondering if I could use motors like one of these http://www.scooterpartscatalog.com/razor-e100-motor-119-17.html http://www.scooterparts4less.com/web_electric/180watt24v_motor.htm
scolton says:
Dec 31, 2010. 6:16 PM REPLY Sure. They would need to be geared down at least about 5:1, even for small wheels. Timing belt would probably be best. I used to think backlash would be a problem for belt or chain-driven platforms, but compared to these drills it would actually be an improvement.
http://www.instructables.com/id/Segstick/
theugleymonkey says:
Do you have any recommendations for the the gears?
scolton says:
Jan 1, 2011. 11:04 AM REPLY Not sure what the pitch on the motor sprockets are. The first one just says "3M". The second one I think is #25 chain, but I'm not sure. Either way, you can definitely find sprockets, pulleys, chain, belt from www.mcmaster.com or www.sdp-si.com once you know what pitch to look for. (Might have to buy the motor and measure it yourself.)
theugleymonkey says:
Jan 1, 2011. 10:15 AM REPLY Do you think implementing the ArduIMU +v2 would work? How much of the software and configurations do you think would need to be changed? http://www.sparkfun.com/products/9956
scolton says:
Oh, also, MOSI and MISO correspond to D11 and D12, the DIR outputs.
scolton says:
Jan 1, 2011. 10:50 AM REPLY Definitely. In fact, if I were starting from scratch that's probably how I would do it. (Less wiring.) The changes would be minimal: You have access to the two PWM driving pins, labeled PWM0 and PWM1 on the ArduIMU. These are the same as D9 and D10 on the regular Arduino. So no changes there. The analog pin definitions change a little, but nothing you can't figure out from the schematic. You'd have to use the SDA or SCL pin as the steering pot analog input. (You'll see why on the schematic.)
theugleymonkey says:
So you say for the steering pot to use SDA or SCL. Why is this? Is this because I can use it as ADC 4 or 5?
scolton says:
Yep.
ameggs says:
Could you use a dimension engineering Sabertooth motor controller for this project? http://www.dimensionengineering.com/Sabertooth2X25.htm http://www.dimensionengineering.com/Sabertooth2x50HV.htm
scolton says:
I think either of those would be fine. The 50A version might be good for a larger balancing platform, too.
static says:
Far out, but can you say impalement hazard? Put some handle bars atop that stick.
teamtestbot says:
Ahh, but see, this is an Instructable. That's your job!
janw says:
Great instructable! And a very clear way to explain things! definately worth 5 stars
drbill says:
Dec 26, 2010. 11:41 PM REPLY I am 56 years old and I am in continual absolute awe at what is being put together by todays kids and I get to see it all here on Instructables. I think you may have a saleable item here if you can make it work as good as a Segway (tm) Kudos
drbill says:
If you make a more refined model, please up-date this I'ble.
http://www.instructables.com/id/Segstick/
technodude92 says:
Very cool project youve got there. How long till your flying down the halls on your own handmade seg...stick?
chouf says:
I hear you have good taste in music (we can hear "Air" on your video) ;-)
godofal says:
Dec 26, 2010. 5:51 AM REPLY lol, awesome :D a tip perhaps: when turning, make the other wheel turn in the opposite direction (or slow down in case of movement) so that you turn in place rather than make a circlish movement nice cheap project though :D
rimar2000 says:
AWESOME! This is genial.
http://www.instructables.com/id/Segstick/