Log in

View Full Version : Programming the joystick trigger...


pudgeball
10-01-2009, 09:12
I have searched through forum after forum. And looked as much source code as I could get my hands on. However I can't find how to program the joystick trigger. 2386 is using the joystick provided in the K.O.P. and we are trying to program the trigger like;

if (trigger is down)
{
//Execute code
}

//Edit: Also we are using WindRiver

JDM
10-01-2009, 09:47
There's a function of the Joystick class called "GetTrigger".

So, the code that you would want to use would be something like the following, where m_Stick is the name of the Joystick object that you want to check.

if (m_Stick->GetTrigger()) {
...
}

I hope this helps.

Dave Scheck
10-01-2009, 09:52
Look into the Joystick class of WPILib. It provides methods to get axes and buttons. You can see the following methods available in Joystick.hvirtual bool GetTrigger(JoystickHand hand = kRightHand);
virtual bool GetTop(JoystickHand hand = kRightHand);
virtual bool GetBumper(JoystickHand hand = kRightHand);
virtual bool GetButton(ButtonType button);
bool GetRawButton(UINT32 button);
Hope that puts you on the right track.

Dave Scheck
10-01-2009, 09:58
JDM - The only problem with GetTrigger is that it makes the assumption that the trigger button is coming in as raw button 1. This is probably fine for the default joysticks in the KOP, but if you switch to something like a gamepad, trigger might not make as much sense. You can drop this in your code to quickly see what the button mapping is using the raw buttons. Once you know the mapping you can decide whether to use the built in methods (like GetTrigger) or to go get the raw button yourself.for(int i = 0; i < 12; i++)
{
printf("%d:%d ", i + 1, driveStick->GetRawButton(i + 1));
}

pudgeball
10-01-2009, 10:25
There's a function of the Joystick class called "GetTrigger".

So, the code that you would want to use would be something like the following, where m_Stick is the name of the Joystick object that you want to check.

if (m_Stick->GetTrigger()) {
...
}

I hope this helps.


The one thing I find when we try to use '->' is that I get an error; "error: base operand of `->' has non-pointer type `Joystick'". So my around that error was/is;

if (m_Stick.GetTrigger()) {
...
}

I finally did get the code to work. With that fix mentioned above. But thank you for your help.