|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
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!
|
|
#2
|
||||
|
||||
|
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. |
|
#3
|
||||||
|
||||||
|
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;
}
|
|
#4
|
|||
|
|||
|
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);
Code:
printf("Port1 Y %3d, Fire %d, Top %d\r",(int)p1_y,(int)p1_sw_trig,(int)p1_sw_top);
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*/
Last edited by JoelP : 02-02-2005 at 21:30. |
|
#5
|
|||
|
|||
|
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 |
|
#6
|
|||
|
|||
|
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.
|
|
#7
|
|||||
|
|||||
|
Re: need help w/ joystick code
Quote:
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) Last edited by Alan Anderson : 02-02-2005 at 23:21. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Team THRUST - Kevin's Code and Camera Code Combine | Chris_Elston | Programming | 3 | 31-01-2005 22:28 |
| Help with code single joystick | JamesBrown | Programming | 9 | 19-01-2005 00:42 |
| heres the code. y this not working | omega | Programming | 16 | 31-03-2004 15:18 |
| Changing 1 joystick code to 2 (rookie team) | Brawler006 | Programming | 5 | 20-02-2004 17:00 |
| robot goes haywire with the one joystick default code | Miles | Programming | 7 | 24-01-2003 14:58 |