Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Java programming of an XBox Controller (http://www.chiefdelphi.com/forums/showthread.php?t=110777)

inkspell4 08-01-2013 21:36

Java programming of an XBox Controller
 
How could we use an xbox controller to control our robot?

Does anyone have a drawing of which buttons correspond to what numbers and what axis' correspond to what numbers?

Any help would be appreciated!

F22Rapture 08-01-2013 21:41

Re: Java programming of an XBox Controller
 
Quote:

Originally Posted by inkspell4 (Post 1211075)
How could we use an xbox controller to control our robot?

Yes, you could, but I would recommend against it. The Xbox Controller has fairly large (and inconsistent) deadzones around the center of the sticks. The logitech joysticks provide better accuracy.

Quote:

Does anyone have a drawing of which buttons correspond to what numbers and what axis' correspond to what numbers?

Any help would be appreciated!
If you just want the button bindings, scroll to the bottom. Otherwise, you can use this class to simplify things.

Code:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.usfirst.Rotoraptors.controls.hids;

import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.buttons.*;

/**
 *
 * @author Daniel
 */

public class XboxController {
   
    private Joystick m_pad;
   
    public XboxController(int port) {
        m_pad = new Joystick(port);
    }
   
    public double getLeftX() {
        return m_pad.getRawAxis(LEFT_X_AXIS);
    }
   
    public double getLeftY() {
        return m_pad.getRawAxis(LEFT_Y_AXIS);
    }
   
    public double getRightX() {
        return m_pad.getRawAxis(RIGHT_X_AXIS);
    }
   
    public double getRightY() {
        return m_pad.getRawAxis(RIGHT_Y_AXIS);
    }
   
    public double getTriggers() {
        return m_pad.getRawAxis(TRIGGERS);
    }
   
    public double getDpadX() {
        return m_pad.getRawAxis(DPAD_LR);
    }
           
    public double applyDeadband(int axis) {
        if(Math.abs(m_pad.getRawAxis(axis)) < .1) {
            return 0;
        } else {
            return axis;
        }
    }         
   
    // Creates buttons
    public Button X = new JoystickButton(m_pad, BUTTON_X);
    public Button Y = new JoystickButton(m_pad, BUTTON_Y);
    public Button A = new JoystickButton(m_pad, BUTTON_A);
    public Button B = new JoystickButton(m_pad, BUTTON_B);
    public Button lBumper = new JoystickButton(m_pad, BUMPER_L);
    public Button rBumper = new JoystickButton(m_pad, BUMPER_R);
    public Button start = new JoystickButton(m_pad, BUTTON_START);
    public Button back = new JoystickButton(m_pad, BUTTON_BACK);
    public Button lStick = new JoystickButton(m_pad, LEFT_STICK_PRESS);
    public Button rStick = new JoystickButton(m_pad, RIGHT_STICK_PRESS);
   
    public boolean getButton(int btn) {
        return m_pad.getRawButton(btn);
    }
   
    // Axis indexes:
    public static final int
            LEFT_X_AXIS = 1,
            LEFT_Y_AXIS = 2,
            TRIGGERS = 3,
            RIGHT_X_AXIS = 4,
            RIGHT_Y_AXIS = 5,
            DPAD_LR = 6;
   
    // Button mappings:
    public static final int
            BUTTON_A = 1,
            BUTTON_B = 2,
            BUTTON_X = 3,
            BUTTON_Y = 4,
            BUMPER_L = 5,
            BUMPER_R = 6,
            BUTTON_BACK = 7,
            BUTTON_START = 8,
            LEFT_STICK_PRESS = 9,
            RIGHT_STICK_PRESS = 10;
   
}

Which you can call the same way you call regular Joysticks (in regards to where you put it and the information you provide to the method), ie:

Code:

    XboxController driverXbox = new XboxController(1);
    XboxController operatorXbox = new XboxController(2);

It also creates the buttons for you so you can keep your OI code cleaner.

Code:

driverXbox.A.whenPressed(doSomething());

inkspell4 08-01-2013 21:46

How much do said logitech controllers cost!

F22Rapture 08-01-2013 21:52

Re: Java programming of an XBox Controller
 
Quote:

Originally Posted by inkspell4 (Post 1211086)
How much do said logitech controllers cost!

The Attack 3s should have come with your Rookie KoP... if not, $20-$25

If you're dead-set on using a gamepad, the Logitech F310 is about the same price, and also has both thumbsticks at the bottom of the controller so tank drive is less awkward. And they seem to have less deadzone than the Xbox controllers.

inkspell4 08-01-2013 21:59

How big is the deadzone on an xbox controller?

F22Rapture 08-01-2013 22:12

Re: Java programming of an XBox Controller
 
Quote:

Originally Posted by inkspell4 (Post 1211096)
How big is the deadzone on an xbox controller?

Depending on the controller, 15-20%

inkspell4 08-01-2013 22:14

Quote:

Originally Posted by F22Rapture (Post 1211100)
Depending on the controller, 15-20%

Have you personally tested these and which is this info based on.

F22Rapture 08-01-2013 22:37

Re: Java programming of an XBox Controller
 
Quote:

Originally Posted by inkspell4 (Post 1211101)
Have you personally tested these and which is this info based on.

I pulled up Xpadder and looked at the raw ouput. Mine was about 18%. Some seem to have more, some less.

cgmv123 08-01-2013 23:03

Re: Java programming of an XBox Controller
 
Here's our XBoxController class:

https://github.com/team1306/Badgerbo...ontroller.java

inkspell4 09-01-2013 16:12

Quote:

Originally Posted by cgmv123 (Post 1211145)

How effective has it been for you guys to use an xbox controller

cgmv123 09-01-2013 18:07

Re: Java programming of an XBox Controller
 
Quote:

Originally Posted by inkspell4 (Post 1211624)
How effective has it been for you guys to use an xbox controller

Very. We've had no issues with it.

inkspell4 09-01-2013 21:13

Quote:

Originally Posted by cgmv123 (Post 1211717)
Very. We've had no issues with it.

Do you feel the deadzones affected your playing

cgmv123 09-01-2013 22:51

Re: Java programming of an XBox Controller
 
Quote:

Originally Posted by inkspell4 (Post 1211901)
Do you feel the deadzones affected your playing

We don't really use the joysticks (we do our driving with the Attack 3's), but when we do we just have extra wide deadbands. We've found our controller sometimes doesn't return exactly to zero.


All times are GMT -5. The time now is 10:02.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi