Shop OBEX P1 Docs P2 Docs Learn Events
Balancing bot? — Parallax Forums

Balancing bot?

quatro007quatro007 Posts: 9
edited 2006-04-22 09:02 in Robotics
I am trying to figure out some code to build a system similar to your balancing bots. The·components·I·am using are a Memsic 2125 two axis accelerometer,·HB-25 motor controller, and a linear actuator.·I am trying to code the stamp so that the motor controller will control the actuator so that a zero angle on the accelerometer is maintained.·I was told by a tech at Parallax that some your code for balancing bots is very similar to what·I am doing. I think he said that it was like a "porportional drive".·I am very new to this stuff and·only have enough coding ability to slightly modify programs or build very simple ones. Any help you guys could give me is greatly appreciated!
thanks,
Sean

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-10 20:31
    Sean,

    ·· With the linear actuator I don't know if the same concets apply.· Typically in a balancing bot, the motor drive will be proportional to the angle of tilt of the bot.· The more it's tilted the more drive you apply in that direction to attempt to upright itself.· Perhaps there are some users on here wo can post their balancing bot code to give you an idea?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • John R.John R. Posts: 1,376
    edited 2006-04-10 21:01
    It sounds like you're doing in "inverted pendulum", is this correct?

    If that is the case, the same concepts should apply. The further from vertical the pendulum leans, the faster the actuator needs to move to "get under" it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John R.

    8 + 8 = 10
  • BamseBamse Posts: 561
    edited 2006-04-10 21:24
    Something like this maybe:

    http://forums.parallax.com/forums/default.aspx?f=21&m=109179

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Living on the planet Earth might be expensive but it includes a free trip around the sun every year...

    /Bamse
  • quatro007quatro007 Posts: 9
    edited 2006-04-11 04:55
    <It sounds like you're doing in "inverted pendulum", is this correct?>·

    That's exactly what i'm trying to do.·My project·is basically a self leveling seat. The actuator is going to adjust the angle of the seat (from below the axis of rotation) to keep the seat level. The code for the IR sensor helps but·I don't know if I have the programming capability to adapt that code to my memsic accelerometer and motor controllers. Does anyone know of any bots that at least use the accelerometer with servos or IR with HB-25s? I may be able to figure out the code if·I have one of the elements, but not having either, is going to be hard. Thanks again!
  • Tronic (Greece)Tronic (Greece) Posts: 130
    edited 2006-04-11 07:02
    An accelerometer is not enouph for such inverted balancing system. I'm currently doing experiments with a ADXL202 accelerometer interfaced on my balancing bot (shown on link above) but it needs a gyroscope to do the balancing and use the accelerometer as reference to let the pendulum know where gravitys direction is, as the gyroscope drifts over time. For gyroscope i purchased a ADXLR150 evaluation board (in DIP package).

    I hope to figure it out soon to update the balancing project. smile.gif

    Thanos

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Greekbotics: Greek Robotics Forum
  • quatro007quatro007 Posts: 9
    edited 2006-04-11 17:12
    Sorry for the ignorance here, but can't the bot balance by knowing the angle of tilt. My theory is to reference zero degrees and sample the angle of tilt then use the actuator to maintain zero deg. In theory I would think that it would work the same as the IR sensor, correct? The IR sensor senses distance, right, and the bot tries to maintain a reference distance. I would think these two are very similar. Now, I know that there may be sensor systems that may be more precise (like IR or gyros) than the accelerometer, and you guys probably need that for a bot to balance freely, but my device isn't really balancing rather it needs to be rotated about a fixed axis to maintain zero degrees.
    My thought was to sample the angle then move the actuator in or out to return to zero degrees. The hard part for me to program are the different elements required for the HB-25. It needs code for final speed, turn motor forward or backward, and ramp up and ramp down. The way the code works, the motor will turn on (in a given direction), ramping up to a set speed, until the code turns it off.

    Does this help or make sense?

    I·have attached a modified version of Parallax's code for the HB-25.

    Thanks
  • Tronic (Greece)Tronic (Greece) Posts: 130
    edited 2006-04-12 06:05
    Well, there is a small problem with accelerator in this case, because it will show zero acceleration during the action of the tilt and the actual tilt as soon the boat reach the max tilt level (like 15 degrees). This means you cant measure the between values and have a smooth reaction of the chair. On the other hand gyros measure the rate of tilting (sorry about my bad english...) and line-up the chair with the reverse movement of that of the boat during the whole action.

    You better do some datalogging measurments of the output of the accelerometer to see for yourself.
    If its output is linear on the boat it might work, otherwise you better use a gyro.

    Thanos


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Greekbotics: Greek Robotics Forum
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-04-12 10:00
    Folks -

    I haven't really followed this thread, but let me offer the following. Generally speaking balancing bots need to sense tilt and respond to it quickly when it's outside of acceptable limits. This can be done by using an accelerometer as a tilt sensor, or by use of a gyro. Generally, the accelerometer is the more practical and less expensive solution.

    The key to the entire thing is having the sensor as NEAR to the center of rotation as possible. That way it will see the tilt as it is occurring, and not by some possible secondary means, if it's hung out on an edge of the platform, away from the center of rotation.

    The tilt sensor will offer two types of readings, depending on whether there is a positive tilt (forward) or negative tilt (backwards). One must respond quickly and appropriately to re-center the center of gravity (move the platform back under the center of gravity). Moving it too quicjly will cause "overshoot" and casue a secondary response in the opposite direction. Too little movement will cause "undershoot" which calls for more center-seeking movement, NOT NECESSARILY FASTER MOVEMENT. Faster movement may well cause overshoot, which only compounds the problem.

    I hope those general thoughts are helpful.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->

    Post Edited (Bruce Bates) : 4/12/2006 10:17:13 AM GMT
  • quatro007quatro007 Posts: 9
    edited 2006-04-12 17:52
    This is great feedback, thanks!
    The part I don't really know how to do is to program it for the motor controller (HB-25). So far I have put the accleleromter into a subroutine and I think the motor controller should go into a subroutine also. There are essentially three elements that I have to code for: direction, max motor speed, and start and stop. Now since the program is trying to keep the seat at 0 degrees, it should never really get outside of a few degrees in either direction before the program starts controlling the actuator moving the seat back to zero.·And since the actuator should be able to move the seat a couple of degrees within·one·second, the actuator will never really get up to full speed before being shut off (spin down should be minimal). So, my first question is, do I just go with a static max speed setting (knowing that just a portion of the ramp up of the actuator will be enough to get back to zero) or do i need to use a variable that gets set by something else (what and how to do this, I don't know)? Next question, for the HB-25 controller, will the code "PULSOUT HB25, 750" (I found this line in the initialization section) stop the motor no matter what direction it was moving (in program section of the sample code from Parallax it shows a "PULSOUT HB25, 750 + or - index" to slow the motor)? If I can just use "PULSOUT HB25, 750" then·I think I know how to use that in my code. For the direction, I think I can just use simple IF statements to compare to the direction of the tilt. Is any of this helping? I know the accelerometer will work good enough for what·I am doing, I think I just need help programming that to work with the moor controllers (I think the controller is the hardest to code right now.

    Also, I think I just figured out how the code for the controller works, can someone please validate this for me? I think it is working like a servo or a two way potentiometer. Here's the sample code that Parallax uses:
    FOR index = 0 TO 250··············· ' Ramp Up To Full Speed
    ··· PULSOUT HB25, 750·+ index········· ' Motor 1 Forward

    this looks very similar to a servo, 750 is·center (or off for a speed control) and the index from 0 to 250 ramps the movement of the servo to 1000 or the extent in one direction (or full speed for a speed control). Using a negative index will be full in the other direction. So, using this logic in my application, I can use a scalar with the angle to set index then just use "PULSOUT HB25, 750·+ or - index" and get rid of the FOR line. This would set the speed and give me a way to adjust the overshoot.

    Does this sound correct? Keep in mind that I don't know much about these devices or coding, so what I am proposing may not make sense, I don't know...

    Anyway, I'd appreciate your feedback.

    Thanks,
    Sean
    ·
  • quatro007quatro007 Posts: 9
    edited 2006-04-13 06:22
    Update:

    OK, so·I think I figured out a few things, but I'm not getting the results that·I should. I have attached the in-progress program. I haven't yet added any code for scaling the motor controller output based on the angle. The problem·I have is that·I get full controller output (15V) when I use just that section of code by itself, but when I include it into the program, it only puts out about .4V and jumps around even at that. It does though respond to the angle like it should, negative voltage for negative angles and positive voltage for pos angles, but still only about .4 V (again it should be about 15V). Can you guys please take a look at my code and see what may be wrong? What I want it to do at this point is put out 15V (like it does with just that section of code)·at a constant angle of tilt and not change voltage until I either rotate back to zero degrees or go over to negative angles (then it should be -15V). I'd really apreciate some help here, I feel like I may be close to getting something working.

    Thanks!
  • quatro007quatro007 Posts: 9
    edited 2006-04-14 05:01
    Chris and All,

    Update: I loaded the new code with the Pause 10s and debug line. The debug window shows exactly what I expect. It displays the correct dialog ("push actuator out", etc.) for the correct IF statement. And, at 0 angle it displays "stop actuator" until I change the angle. So, as far as the debug window goes, it's perfect.

    For the purpose of the system, the motor, it still doesn't work. I connected a small fan to the motor controller and it works perfect when I use the controller code (attached: HB-25 test - forward then backward), like you suggested to make sure everything works. It still doesn't really do anything when I use the code with the accelerometer. For the most part, it just bounces around 0V and the fan twiches. So, as far as the code I added while we talked, it didn't do anything. I attached the new code so that you can verify (seat computer-b). If anyone else has any suggestions, please post them. Thanks!

    Sean
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-14 17:14
    I will connect one up here with the Memsic 2125 and see what I get.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-14 18:24
    Okay,

    ·· I found what was causing the erratic behavior of the motor.·· You're trying to SEROUT to the same pin (PIN15) that the HB-25 gets its PULSOUT from.· This is being done in the Calcs routine.· It's garbage that keeps shutting the HB-25 down due to out of range pulse values associated with true serial communication.· Once that is corrected everything works great as far as moving the motor in a given direction when tilted that way.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • quatro007quatro007 Posts: 9
    edited 2006-04-14 18:33
    Oh cool! So, can I just change that SEROUT to any other number like say 10? I don't really want to change it to 14 because I may need that port at some point.

    What·number did you change it to?

    Thank you so much, I really appreciate it!

    Sean
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-14 18:35
    I commented it out...I assume it's code you're not using?· If not it doesn't need to be there.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • quatro007quatro007 Posts: 9
    edited 2006-04-14 18:52
    Oh, that was part of the code from you guys as part of the MEMSIC angle program, but if I don't need it for my app, I'll comment it out.
    Thanks again!

    I have a secondary question about the MEMSIC angle program, why does it not show 1 degree. The first angle it shows is 2 degrees, so it goes negative whatever, -2, 0, 2, positive whatever. It would be helpful for me to get that 1 degree angle so I can slow down the actuator and make the balance more accurate. And, it would be even better if I could get decimal angles, to the tenth of a degree anyway.

    Thanks.
    ·
  • SterlingSterling Posts: 51
    edited 2006-04-20 00:12
    How is the bot coming along?
  • quatro007quatro007 Posts: 9
    edited 2006-04-20 23:46
    Well, I got the program to work (my original post), I have not yet installed the computer or the actuator onto the device. So, I don't know if it will·hold vertical·as well as your balancing bots. I'm sure I'll have to do some fine tuning after I get everything put together. I also have not yet resolved the 1 deg angle issue that I was trying to solve, but I think I'll just wait until I try everything out to find out if it's still an issue.

    Now I'm having an issue where the HB25 controllers are not wokring properly when I switch the Stamp and the HB25s on at the same time. I am trying to use 1 switch to power on the HB25s and the Stamp so that they don't consume power while they aren't being used. I left a message at Tech Support, so hopefuly I can get it figured out soon. I know that there is probably an issue with the HB25s not initializing before the Stamp sees them. I have added a pause to the first line of the program, but that didn't work.

    Thanks,

    Sean
  • SterlingSterling Posts: 51
    edited 2006-04-22 09:02
    Which motors are you using?
Sign In or Register to comment.