Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   need help w/ joystick code (http://www.chiefdelphi.com/forums/showthread.php?t=33854)

willie837 02-02-2005 15:36

need help w/ joystick code
 
I have a single joystick code for my robot, but I don't want it to do anything when i tilt the joystick left and right. I can't figure out how to stop the robot from doing anything when i move the joystick left and right. Please help!

kjohnson 02-02-2005 15:46

Re: need help w/ joystick code
 
Just comment out anything that has to do with the x-axis on the joystick and leave everything with the y-axis.

This may not work correctly but we have never used a one joystick drive so I don't really know if it will work or not. It may be more complicated than just commenting out the x-axis. Taking out the x-axis may actually disturb the mixing function of the code but its worth a try.

Chris Hibner 02-02-2005 15:54

Re: need help w/ joystick code
 
Add a joystick deadzone in the code. For example:

Code:

#define JOY_DEADZONE 10
if (xJ_raw < 127-JOY_DEADZONE)
{
    xJ_raw = xJ_raw + JOY_DEADZONE;
}
else if (xJ_raw > 127+JOY_DEADZONE)
{
    xJ_raw = xJ_raw - JOY_DEADZONE;
}
else
{
    xJ_raw = 0;
}

if (yJ_raw < 127-JOY_DEADZONE)
{
    yJ_raw = yJ_raw + JOY_DEADZONE;
}
else if (yJ_raw > 127+JOY_DEADZONE)
{
    yJ_raw = yJ_raw - JOY_DEADZONE;
}
else
{
    yJ_raw = 0;
}

Of course, the above assumes that the joystick is biased at 127 and you are using unsigned variables for your joystick axes.

JoelP 02-02-2005 21:22

Re: need help w/ joystick code
 
dont even bother with setting up a deadzone.
this is assuming your using the default FRC codes
in user_routines.c go to the void Process_Data_From_Master_uP(void) function
then find the printf statement and change it from this
Code:

printf("Port1 Y %3d, X %3d, Fire %d, Top %d\r",(int)p1_y,(int)p1_x,(int)p1_sw_trig,(int)p1_sw_top);
to this
Code:

printf("Port1 Y %3d, Fire %d, Top %d\r",(int)p1_y,(int)p1_sw_trig,(int)p1_sw_top);
poof, no more x-axis

then to avoid any problems with the mixer, just remove it and replace it with another code to set pwm values to the y-axis
ex.
Code:

pwm01=p1_y
pwm02=254 - p2_y /*to reverse the pwm signals if you want,
                            instead of reversing the motor polarity*/


devicenull 02-02-2005 22:47

Re: need help w/ joystick code
 
Taking out the x axis on single joystick is a bad idea. AFAIK, its just going to go only forward or backward, because theres nothing there telling it to turn.

JoelP's code is going to give you forward and reverse only... which would be fine for tank drive (2 joysticks), but not single

JoelP 02-02-2005 23:12

Re: need help w/ joystick code
 
Perhaps their design uses the joystick buttons or auxillary switches to control turning. I don't see the advantages of that design, but hey, its their robot.

Alan Anderson 02-02-2005 23:17

Re: need help w/ joystick code
 
Quote:

Originally Posted by willie837
I have a single joystick code for my robot, but I don't want it to do anything when i tilt the joystick left and right.

A single joystick with no left/right action will give you only one axis of control. At first glance, it looks like you're asking for a robot which will only go forward and backward, and never turn. The easiest way to do that is to replace every occurrence of p1_x in the user_routines.c file with the constant 127.

But that can't be what you want. Are you perhaps asking how to keep the robot from turning in place when you aren't also moving forward or backward? That's conceptually easy, and I could probably change the code myself to do it in about 30 seconds, but it's not easy to describe to a novice programmer. Try changing every occurrence of p1_x to the following:
Code:

(((p1_y<137)&&(p1_y>117))?127:p1_x)
Basically, this keeps the x-axis value at neutral when the y-axis value is within 10 of neutral.


All times are GMT -5. The time now is 17:31.

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