View Full Version : memsic accelerometer code drives motor or servo for unicycle project
08-09-2008, 08:47 PM
hello everyone, i am trying to engineer a self balancing unicycle, and have studied the code samples provided by the parallax product site. but it stops short in that it just shows the debug.
does anyone know how to take the code offered (and willing to share·with us)·and then move a motor appropriately, that turns the wheel and also simultaneously balances the unicycle,·via the stamp 2 measurement taken from the memsic.
this project has lots of unique implications for those willing and able to take the plunge. here's a site that is very interesting ·http://tlb.org/eunicycle.html
thanks and will look forward to comments
08-09-2008, 09:24 PM
Look around in Completed Projects for the "self-balancing robot" stuff.
Just curious: how are you going to attach the output of the Basic Stamp to the wheel? If there is a person on the unicycle, then a rather large motor will be needed, along with some batteries. One more thing to consider: will the BS2 only balance in one dimension or two? If you expect it to work going sideways you'll have to do a bunch of research on how to manuever the wheel to do that balancing act. Hope you can ride!
08-09-2008, 09:56 PM
thanks for the input. unless i am missing something, there is no code posted on the completed project
·for the self balancing robot. although it is required to provide code to post on that page...
08-09-2008, 10:01 PM
the balancing takes place only forward and backward. sideways is like balancing on a bike. the batt, motor, controller all fit under the seat. the motor can attach to the wheel via a chain and sprocket.·the memsic comes in to be measured by the bs2 and output the result to the motor to balanace the wheel, many times per sec so it is a smooth adjustment. i.e. if one falls forward on the·unicycle, the memsic senses this and the motor speeds up to turn the wheel faster forward to compensate to right the unicycle.
08-09-2008, 10:04 PM
the bs2·output goes to a motor controller to control the 12-24v dc motor, 25 amps....
08-09-2008, 10:17 PM
Then I guess you're missing something --
For some "reason" he U/L'ed the programs as .BS2.TXT (so, knock off the .txt)
08-09-2008, 10:46 PM
yeh thanks, he's using an infrared sensor and not the memsic which is more precise. most of the memsic code is available at the product section, with the exception of taking it from the reading of the memsic to outputting to the motor. ·that is what i am looking for. once i can move a motor with the reading then i can figure out the rest.·thanks for your searching.
08-09-2008, 10:56 PM
Maybe you'll have to be the first.· It seems you know what to do, the rest·will be·the pioneering.· The link I posted was for an IR, another I recall uses Ping, and there are probably others.
08-09-2008, 11:45 PM
all i need is code to go from the reading the memsic to outputting to the motor. the rest of the memsic code is available on the parallax site. the code will maintain level..
You'll need an accelerometer *and* a gyro (the electric unicycle link you provided uses both). The accelerometer alone is not enough (it will report a "tilt" when you may just be stopping or starting hard). Using both together is often called an IMU (Inertial Measurement Unit). Sparkfun sells some nice modules for just this purpose (with accelerometer and gyro built in). The IR or Ping methods won't work unless you plan to only use the cycle on perfectly level ground.
In particular the SEN-00741 seems like a good value.
You can also purchase gyros for RC copters separately if you want to go that route.
When the going gets weird, the weird turn pro. -- HST
08-10-2008, 05:54 AM
thanks zoot, that's good info.......
Also, another thing to consider is the linear nature of your program (as it is now) You don't want to have three positions: upright, lean forward, lean sideways. If you do, the BS2 will turn on the motor and flip you to the other side. Then it will see this and flip back over. What I'm trying to say is that you'll want to have a gradual scale for compesation. If the cycle is just a little bit to one side, you have a little bit of compensation that reduces as it approaches the vertical.
I have a question: will the user be able to pedal? If you have the motor hooked up dirrectly to the wheel, then this could lead to complications...
08-10-2008, 07:34 AM
no the user won't pedal. the motor will be connected directly to the wheel. steering is accomplished by leaning.
08-10-2008, 07:38 AM
the segway works in the same manner. the user leans forward and the motor speeds up to right itself and also to increase speed for fw movement. if the user leans bw, the motor will slow or stop if leaned back enuf. so the sensor, whatever it is, will be trying to keep the user vertical via bs2 and the motor. the motor will be going fw, bw, etc at a very fast pace, but it needs to be a smooth transition...
Do a search at wikipedia and the Parallax forums on "PID control" -- Proportional Integral Derivative control. It's an extremely common and not very difficult control scheme for just this sort of thing (keeping a dynamic system "on point"). You'll turn up lots of examples. See esp. Andy Lindsay's write-up for the Stamp.
When the going gets weird, the weird turn pro. -- HST
Before you get too far you may want to test to see how easy it is to balance the side to side (using your body) you could clamp a pipe at the top of the fork and put it between high points. See if you can stay upright. My guess is that you will find it very difficult. Take the bike for a simulation: the bike has two wheels, so the forward-backward is under control (done by the BS2 for you). However, it is *very* difficult to stay still in one spot on the bike without falling over.
08-10-2008, 08:59 PM
right, the tlb.org site, blackwell makes a comment about wildly flailing his arms to keep from falling side to side. the general thought is it takes about 30 minutes to figure out the balancing side to side...
08-10-2008, 10:15 PM
an improvement could be to use a very fat·tire.
Once you get the basic go here / go there done, you can do neat stuff like bot following or GPS navigation. Say you have ten of these unicycles: the first one uses GPS to go somewhere, and the others follow in a line... You could field your own army.
08-11-2008, 12:24 AM
i intend to make them self propagate also, but first i need the software ideas...
So what else do you need? Seems we've discussed everything:
Use gyros and accelerometers for motion sensing
Use the BS2 for computations and output
Use a linked motor for drive
What exactly are you looking for?
08-11-2008, 08:03 PM
thanks for all the help. now to the drawing board.