|
Re: Programming tricks (and former trade secrets)
Thanks for the note, no, this one is a loosely guarded secret...
We do some strange things with the scaling of our joysticks, but the principle is the same regardless of how you do it.
Start by creating a static global variable for each joystick axis, like:
char p1_x_offset = 0;
char p1_y_offset = 0;
Any place that you normally use the raw joystick value, use the joystick value minus the offset value, like:
pwm01 = (p1_y - p1_y_offset); //used to be p1_y only
Set the offset value to the joystick value when a button is pressed:
if ( button_pressed )
p1_y_offset = p1_y;
I think you get the idea. You are better off working with integer variables to avoid overflows, and handle limit checking, then converting back to char for writing to the pwm output.
Another thing to consider is adding a button to clear the offset. If you use this method to remove a large error, remember that the offset correction will not be present when the robot is reset, and the thing might take off.
In our implementation we limit the offset value to about 6 counts...
Let me know if you have other questions.
Jim
|