Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Desensitizing Joysticks (http://www.chiefdelphi.com/forums/showthread.php?t=24613)

phrontist 03-02-2004 21:42

Re: Desensitizing Joysticks
 
We are going to map our joystick input to a function (y=x^3 or something) and then map the output to the motors. We were also considering a recursive approach, such that it finds the delta (change-in joystick postion) and alters accelleration accoordingly.

WillyC 04-02-2004 01:33

Re: Desensitizing Joysticks
 
Quote:

Originally Posted by bob1million
This works great on our bot, everyone from SWVGS Maximus thanks you.
We used a switch statement and it did not slow down anything. It is a big improvement from what we had. :)

I'm glad to hear that this helped you guys. We just tested this today and found that it worked really nice. Thanks, good luck.

squide 08-02-2004 18:23

Re: Desensitizing Joysticks
 
Quote:

Originally Posted by WillyC
I'm glad to hear that this helped you guys. We just tested this today and found that it worked really nice. Thanks, good luck.

Team 1056 would also like to thank you. We created an array with the values, adjusted the joystick values so they were divisible by five then got the value from the array by dividing by 5.

Would a larger array of 255 members be okay to use, or would it slow the program down?

Thanks!

Ryan M. 08-02-2004 18:56

Re: Desensitizing Joysticks
 
Quote:

Originally Posted by squide
Team 1056 would also like to thank you. We created an array with the values, adjusted the joystick values so they were divisible by five then got the value from the array by dividing by 5.

Would a larger array of 255 members be okay to use, or would it slow the program down?

Thanks!

A large array size won't slow the program down in any noticable way.

deltacoder1020 08-02-2004 19:25

Re: Desensitizing Joysticks
 
however, you'll probably want to put it in rom, as you only have 1800 bytes of variable space in user memory. just add the keyword "rom" to the list of type modifiers in the declaration.

m0rph3us 08-02-2004 19:45

Re: Desensitizing Joysticks
 
Quote:

Originally Posted by phrontist
We are going to map our joystick input to a function (y=x^3 or something) and then map the output to the motors. We were also considering a recursive approach, such that it finds the delta (change-in joystick postion) and alters accelleration accoordingly.

You might want to stay away from recursive functions because they can take up a lot of memory while running making the code less reliable.

Andy A. 08-02-2004 23:49

Re: Desensitizing Joysticks
 
Hold on a sec folks...

I'm assuming before you've done any of this, you've gone through and recalibrated the Victors with the joysticks you plan on using, right?

Right?

The option to recalibration is really just there because not all joysticks are created equal. The output from one stick to another varies, espically from model to model. By calibrating each victor to the joystick you use, you'll get a smooth, consistent output from it, instead of either:

