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!

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.

Add a joystick deadzone in the code. For example:

#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;
    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;
    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.

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

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

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

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

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

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.

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:


Basically, this keeps the x-axis value at neutral when the y-axis value is within 10 of neutral.