Log in

View Full Version : joystick button


furiousgeorge
07-02-2009, 13:04
hey, i'm trying to program a motor to run off of a button on the joystick (preferably the trigger button) but i'm not sure exactly how to do that can someone help me?

bwobo
07-02-2009, 13:52
If you look in the SimpleRobot example class it shows a joystick defined:

Joystick *joystickname;
//then later:
joystickname = new Joystick (1) //where "1" is, is the USB port on the Driver Station in which the joystick is plugged into.
//then in your teleop code:
if (joystickname -> GetRawButton(button #)){
//put code here for which motor to run
}


Of course this is with WindRiver and C++, LabView you will need someone else's help on

EDIT:
Saw your other thread.
This code will make it so when you hold a button down the specified motor runs.
If you want it so one button sends it forward, and another backward, its the same thing, just another if statement. (in one if statement, set the motor to a value of 1 (makes it go forward full speed), then in the other if statement, set the motor to a value of -1 (full speed in reverse)
If you want it so you only have to press the button once for it to start, then again for it to stop, you need to create a boolean for the motor running, and have the button set it true or false.

furiousgeorge
07-02-2009, 14:45
yeah, i'm using labview, thanks though

Greg McKaskle
07-02-2009, 15:37
Break the problem down. First see if you can figure out how to read the joystick button.

Next use the Motor WPI VIs to set the motor speed to 0 or some nonzero value to control the speed.

Now put the two together so that the button Boolean selects one of two speeds.

If you want the button to be sticky, you need storage such as a feedback node, a shift register, or a variable.

If this doesn't help, ask for specifics on the part above you can't figure out.

Greg McKaskle

furiousgeorge
07-02-2009, 15:42
i'm sorry but i'm a rookie, and none of what you just said really made any sense

Greg McKaskle
07-02-2009, 15:57
Programming involves breaking big tasks down into small tasks that you know how to do. First figure out how to read a joystick button. You might want to look at examples, or show the context help window and look at the palette of icons for reading the joystick.

Then move on to the other steps.

Greg McKaskle