|
Feedback is the answer
In my opinion, in order for steering drive wheels to work, you really need feedback.
Essentially, you need to have a pot that will give you the true position of the wheel in question.
Your operator interface will define a "desired position" (perhaps via a steering wheel or a pot on the operator interface side - some calculation may be required to go from the pot you read to the actual desired position -- typically you have to at least scale the values to match up correctly).
Given an actual steering position and a desired position, you can calculate a "steering error" term by subtracting one from the other.
This error value can be scaled by a "gain" and then added or subtracted from $7F (127) to generate your PWM output for your steering motors.
There is a whole bunch of places to stub your toe while implementing the above scheme, but if you do, you can have a very cool drive system that is easy to use.
For your thinking purposes, I will list a few things that may trip you up:
Define increasing pot values the same way that increasing PWM values (i.e. higher PWM values tend to move the steering motor in the direction that moves the pot to a higher value).
Get the feedback loop working with a basic system first -- for instance map the steering angle to the wheel value of a joystick.
Get your fancy arc-sin method of calculating desired angle working after you have your feedback loop working.
16 bit unsigned math is going to drive you nuts! Get used to it. Basically, you will have to test for the sign of your error term before you calculate your PWM value and then use IFs & Gotos to subtract an abs(error) term.
For gains for your feedback loop, multiply by a GainNum and then divide by a GainDem. This will give you more resolution in your gain choices -- you would be surprised how often 1 is too small and 2 is too large. If you multiply by 24 and divide by 16, viola! you have a gain of 1.5.
When I say "divide" I don't really mean divide. I mean divide by 2^N which is to say ">> N" Shift right is a MUCH faster operation than division. Also, 2 complement math (which is effectively what Pbasic gives us access to) works for plus, minus, multiply (for 8 bit numbers at least, watch for overflow/underflow problems) BUT DIVIDE DOES NOT WORK. This is why you have to test for the sign of the error before you do the division.
PWM outputs have $7F as "off" you will have to make sure you don't add too much or subtract too much so that the PWM acts fine until a large error is encountered. In my code there are a bunch of things like this that take care of this problem "... + $8000 MAX $80FE MIN $8000 - $8000" This will make the ... be no more than $FE (a.k.a. 254) and no less than 0.
Don't make the mistake of thinking that "... MIN 0" actually makes the ... no less than zero. Trust me, the above ... will remain unchanged regardless of what ... is.
Start will a low gain and increase it until it goes "unstable" or until it is oscillating too much. Then reduce the gain until you have an acceptable amount of oscillation and an acceptable reaction time. My controls profs would kill me if they new I was giving you such crude advice but, hey, it works (mostly).
One more note, you should try to gear your pots such that full travel of your steering mechanism translates to about 180 degrees of travel of your pot (assuming that you are using 270 degree pots). This has been a good compromise for us. It gives us enough resolution without being so close to the edge that we are hitting the end areas of the pot, which we have found is not as linear and/or reliable as the middle of the pot.
One final word of caution. You will break a lot of pots when you try this. It is very easy to make a sign error that will cause your steering motor to go insane. Have your finger on the kill switch as you download and run new code. Good luck.
Joe J.
Last edited by Joe Johnson : 11-11-2001 at 23:12.
|