Shop OBEX P1 Docs P2 Docs Learn Events
memsic accelerometer code drives motor or servo for unicycle project — Parallax Forums

memsic accelerometer code drives motor or servo for unicycle project

Let's Go!Let's Go! Posts: 124
edited 2008-08-11 12:03 in BASIC Stamp
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

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-08-09 13:24
    http://search.parallax.com

    Look around in Completed Projects for the "self-balancing robot" stuff.
  • SRLMSRLM Posts: 5,045
    edited 2008-08-09 13:54
    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!
  • Let's Go!Let's Go! Posts: 124
    edited 2008-08-09 13:56
    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...
  • Let's Go!Let's Go! Posts: 124
    edited 2008-08-09 14:01
    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.
  • Let's Go!Let's Go! Posts: 124
    edited 2008-08-09 14:04
    the bs2·output goes to a motor controller to control the 12-24v dc motor, 25 amps....
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-08-09 14:17
    Then I guess you're missing something --

    http://forums.parallax.com/showthread.php?p=570699

    For some "reason" he U/L'ed the programs as .BS2.TXT (so, knock off the .txt)
  • Let's Go!Let's Go! Posts: 124
    edited 2008-08-09 14:46
    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.
    ·
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-08-09 14:56
    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.
  • Let's Go!Let's Go! Posts: 124
    edited 2008-08-09 15:45
    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..
  • ZootZoot Posts: 2,227
    edited 2008-08-09 17:26
    Cool project!

    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.

    www.sparkfun.com/commerce/categories.php?c=85

    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

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • Let's Go!Let's Go! Posts: 124
    edited 2008-08-09 21:54
    thanks zoot, that's good info.......
  • SRLMSRLM Posts: 5,045
    edited 2008-08-09 22:50
    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...
  • Let's Go!Let's Go! Posts: 124
    edited 2008-08-09 23:34
    no the user won't pedal. the motor will be connected directly to the wheel. steering is accomplished by leaning.
    ·
  • Let's Go!Let's Go! Posts: 124
    edited 2008-08-09 23:38
    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...
    ·
  • ZootZoot Posts: 2,227
    edited 2008-08-09 23:45
    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

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • SRLMSRLM Posts: 5,045
    edited 2008-08-10 06:00
    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.
  • Let's Go!Let's Go! Posts: 124
    edited 2008-08-10 12:59
    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...
  • Let's Go!Let's Go! Posts: 124
    edited 2008-08-10 14:15
    an improvement could be to use a very fat·tire.
  • SRLMSRLM Posts: 5,045
    edited 2008-08-10 15:05
    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.
  • Let's Go!Let's Go! Posts: 124
    edited 2008-08-10 16:24
    i intend to make them self propagate also, but first i need the software ideas...
  • SRLMSRLM Posts: 5,045
    edited 2008-08-10 18:43
    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?
  • Let's Go!Let's Go! Posts: 124
    edited 2008-08-11 12:03
    thanks for all the help. now to the drawing board.
Sign In or Register to comment.