A: Peaking early (I've seen victors putting out %100 at only half stick), which leads to ultra sensitive sticks

or

B: Never peaking. Which leads to speed and power you never get, just because your stick doesn't let you move the pot that extra bit.

Honestly, calibrate the Victors before you do anything else. I suspect that a great deal of the trouble teams are having with the new sticks is because the victors factory calibration is off from were they 'want' to be with the new sticks.

Check your documentation for the procedure. It takes 30 seconds, and can do only good.

-Andy A.

Astronouth7303 09-02-2004 07:28

Re: Desensitizing Joysticks
 
Compared to last year's, the new sticks are more seensitive. I think it's because the centering springs aren't as powerful.

Alan Anderson 09-02-2004 08:17

Re: Desensitizing Joysticks
 
Quote:

Originally Posted by KenWittlief
I dont understand how putting a deadband around 127 will make the joystick less sensitive

in fact, your bot is going to lurch when the joystick is moved just outside the deadband.

I think the Victors would mask that effect quite nicely, because they have their own deadband around 127.

gnormhurst 09-02-2004 11:01

Re: Desensitizing Joysticks
 
Quote:

Originally Posted by Alan Anderson
I think the Victors would mask that effect quite nicely, because they have their own deadband around 127.

I have found that the Victors do indeed have their own deadband of about +/- 7 that I didn't like, so I wrote code to get around it. I chose my own deadband (+/-2 for example). First I calculate my (smooth) transfer function assuming the Victor has no deadband. Then, when the value is inside MY deadband, I set the output to the center value of the Victor (determined either by experimentation (which is what I did) or by calibration of the Victor (better).

When the value is above my deadband, I add a fixed offset to the value. When it is below my deadband, I subtract a fixed offset. This way the output "jumps" from dead to the first value that causes the Victor to do something. I actually did the process on absolute values and restored the sign at the end.

BTW, I have found that working with signed ints saves a lot of headaches. But you need to be careful when converting back to unsigned char that the value is in the range 0-255!

Code:

int speed;  // signed motor speed; negative means backwards
int absoluteSpeed; // always positive
int direction; // +1 or -1 (sign of speed)

#define ABS( x )  (x) > 0 ? (x) : (-x)
#define SIGN( x ) (x) > 0 ? (+1) : (-1)
#define VICTOR_CENTER 131
#define VICTOR_DEADBAND 7
#define MY_DEADBAND 2

// ... ( magic transfer function that sets 'speed')

// work around Victor's deadband:
//
absoluteSpeed = ABS ( speed );
direction    = SIGN( speed );

if ( absoluteSpeed > MY_DEADBAND )
  absoluteSpeed += VICTOR_DEADBAND;
else
  absoluteSpeed = 0;

// restore sign and add offset.  (Be careful to keep this in range of 0-255!)
pwm13 = (unsigned char) clipInt((absoluteSpeed * direction) + VICTOR_CENTER, 0, 255);


The function clipInt() is:

Code:

int clipInt( int in, int low, int high )
{
  if ( in > high )
    return high;
  else if ( in < low )
    return low;
  else
    return in;
}

CAUTION: I wrote all this code manually here (not cut and pasted), so it may have bugs!

Catastrophy 09-02-2004 23:52

Re: Desensitizing Joysticks
 
I know that people have said what to do, but, I'm new to this and do not understand how to modify the sensitivity. Could anyone please post up the code to desensitize the joysticks and where to put it. Thanks! :D

deltacoder1020 10-02-2004 00:48

Re: Desensitizing Joysticks
 
there is no specific "the code" - there a plenty of ways to do this. however, I have included an example below - it maps the joystick values to an approximation of an x-squared curve. it's not perfect, and i would probably do it differently if i were putting a ton of effort into it, but this is for an example. it should still be functional though.

Code:

const rom signed char JOYSTICK_SMOOTHING[128] =
{
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2,
2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7, 8,
8, 9, 9, 10, 10, 11, 11, 12, 13, 13, 14, 14, 15, 16, 17, 17,
18, 19, 20, 20, 21, 22, 23, 24, 25, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 48, 49,
50, 51, 53, 54, 55, 56, 58, 59, 61, 62, 63, 65, 66, 68, 69, 71,
72, 74, 75, 77, 78, 80, 81, 83, 85, 86, 88, 89, 91, 93, 95, 96,
98, 100, 102, 103, 105, 107, 109, 111, 113, 114, 116, 118, 120, 122, 124, 126
};

unsigned char Get_Desensitized_Output(unsigned char input)
{
    if(input > 127)
    {
        return ((unsigned char) (128 + JOYSTICK_SMOOTHING[input - 127]));
    {
    else
    {
        return ((unsigned char) (127 - JOYSTICK_SMOOTHING[127 - input]));
    }
}


Ryan M. 10-02-2004 08:51

Re: Desensitizing Joysticks
 
Quote:

Originally Posted by deltacoder1020
Code:

const rom signed char JOYSTICK_SMOOTHING[128] =
{
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2,
2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7, 8,
8, 9, 9, 10, 10, 11, 11, 12, 13, 13, 14, 14, 15, 16, 17, 17,
18, 19, 20, 20, 21, 22, 23, 24, 25, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 48, 49,
50, 51, 53, 54, 55, 56, 58, 59, 61, 62, 63, 65, 66, 68, 69, 71,
72, 74, 75, 77, 78, 80, 81, 83, 85, 86, 88, 89, 91, 93, 95, 96,
98, 100, 102, 103, 105, 107, 109, 111, 113, 114, 116, 118, 120, 122, 124, 126
};
 
unsigned char Get_Desensitized_Output(unsigned char input)
{
if(input > 127)
{
return ((unsigned char) (128 + JOYSTICK_SMOOTHING[input - 127]));
{
else
{
return ((unsigned char) (127 - JOYSTICK_SMOOTHING[127 - input]));
}
}


That's a lot of numbers. :) I like it though.

deltacoder1020 10-02-2004 10:56

Re: Desensitizing Joysticks
 
Quote:

Originally Posted by Texan
That's a lot of numbers. :) I like it though.

yeah - it's a lookup table... gonna have a lot of numbers any way you work it. save you the trouble of typing them in, though :)

Phil_Lutz 10-02-2004 21:11

Re: Desensitizing Joysticks
 
We are using an array of values.
First we worked out in excel a parabolic equation for all the values from -127 to +127 (with zero as neutral)
Then input the adjusted speed into the array.
It was decided to have the parabola reach linear at about 1/4 throttle/joystick movement.

unsigned int throttle_curve[50] = {value0,value1,......};

then we write a quick little function to take the motor speed in and transform it.


unsigned int adjust_throttle(unsigned int speed_in)
{
int speed_out;
if (speed_in > 104 && speed_in < 150)
speed_out = throttle_curve[speed_in - 104];
else
speed_out = speed_in;
return speed_out;
}

call it like this.

p1y = adjust_throttle(p1y);

The nice part of this setup is that you just adjust array values to flatten or sharpen the curve.

Phil


All times are GMT -5. The time now is 05:21.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi