|
Re: Help with Joystick Axes and Sensitivity
I used an output curve and deadzone system to get around my team's joystick problems. Basically, instead of always setting the output to whatever the joystick reads (output = input;), you first want to round the value to neutral if it's pretty close, to prevent "ghosting", or off-center movement when the springs don't pull the stick all the way back. This would be something like output = input; if(output < 127 + c && output > 127 - c) output = 127; where c is a value you experiment with (I think ours is set to 16 now). Then, for values that make it through this filter, you want to apply some algorithm to weigh the output.
There are a few different formulas you could try. If you want to think of it visually, consider a graph in the first quadrant of output vs input. The easiest function to use is a linear one, which would just be a simple straight line that cuts diagonally through the neutral point. This is what you already have, and doesn't give you the best results. Another option is a sinusoidal or parabolic graph, that is concave down left of the neutral point, concave up to the right, and has a slope of zero in the middle. This way, if you move the joystick part way left or right, you don't get much movement, but when you go all the way you still get full power.
It's easier to deal with the math when the variables are signed chars (ranging from -128 to 127) instead of unsigned chars (0 to 255). You would read in the joystick value as a signed char, convert to unsigned and subtract 127, do all your calculations, then at the end add 127 and convert back to signed and map it out to pwm01 and the others. It's up to you whether you want to complicate the variables this way, but it will simplify calculations later on.
If you do use signed chars, the formula for parabolic weighting is output = (int)input * input / 127; if(input < 0) output = -output;. For sinusoidal, it's output = 127 * sin((float)input * PI / 256);. My teammates seem to like the second function better, but as GregT said, it is computational expensive to use floating point operations.
Last edited by Workaphobia : 05-02-2005 at 00:43.
|