View Single Post
  #12   Spotlight this post!  
Unread 12-03-2008, 09:53
Kevin Sevcik's Avatar
Kevin Sevcik Kevin Sevcik is online now
(Insert witty comment here)
FRC #0057 (The Leopards)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Houston, Texas
Posts: 3,721
Kevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond repute
Send a message via AIM to Kevin Sevcik Send a message via Yahoo to Kevin Sevcik
Re: How to Auto Calibrate

Quote:
Originally Posted by jamie_1930 View Post
After thinking about this I think I have your code.
if(trig_sw==1)
x1==127
y1==127
x2==127
y2==127
This should be it. Although you still want to check the variables
x1,x2,y1,y2 are supposed to be the joystick direction.
Jamie, I don't think that's what he's talking about. If you did something like that at the beginning of you default routine, then you'd have your joysticks zeroed while you held down the trigger, but you'd never be able to move.

You could do this pretty simply with code along these lines:
Code:
//Definitions
signed char p1_x_off = 0;
signed char p1_y_off = 0;

//Code somewheres at the top of your default routine before you use p1_x, etc. for anything useful:

if (p1_top == 1)
{
    p1_x_off = 127 - p1_x;
    p1_y_off = 127 - p1_y;
}

p1_x = Limit_Mix(2000 + p1_x + p1_x_off);
p1_y = Limit_Mix(2000 + p1_y + p1_y_off);
And then you'd be able to virtually offset your joysticks back to center. Sort of. As QBranch has said, if you actually do this, then the effective range of your joystick is reduced by however wrong you were when you calibrated. for example:
Code:
Joystick center starts at:
p1_x = 147

You "calibrate" so:
p1_off = -20

Here, then are some typical joystick values
and how they'd come out in your code:
p1_x         147   127     0   20   254
p1_x + off   127   107   -20    0   234
Limit_Mix'd  127   107     0    0   234
Notice how actual values between 0 and 20 look like 0 to your code. Notice also how your code will now never see anything higher than 234. These sort of limits that come from this "calibration" are why you always see teams fiddling with trim dials as opposed to using code like this. It might be a little more time consuming and troublesome, but it just works better.
__________________
The difficult we do today; the impossible we do tomorrow. Miracles by appointment only.

Lone Star Regional Troubleshooter