PDA

View Full Version : Programming Specific Button Input on Controller


Mikesername
01-17-2009, 04:14 PM
Hey,
Searching didn't help much, mainly because I didn't know how to phrase the query...

But what I want to know is, how could I program a specific button input on the controller? i.e., programming the trigger to activate a motor when pressed...

I know I'm being a little vague but I don't really know how to phrase this question :\

Thanks,
Mike

Alexa Stott
01-17-2009, 04:17 PM
In WindRiver, you can use joystickname.GetTrigger() and joystickname.GetTop() for the trigger and the top. You can then use joystickname.GetRawButton(button number).

Replace joystickname with the name of your joystick variable. Replace button number with the number of the button (each button is labelled by number on the kit joysticks).

GetTrigger, GetTop, and GetRawButton return true or false.

Mikesername
01-17-2009, 04:19 PM
How about in LabView?

Thanks for the quick reply, btw :)

keehun
01-17-2009, 04:22 PM
Yes!

Now, you haven't mentioned if you use LabView or C, but for LabView this is what you would do:

Use the "Joystick -> Get" VI. It's under WPI libraries -> RobotDrive-> Joysticks -> Get

You first need to open a "channel" to that joystick. Then pass in the JoystickDevRef from the OPEN to GET

There are two outputs, one for axis and one for buttons. You need a "Unbundle" vi. It's in Programming->Clusters->Unbundle (you have two choices, by name or just by blocks)

Then you can select which button to read and it will give you a true or a false.

keehun

edit: wow you guys respond fast ;-) (while I was typing he mentioned that he used labview)

Alexa Stott
01-17-2009, 04:22 PM
How about in LabView?

Thanks for the quick reply, btw :)

I have only worked for a bit in LabView, but I believe you could just use the blocks that are available in the WPILib. It has all the same functions available, but everything is a block, not actual code. You should be able to "wire" everything in LabView so that if one of the functions returns "true," it turns on the motor. If "false," it turns it off.

Sorry I cannot give more specific instructions than this. Perhaps someone who has worked more with LabView would be able to help.

Edit: keehun just posted the appropriate instructions above.

ShotgunNinja
01-17-2009, 04:37 PM
Also, it is possible to make a subVI that lets you select a single button output. Here's a copy of a subVI that I threw together (Sorry, haven't really tested it that much, let me know how it works!). You have to use an unsigned 16-bit int for the "index" pin, can't seem to figure out why (It says "wire enumeration conflict"). I guess speed of recursions doesn't really matter, but it's theoretically slightly faster than using the Joystick Get VI.

Mikesername
01-17-2009, 05:03 PM
Keehun, I tried what you said and I've gotten this far:

http://img240.imageshack.us/img240/5066/joystickinputwd9.png

After this, I'm confused... how do I specify button from axis..?


(btw, rookie team/freshman)

EDIT: I cleaned up the wire so I'm not opening two channels for the same USB and the joystick get just comes off of the same wire now, I was just too lazy to retake the SS, so I don't need comments on how that's messed up :P

TotalChaos
01-17-2009, 05:21 PM
Mikesername,

I think I have to solution to what you are trying to do posted in another thread. Check it out HERE (http://www.chiefdelphi.com/forums/showthread.php?t=72126).

I hope it's what you're looking for.

Good luck!

- Austin

Mikesername
01-17-2009, 05:34 PM
@Austin:
Thanks! Your post with diagrams really helped!

If I have any other questions about it, (which I probably will :P) I'll ask.

Thanks guise.