Shop OBEX P1 Docs P2 Docs Learn Events
Help with Basic Stamp acceleration/deceleration — Parallax Forums

Help with Basic Stamp acceleration/deceleration

CarlBelCarlBel Posts: 6
edited 2014-04-03 20:33 in General Discussion
Hello all,
I am currently in the middle of a project and I need my Boe-Bot robot to slow to a stop (because if it stops suddenly the robot will jerk and become off-track). I am using BASIC Stamp Editor v.2.5.3 and I understand the basics about how to accelerate and decelerate. For example if my right wheel was connected to connector 13 and my left wheel was connected to connector 12, this would be my program:

pulseCount VAR Word

FOR pulseCount = 100 TO 1
PULSOUT 13, 750 - pulseCount
PULSOUT 12, 750 + pulseCount
PAUSE 20
NEXT
END

This would make my robot decelerate at the same speed. My problem is that if my right wheel is turning at 650 and my left wheel is turning at 850, my robot does not go straight. In order for my robot to go straight, this is the program:

pulseCount VAR Word


FOR pulseCount = 1 TO 244
PULSOUT 12, 812
PULSOUT 13, 706
PAUSE 20
NEXT
END

Notice that my right wheel is 44 units away from 750 (which is when the wheel is at a full stop) and my right wheel is 62 units away from 750. The only ways I can see to solve this problem is to make both my wheels rotate at the same speed and in opposite directions while being at equidistant numbers from 750 (for example my right wheel turning at 650 and my left wheel turning at 850 and the robot going straight), or to keep my wheels rotating at the speed indicated above (706 and 812) and to decrease/increase them both gradually to 750 at the same speed.

I am not very familiar with all the Basic Stamp commands and if there is anyone who can help, it would be greatly appreciated.
Thank you.

Comments

  • kwinnkwinn Posts: 8,697
    edited 2014-04-03 09:43
    CarlBel wrote: »
    Hello all,
    I am currently in the middle of a project and I need my Boe-Bot robot to slow to a stop (because if it stops suddenly the robot will jerk and become off-track). I am using BASIC Stamp Editor v.2.5.3 and I understand the basics about how to accelerate and decelerate. For example if my right wheel was connected to connector 13 and my left wheel was connected to connector 12, this would be my program:

    pulseCount VAR Word

    FOR pulseCount = 100 TO 1
    PULSOUT 13, 750 - pulseCount
    PULSOUT 12, 750 + pulseCount
    PAUSE 20
    NEXT
    END

    This would make my robot decelerate at the same speed. My problem is that if my right wheel is turning at 650 and my left wheel is turning at 850, my robot does not go straight. In order for my robot to go straight, this is the program:

    pulseCount VAR Word


    FOR pulseCount = 1 TO 244
    PULSOUT 12, 812
    PULSOUT 13, 706
    PAUSE 20
    NEXT
    END

    Notice that my right wheel is 44 units away from 750 (which is when the wheel is at a full stop) and my right wheel is 62 units away from 750. The only ways I can see to solve this problem is to make both my wheels rotate at the same speed and in opposite directions while being at equidistant numbers from 750 (for example my right wheel turning at 650 and my left wheel turning at 850 and the robot going straight), or to keep my wheels rotating at the speed indicated above (706 and 812) and to decrease/increase them both gradually to 750 at the same speed.

    I am not very familiar with all the Basic Stamp commands and if there is anyone who can help, it would be greatly appreciated.
    Thank you.

    To accelerate or decelerate in a straight line both wheels have to speed up or slow down at the same rate, so you need to add to both pulsout 12 and 13 to accelerate, and subtract from both to decelerate.
  • CarlBelCarlBel Posts: 6
    edited 2014-04-03 10:09
    But I only know how to add/subtract integers from both pulsout 12 and 13. For example: pulseCount VAR Word

    FOR pulseCount = 62 TO 1


    PULSOUT 12, 750 + pulseCount
    PULSOUT 13, 750 - pulseCount
    PAUSE 20
    NEXT
    END

    This will make my left wheel go from 812 to 750, but make my left wheel go from 688 to 750 (which will not make it go straight). I need to make my left wheel go from 812 to 750 and my right wheel go from 706 to 750. Is there a way to make both of these approach 750 at the same rate, during the same time interval?
  • NWCCTVNWCCTV Posts: 3,629
    edited 2014-04-03 14:01
    Have you centered your Servos? I have found that not all Servos act alike. Some times even if they are synchronized they tend to move differently so you just need to play with the values to get them to go straight.
  • CarlBelCarlBel Posts: 6
    edited 2014-04-03 14:28
    Well, if by "centered my Servos" you mean tweak the inside of the servo until a PULSOUT 12 (and 13), 750 made the motor remain still, then yes. But even though I think they are considered "centered", would I need to tweak the Servos until at 750 they remained still AND until this command (see below) made them go straight?

    PULSOUT 12, 800

    PULSOUT 13, 700

    I am able too make the robot go pretty straight, but not if both values are equidistant from 750. If I tweaked the Servos enough, would it be possible to make them go straight at
    PULSOUT 12, 800 / PULSOUT 13, 700?

    Also, the Servos I am using are about two years old. Would I have buy new ones?
  • NWCCTVNWCCTV Posts: 3,629
    edited 2014-04-03 15:00
    Yes, I actually meant synchronize which is to make sure 750 is a dead stop. After then the tweaking would be done within your code. Just play with the values and eventually you will get it to go straight. I would not think you need new servos. I have about a half dozen CR servos and pretty much never have 2 that work identical.
  • kwinnkwinn Posts: 8,697
    edited 2014-04-03 15:09
    Sorry, misunderstood the original question. I don't think buying new servos is necessary. The problem you are having is common for servos that do not have feedback from encoders to control the speed of the motors. That makes it very difficult to control the direction the robot travels in. Short of adding encoders the only suggestion I can make is to measure the speeds of both motors at different pulsout commands and use that information to compensate with software speed correction.
  • CarlBelCarlBel Posts: 6
    edited 2014-04-03 15:09
    But I can make it go straight, if:
    PULSOUT 12, 812
    PULSOUT 13, 702

    My problem is that since these values (812 and 702) are not equidistant from 750 (812 is 62 units away from 750 and 702 is 48 units away from 750), I cannot make my wheels slow down to a stop. What do you mean by "play with the values" because if it means trying different combinations of PULSOUT to make it go straight, I already did that. Is there a way to "play with the values" so that
    PULSOUT 12, 800
    PULSOUT 13, 700
    will make my Boe-Bot go straight?

    (Thanks for the help btw)
  • SapphireSapphire Posts: 496
    edited 2014-04-03 15:34
    You will have to scale pulseCount for the ratio between 48 and 62. That's about 0.77 which you can't directly use in the stamp. But there is a trick with the */ operator that will get you close.
    FOR pulseCount = 62 TO 1
      PULSOUT 12, 750 + (pulseCount*/198)
      PULSOUT 13, 750 - pulseCount
      PAUSE 20
    NEXT
    

    The */198 multiplies pulseCount by a fraction, returning an integer. 198 comes from 198/256 = 0.77 and as pulseCount goes from 62 to 1, (pulseCount*/198) will go from 47 to 0 which should get you what you want. You can use DEBUG to confirm this.

    Note I don't know if left/right is on pin 12/13 so the */198 might need to be on the other line, but you should know which it is. And you might have to try other values if the response isn't exact (like */199 or */197).
  • GenetixGenetix Posts: 1,754
    edited 2014-04-03 15:59
    Servos run slower and differently as the batteries wear down so make sure your using new batteries. Are you using Alkaline batteries or rechargeables?

    Try 805 and 695, which are both 55 from 750.
    Your current values differ by 14 pulses so 7 was subtracted from each to even out the values.
  • CarlBelCarlBel Posts: 6
    edited 2014-04-03 16:47
    Great! "The */198 multiplies pulseCount by a fraction, returning an integer. 198 comes from 198/256 = 0.77 and as pulseCount goes from 62 to 1, (pulseCount*/198) will go from 47 to 0 which should get you what you want" <- This is exactly the information I was looking for.Thank you so much Sapphire! One more problem I am encountering is that my robot sometimes randomly jerks to the left. My servos might have been a little damaged as I've just noticed that one wheel wiggles a little more than the other (which wiggles a little but which is probably negligible). I have ordered a new pair and all my problems should be fixed once I install them, center them, get them to go straight and manage to get them to slow to a stop.

    Thank you all so much for your help,
    This is a wonderful community.
    If I encounter more problems I will certainly come back to the forums.

    One last question for Sapphire (or anyone else who might have the answer):
    Why is it that */198 would multiply the pulseCount by 198/256? Where does the 256 come from?
  • CarlBelCarlBel Posts: 6
    edited 2014-04-03 16:49
    Changing the batteries is a good idea, thanks. Although I dont think 805 and 695 would work because by that same logic 850 and 650 would work no?
  • SapphireSapphire Posts: 496
    edited 2014-04-03 17:42
    CarlBel wrote: »
    Why is it that */198 would multiply the pulseCount by 198/256? Where does the 256 come from?

    Look at page 122 of the Basic Stamp Syntax and Reference manual or the Binary Operators section of the on-line help for a detailed explanation of the */ operator.
  • GenetixGenetix Posts: 1,754
    edited 2014-04-03 20:33
    Here is the explanation from page 112 of the BASIC Stamp Manual:

    The Multiply Middle operator (*/) multiplies variables and/or constants, returning the middle 16 bits of the 32-bit result.
    This has the effect of multiplying a value by a whole number and a fraction.
    The whole number is the upper byte of the multiplier (0 to 255 whole units) and the fraction is the lower byte (0 to 255 units of 1/256 each).
    The */ (star-slash) instruction gives you an excellent workaround for the BASIC Stamp's integer-only math.


    Suppose you want to multiply a value by 1.5.
    The whole number, and therefore the upper byte of the multiplier, would be 1, and the lower byte (fractional part) would be 128, since 128/256 = 0.5.


    To calculate the constant for use with the */ operator, multiply the target (mixed) value by 256 and convert to an integer.
    Note that the */ operator can be used to multiply by mixed values up to about 255.996.
Sign In or Register to comment.