|
Use feedback!
I don't think you will not be successful at what you are trying to do by just timing the outputs.
You really need to use feedback.
Have a potentiometer (pot) give your program the true position of the steering.
Compare the pot value to the desired value. Calculate the sign and magnitude of the error. Multiply the magnitude of the error by a gain (you may want to multiply it by a constant and divide it by a power of 2, i.e. shift the result right N bits, this will give you the abiltiy to have a gain between 1 and 2 for example). Then if the error is greater than zero add this scaled error to 127 to get the appropriate PWM output. If the error is less than zero subtract the scaled error from 127 to get your appropriate PWM output. You have to be careful about going under 0 or over 254 with your PWM output.
Anyway, this is a very simple feedback loop (called proportional feedback). It works pretty well, especially for steering (trust me I know this to be true).
Have your finger on the e-stop button (you all have built a yellow dongle with an e-stop button haven't you?) as you test your code because it is easy to have the steering go insane while you debug your code. You have to get the gain to have the right sign AND you have to have the gain set large enough but not too large. There are a lot of places to stub your toe, but the destination is worth the trip.
Good luck.
Joe J.
|