Help in coding an Xbox controller in addition to a joystick

Hey all, right now we are running a mecaum drive robot. We have our mec drive coded to our Logitech joy stick, which is great. We wanna keep that. But our problem comes in when we want to operate our lift system. We have two pivot points that we would like to control with separate joysticks. We figured we would use an xbox 360 controller for that. I have all the buttons and our first pivot point coded however I am having trouble coding in the second joystick/left analog stick on the xbox controller. Is this impossible to do, I don’t think so. Any help would be greatly appreciated. Thanks here’s my code right now.

The Xbox Controller has six axes that you can read from. You can use the Driver Station USB tab to figure out the axis number of whatever you’re interested in, and then pick up that axis in your LabVIEW code.

So it looks like I want to code to the r x-y axes and the l x-y axes but I dont know how to do this, might you know how?

In the Joystick/GetValues.vi, it looks like you are already reading axes 2 and 3 (I can’t quite tell, as it’s cut off). You can read more axes there, similar to how you are reading several buttons just above.

So do I just add two more arrays of can it will code too the the other axis

I don’t know which joystick is which in your setup - I’m assuming Joystick 0 is your logitech joystick.

Let’s assume Joystick 1 is your Xbox controller. You’ll need something like the following:

“Joystick 1” -> Joystick/GetReference -> Joystick/GetValues -> Index into Array (selecting axes 0 and 1, or possibly 2 and 3) -> into whatever logic you have for controlling things.

Can somebody with LabVIEW installed show @SagaFraga how to pull in axes from an additional joystick?

To read inputs from 2 different joysticks/controllers (the kind of controller does not affect your code and you will simply need to order them properly in the driverstation for the expected behavior to occur) you simply need to add a new joystick to begin.vi and put it on USB 1 with a different refnum.

In your robot’s code, you can duplicate the code from joystick 0 to read inputs from joystick 1

Begin.vi
joy

Teleop.vi
tele

On another note, I see you’ve written your code in teleop rather than periodic tasks, make sure you put an infinite loop refering to teleop in autonomous.vi to be able to pilot your robot in autonomous mode

Yes I have done that, Its trying to run it with both a joystick and an box controller. So that’s three points of articulation I nee’d, i guess.

Our team has been using XBox joysticks for several years with LabVIEW and we find that is is useful to name the buttons and axes appropriately to prevent common programming errors. You may want to consider using a vi like our XBOX_Joystick_Name.vi (view online). Then you can just hook up the outputs of Joystick Get Values to this naming VI and unbundle which buttons or axes you care about.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.