Help with Basic Stamp acceleration/deceleration
CarlBel
Posts: 6
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.
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
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.
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?
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?
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)
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).
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.
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?
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.
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.