|
Re: Help an old dog w/ new tricks
I'm not a programmer, but I can offer some advice. Let's start with the encoders:
RPM doesn't help much, but the number of "counts" does. If you determine, empirically if necessary, the number of inches that, say, 1,000 counts equals, you can measure distance. If for example 1,000 counts equals 75 inches, then each count is 0.75 (3/4) inch. If you want to go xx feet, just run the motors until you're 'close' to xx feet, then slow down more and more until you stop at xx feet (which is nn,nnn counts). The key here: Make sure that you are counting consistently. If you are not, nothing gets done until you are counting consistently. This becomes a mechanical or sensor thing.
Now the Gyro: You can turn 90 degrees, that's HUGE. The 'staying on track after" is not a trivial problem, but the basic idea is to set the direction after the turn (that means, read the gyro and make that youer "set point" or "goal"). Then track your direction and, if the path deviates from the goal, make corrections.
The key to this is tracking the deviation in a reasonable way. A difference of 0.01 degree would be impossible, from a mechanical view, to correct. So you average a reading every 1/4 second and, if after 8 readings the average is more than, say, 2 degrees to one side, you go to a subroutine that tweaks the power to the other side by reducing it slightly. Now, 'tweaks slightly' can be related to the number of degrees error: Bigger tweak for 5 degrees, smaller tweak for 2 degrees, huge tweak for 15 degrees.
Just don't do this too fast: a change every 1/2 to 2 seconds is on the order of magnitude for what you want.
Many years ago I posted a few posts on PID; if you find them they'll explain in a more logical way the concepts of error, corrections, and how often you apply corrections.
But doing all this in theory is not going to teach you what you need: get the robot, and focus on ONE thing at a time. Get that thing nailed flat and fully understood - fool with it to see what happens - and write down what you learned (your memory will not suffice. The faintest ink is superior to the strongest memory). Then move to the next thing.
And keep asking us here.
__________________
I am N2IRZ - What's your callsign?
|