Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Need Help with Sensitivity of Joysticks (http://www.chiefdelphi.com/forums/showthread.php?t=63069)

iwin2000 01-02-2008 18:58

Need Help with Sensitivity of Joysticks
 
I'm trying to decrease the maximum range of the joystick on the x-axis using EasyC because the robot turns too fast on the x-axis. I tried using arcade mode at first, but I don't see a way of limiting the joystick range or the PWM output via the Arcade function.

What I tried to do was limit the PWM input. As a test, instead of being 0 (Minimum output), it is now 77, and it is 177 as a maximum. I used the following code and it doesn't seem to work. Does anyone know how I can do this?

Code:

unsigned char Port1XAxis = 127;
while ( 1 )
{
OIToPWM ( Port1XAxis , 1 , 1 , 0 ) ;

if ( Port1XAxis <= 77 )
{
Port1XAxis = 77 ;
//SetPWM ( 2 , 177 ) ;
//SetPWM ( 1 , 177 ) ;
}

else if ( Port1XAxis >= 177 )
{
Port1XAxis = 177 ;
//SetPWM ( 2 , 77 ) ;
//SetPWM ( 1 , 77 ) ;
}
Arcade2 ( 1 , 2 , 0 , 0 , 2 , 1 , 1 , 1 ) ;

I know this code has some errors, but can someone help me figure out how to do something like this?

Thanks a lot.

JohnC 01-02-2008 19:14

Re: Need Help with Sensitivity of Joysticks
 
We used this to scale our drive last year. The "Offset" is referring to how far the joystick's Y-axis potentiometer is from 127.

Code:

int Scale_Offset(int initialValue, double scaleFactor) {
        return ((double)(initialValue-127)/scaleFactor)+127;
}

In context, it looked like this:

pwm05 = Scale_Offset(p1_y,3.);

iwin2000 02-02-2008 01:49

Re: Need Help with Sensitivity of Joysticks
 
That's right and I actually tried to do a function like that, but I am using EasyC's 'Arcade 2-motor' function to be able to control all motors through one joystick and it doesn't seem to allow for any input like that.

In Arcade mode, Y-Axis movement indicates forward/reverse, and X-Axis indicates right/left, and what I want to do is limit the X-Axis max PWM to something to slow it down (maybe minimum value of 77 and max of 177).

Does anyone know if/how I can do this in EasyC?

xrabohrok 02-02-2008 13:36

Re: Need Help with Sensitivity of Joysticks
 
My team has been using a speacial sin curve array to tone down the sensitivity. It has kind of been a hand-me-down for four years now.

Code:

const rom unsigned char joystick_values[256] =  { 
0,  0,  0,  0,  0,  0,  0,  0, // 0  - 7
 
0,  0,  0,  0,  0,  8,  16,  24, // 8  - 15
   
30,  36,  41,  45,  50,  53,  57,  60, // 16  - 23
   
63,  65,  68,  70,  72,  74,  76,  78, // 24  - 31
 
80,  81,  83,  84,  86,  87,  88,  89, // 32  - 39
   
90,  91,  92,  93,  94,  95,  96,  97, // 40  - 47
 
98,  98,  99, 100, 101, 101, 102, 102, // 48  - 55
 
103, 104, 104, 105, 105, 106, 106, 107, // 56  - 63
 
107, 108, 108, 109, 109, 110, 110, 110, // 64  - 71
 
111, 111, 112, 112, 112, 113, 113, 114, // 72  - 79
 
114, 114, 115, 115, 115, 116, 116, 116, // 80  - 87

117, 117, 117, 117, 118, 118, 118, 119, // 88  - 95
 
119, 119, 120, 120, 120, 120, 121, 121, // 96  - 103
 
121, 121, 122, 122, 122, 122, 123, 123, // 104 - 111
 
123, 124, 124, 124, 124, 125, 125, 125, // 112 - 119
 
125, 126, 126, 126, 126, 127, 127, 127, // 120 - 127
 
127, 127, 128, 128, 128, 128, 129, 129, // 128 - 135
 
129, 129, 130, 130, 130, 130, 131, 131, // 136 - 143
   
131, 132, 132, 132, 132, 133, 133, 133, // 144 - 151
   
133, 134, 134, 134, 134, 135, 135, 135, // 152 - 159
   
136, 136, 136, 137, 137, 137, 137, 138, // 160 - 167
   
138, 138, 139, 139, 139, 140, 140, 140, // 168 - 175
   
141, 141, 142, 142, 142, 143, 143, 144, // 176 - 183
   
144, 144, 145, 145, 146, 146, 147, 147, // 184 - 191
   
148, 148, 149, 149, 150, 150, 151, 152, // 192 - 199
   
152, 153, 153, 154, 155, 156, 156, 157, // 200 - 207
   
158, 159, 160, 161, 162, 163, 164, 165, // 208 - 215
   
166, 167, 168, 170, 171, 173, 174, 176, // 216 - 223
   
178, 180, 182, 184, 186, 189, 191, 194, // 224 - 231
   
197, 201, 204, 209, 213, 218, 224, 230, // 232 - 239
   
238, 246, 255, 255, 255, 255, 255, 255, // 240 - 247
   
255, 255, 255, 255, 255, 255, 255, 255  // 248 - 255
};

It's worked for us. Just put the array like this:

Code:

pwm_01 = joystick_values[p1_y];
Do this for all pwm's you want dampend. Hope it works.

As for limiting speed, I have no idea what the arguments of the Arcade function are. If set pwms are what you are using to change the pwm values, they are commented out (you probably know that already). You also have it set 177 on the 77 if statement and 77 on the 177 if statement. Would switching those two help?

psy_wombats 02-02-2008 13:43

Re: Need Help with Sensitivity of Joysticks
 
As far as joystick sensitivity goes, our team has been using this:

Code:

long ramping (unsigned char ramp)
{
    long answer = 0;
    answer =  ((long)ramp - 127);
    answer = ((answer) * (answer) * (answer));
    answer = ((answer) / (128 * 128));
    answer = (answer) + (127);
    return answer;
}

It's not a sine function, but cubic. You should be able to have max speed at full forward, but also have better control with lower values. Something like:

http://www.chiefdelphi.com/forums/at...9&d=1201127844

jacobhurwitz 02-02-2008 14:21

Re: Need Help with Sensitivity of Joysticks
 
Quote:

Originally Posted by psy_wombats (Post 690739)
As far as joystick sensitivity goes, our team has been using this:

Code:

long ramping (unsigned char ramp)
{
    long answer = 0;
    answer =  ((long)ramp - 127);
    answer = ((answer) * (answer) * (answer));
    answer = ((answer) / (128 * 128));
    answer = (answer) + (127);
    return answer;
}

It's not a sine function, but cubic. You should be able to have max speed at full forward, but also have better control with lower values. Something like:

http://www.chiefdelphi.com/forums/at...9&d=1201127844

We're using a quadratic function. The only problem is that x*x is always positive, so we defined an absolute value function and do x*abs(x).


All times are GMT -5. The time now is 23:44.

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