|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Programing joystick buttons
Could someone please help me? I've been trying to figure out how to program the joystick buttons to make the motors move. I looked through the code samples, and the default code and I found nothing that I can understand properly.
My past experience with C is MikroC which is different than programing the FIRST FRC robots. Thanks in advance! |
|
#2
|
||||
|
||||
|
Re: Programing joystick buttons
The joystick buttons should follow this sort of naming convention:
Code:
p1_sw_aux1 p1_sw_aux2 p1_sw_trig p1_sw_top You should be able to work these with a simple if statement, something like: Code:
if (p1_sw_aux1){
pwm01=255;
} else {
pwm01=127;
}
|
|
#3
|
||||
|
||||
|
Re: Programing joystick buttons
there's also of course the joystick values themselves (p1_y, p1_x, p2_y...), and the wheel values (p1_wheel) (look on other threads for the output)
|
|
#4
|
||||
|
||||
|
Re: Programing joystick buttons
ok, i'll assume you're using port 1 on the operator interface (OI). just because i'm not sure what you know up to this point (and who's reading) i'll just give a brief intro.
as you know, the port your joystick is plugged into is referrred to as pX_something, so it will be p1_..... the analog outputs are p1_y, the y-axis, p1_x, the x-axis, p1_wheel, p1_aux ...these are not used as far as i know on the KOP joysticks (possibly the hat on the top?), but they ARE used with the USB ckicklet if you're using that.... now, the analog buttons are: p1_sw_trig, the trigger, p1_sw_top, one of the buttons, i'm not sure which, as with p1_sw_aux1 and p1_sw_aux2. that's about it! |
|
#5
|
||||
|
||||
|
Re: Programing joystick buttons
Are you using a Robotics IDE (ROBOTC, EasyC, etc.), or are you using a regular C editor? I've found EasyC to be just that, easy. If you are this early on in the programming, you can still switch over to EasyC (or another), and have that much already taken care of for the programming, so you can focus on other things like figuring out the best way to pull off Hybrid Mode.
In EasyC, you could do it in about 6 lines of code. EDIT: By the way, yes; the p1_wheel does refer to the "hat", and I believe that there is also p1_sw_thumb for the thumb button (or would that be what p1_sw_top goes to?) Last edited by ShotgunNinja : 03-02-2008 at 19:17. |
|
#6
|
||||
|
||||
|
Re: Programing joystick buttons
I'm surprised it takes that much. In MPLAB, it is just four:
Code:
if(p1_sw_top) pwm01 = 254; else pwm01 = 127; Code:
if(p1_sw_top){
pwm01 = 254;
} else {
pwm01 = 127;
}
p1_sw_top is the top button on CH flightsticks and, I believe, one of the buttons on the top of the AVB Top Shots. I think the thumb button is either another trigger or top button... the wiring in those AVB sticks is darn confusing. |
|
#7
|
||||
|
||||
|
Re: Programing joystick buttons
Well, actually, we're using two AVB (or is it ADB? It looks kind of like that
) sticks for our OI, and using EasyC for programming, we don't need to use the p1_sw_(fill in the blanks) variables, as we can just use a single function to bind everything together. It hurts my pride acquired from slaving over the Source Engine code to use such simplified functions, thus limiting my amount of precise control, but it goes a lot faster, and it works. ![]() EDIT: And those six lines set up the entire operator interface. Just a by-the-way. |
|
#8
|
|||||
|
|||||
|
Re: Programing joystick buttons
Quote:
Code:
pwm01 = p1_sw_top?254:127; |
|
#9
|
||||
|
||||
|
Re: Programing joystick buttons
it mostly depends on which controler you are using, if your using controler 1:
p1_sw_trig p1_sw_top p1_sw_aux1 p1_sw_aux2 to program the buttons is acutally very simple pwm01 = 127 if (p1_sw_trig == 1) {pwm01 = 150} this program says "while controler 1's trigger is being pressed, pwm01 will move at 150" this is the way i was taught anyway, the other ways will work also |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Buttons to Pins on Joystick | yarb65 | Electrical | 1 | 24-08-2007 20:39 |
| Programming Extra Joystick Buttons | Inverted | Programming | 2 | 08-02-2007 11:45 |
| Victors Controlled By Joystick Buttons | douglass1371 | Electrical | 2 | 17-02-2006 01:57 |
| Programing a joystick | Justin_302 | Programming | 2 | 21-03-2005 22:45 |
| Assigning Joystick buttons.... | archiver | 2001 | 5 | 24-06-2002 00:59 |