Xbox Controller Axis 3

Hello. My team has decided that we are using the xbox controller for our regional competition. I have it all done except one thing that i cant quite get to work right. The two trigger buttons at the top back of the xbox controller I believe is Axis 3. We are trying to get the left side to activate one solenoid and the right side to activate the other. Is this possible since its not like a normal button that is a boolean and if so how can I go about this? Thansk.

    solenoid.set(controller.getRawAxis(3) < -0.7)

If you’re not entirely sure what axis it is, go to Run and type “joy.cpl” without quotes. There should be a mapping under the Properties tab (while the controller is plugged in). The triggers together are actually one axis, with the left side being zero through negative one and the right side being zero through positive one. That way, synchronous triggers always equal 0 (both pressed, neither pressed, both half-pressed, and so on). I think you would probably be better off with the bumpers (because they’re boolean, like solenoids; on or off) for your purpose. Just my thoughts :stuck_out_tongue:

if (triggeraxis > 0)//Room for error? change 0 to 0.5
    //solenoid 1
else if (triggeraxis < 0) //should be some room for error, like -0.5
    //solenoid 2
   //set solenoid 1 and 2 to off

In my XboxController class I have it setup so that the trigger axis pretends to be buttons. You can even use them with the Button class to start commands in the CommandBased Structure:

nothing is working

Is it communicating with your computer? Are the drivers installed? If joy.cpl shows it’s not working, it’s not the code.

It is communicating.

Are you pressing both triggers at the same time? Because if so, that won’t work.

What our team did to test the xbox controllers was something along the lines of this code:

for (int i = 1; i <= 6; i ++)
System.out.println("AXIS "+i +" READS "+joystick.getRawAxis(i);

If you run this in your teleop code, and monitor the NetConsole, you should see Axis 3 read a value of near 0when neither trigger is pressed, a value of near 1 when one trigger is pressed, and a value of near -1 when the other is pressed.
If you can confirm that Axis3 does behave in that manner, then joelg236’s code should work with the addition of setting another solenoid when the value is > 0.7.

It would help if we could see your code.

Sorry guys. The code was right, but wasn’t working because the solenoid wires got crushed and needed rewired. Thanks for your help.

Glad to hear your problem was resolved!