Go to Post I think being successful in FIRST is creating an environment where people can grow, learn, change, and recreate... It's about making an environment where kids feel they can be successful... in whatever discipline they choose. - ColleenShaver [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 08-01-2013, 21:36
inkspell4's Avatar
inkspell4 inkspell4 is offline
Registered User
FRC #3650 (Robo Raptors)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Maryland
Posts: 326
inkspell4 will become famous soon enough
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!
__________________
Chesapeake Regional : 2013, 2012, 2011
Rookie Year: 2011
2013 RoboRaptors Team 3650 Programming Team Captain
Team Website : http://www.roboraptorsfrcteam3650.com/index.html
_____________________________________________
Reply With Quote
  #2   Spotlight this post!  
Unread 08-01-2013, 21:41
F22Rapture's Avatar
F22Rapture F22Rapture is offline
College Student, Mentor
AKA: Daniel A
FRC #3737 (4H Rotoraptors)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Goldsboro, NC
Posts: 476
F22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant future
Re: Java programming of an XBox Controller

Quote:
Originally Posted by inkspell4 View Post
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());
__________________
Research is what I’m doing when I don’t know what I’m doing.
- Wernher von Braun
Attending: Raleigh NC Regional

Last edited by F22Rapture : 08-01-2013 at 21:48.
Reply With Quote
  #3   Spotlight this post!  
Unread 08-01-2013, 21:46
inkspell4's Avatar
inkspell4 inkspell4 is offline
Registered User
FRC #3650 (Robo Raptors)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Maryland
Posts: 326
inkspell4 will become famous soon enough
How much do said logitech controllers cost!
__________________
Chesapeake Regional : 2013, 2012, 2011
Rookie Year: 2011
2013 RoboRaptors Team 3650 Programming Team Captain
Team Website : http://www.roboraptorsfrcteam3650.com/index.html
_____________________________________________
Reply With Quote
  #4   Spotlight this post!  
Unread 08-01-2013, 21:52
F22Rapture's Avatar
F22Rapture F22Rapture is offline
College Student, Mentor
AKA: Daniel A
FRC #3737 (4H Rotoraptors)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Goldsboro, NC
Posts: 476
F22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant future
Re: Java programming of an XBox Controller

Quote:
Originally Posted by inkspell4 View Post
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.
__________________
Research is what I’m doing when I don’t know what I’m doing.
- Wernher von Braun
Attending: Raleigh NC Regional
Reply With Quote
  #5   Spotlight this post!  
Unread 08-01-2013, 21:59
inkspell4's Avatar
inkspell4 inkspell4 is offline
Registered User
FRC #3650 (Robo Raptors)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Maryland
Posts: 326
inkspell4 will become famous soon enough
How big is the deadzone on an xbox controller?
__________________
Chesapeake Regional : 2013, 2012, 2011
Rookie Year: 2011
2013 RoboRaptors Team 3650 Programming Team Captain
Team Website : http://www.roboraptorsfrcteam3650.com/index.html
_____________________________________________
Reply With Quote
  #6   Spotlight this post!  
Unread 08-01-2013, 22:12
F22Rapture's Avatar
F22Rapture F22Rapture is offline
College Student, Mentor
AKA: Daniel A
FRC #3737 (4H Rotoraptors)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Goldsboro, NC
Posts: 476
F22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant future
Re: Java programming of an XBox Controller

Quote:
Originally Posted by inkspell4 View Post
How big is the deadzone on an xbox controller?
Depending on the controller, 15-20%
__________________
Research is what I’m doing when I don’t know what I’m doing.
- Wernher von Braun
Attending: Raleigh NC Regional
Reply With Quote
  #7   Spotlight this post!  
Unread 08-01-2013, 22:14
inkspell4's Avatar
inkspell4 inkspell4 is offline
Registered User
FRC #3650 (Robo Raptors)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Maryland
Posts: 326
inkspell4 will become famous soon enough
Quote:
Originally Posted by F22Rapture View Post
Depending on the controller, 15-20%
Have you personally tested these and which is this info based on.
__________________
Chesapeake Regional : 2013, 2012, 2011
Rookie Year: 2011
2013 RoboRaptors Team 3650 Programming Team Captain
Team Website : http://www.roboraptorsfrcteam3650.com/index.html
_____________________________________________
Reply With Quote
  #8   Spotlight this post!  
Unread 08-01-2013, 22:37
F22Rapture's Avatar
F22Rapture F22Rapture is offline
College Student, Mentor
AKA: Daniel A
FRC #3737 (4H Rotoraptors)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Goldsboro, NC
Posts: 476
F22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant future
Re: Java programming of an XBox Controller

Quote:
Originally Posted by inkspell4 View Post
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.
__________________
Research is what I’m doing when I don’t know what I’m doing.
- Wernher von Braun
Attending: Raleigh NC Regional
Reply With Quote
  #9   Spotlight this post!  
Unread 08-01-2013, 23:03
cgmv123's Avatar
cgmv123 cgmv123 is offline
FRC RI/FLL Field Manager
AKA: Max Vrany
FRC #1306 (BadgerBOTS)
Team Role: College Student
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Madison, WI
Posts: 2,085
cgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond repute
Re: Java programming of an XBox Controller

Here's our XBoxController class:

https://github.com/team1306/Badgerbo...ontroller.java
__________________
BadgerBOTS Robotics|@team1306|Facebook: BadgerBOTS
2016 FIRST Championship Tesla Division | 2016 Wisconsin Regional Engineering Inspiration Award

2015 FIRST Championship Carson Division | 2015 Wisconsin Regional Chairman's Award

2013 FIRST Championship Curie Division | 2013 Wisconsin Regional Chairman's Award

2012 FIRST Championship Archimedes Division | 2012 Wisconsin Regional Engineering Inspiration Award, Woodie Flowers Finalist Award (Lead Mentor Ben Senson)

Reply With Quote
  #10   Spotlight this post!  
Unread 09-01-2013, 16:12
inkspell4's Avatar
inkspell4 inkspell4 is offline
Registered User
FRC #3650 (Robo Raptors)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Maryland
Posts: 326
inkspell4 will become famous soon enough
Quote:
Originally Posted by cgmv123 View Post
How effective has it been for you guys to use an xbox controller
__________________
Chesapeake Regional : 2013, 2012, 2011
Rookie Year: 2011
2013 RoboRaptors Team 3650 Programming Team Captain
Team Website : http://www.roboraptorsfrcteam3650.com/index.html
_____________________________________________
Reply With Quote
  #11   Spotlight this post!  
Unread 09-01-2013, 18:07
cgmv123's Avatar
cgmv123 cgmv123 is offline
FRC RI/FLL Field Manager
AKA: Max Vrany
FRC #1306 (BadgerBOTS)
Team Role: College Student
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Madison, WI
Posts: 2,085
cgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond repute
Re: Java programming of an XBox Controller

Quote:
Originally Posted by inkspell4 View Post
How effective has it been for you guys to use an xbox controller
Very. We've had no issues with it.
__________________
BadgerBOTS Robotics|@team1306|Facebook: BadgerBOTS
2016 FIRST Championship Tesla Division | 2016 Wisconsin Regional Engineering Inspiration Award

2015 FIRST Championship Carson Division | 2015 Wisconsin Regional Chairman's Award

2013 FIRST Championship Curie Division | 2013 Wisconsin Regional Chairman's Award

2012 FIRST Championship Archimedes Division | 2012 Wisconsin Regional Engineering Inspiration Award, Woodie Flowers Finalist Award (Lead Mentor Ben Senson)

Reply With Quote
  #12   Spotlight this post!  
Unread 09-01-2013, 21:13
inkspell4's Avatar
inkspell4 inkspell4 is offline
Registered User
FRC #3650 (Robo Raptors)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Maryland
Posts: 326
inkspell4 will become famous soon enough
Quote:
Originally Posted by cgmv123 View Post
Very. We've had no issues with it.
Do you feel the deadzones affected your playing
__________________
Chesapeake Regional : 2013, 2012, 2011
Rookie Year: 2011
2013 RoboRaptors Team 3650 Programming Team Captain
Team Website : http://www.roboraptorsfrcteam3650.com/index.html
_____________________________________________
Reply With Quote
  #13   Spotlight this post!  
Unread 09-01-2013, 22:51
cgmv123's Avatar
cgmv123 cgmv123 is offline
FRC RI/FLL Field Manager
AKA: Max Vrany
FRC #1306 (BadgerBOTS)
Team Role: College Student
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Madison, WI
Posts: 2,085
cgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond repute
Re: Java programming of an XBox Controller

Quote:
Originally Posted by inkspell4 View Post
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.
__________________
BadgerBOTS Robotics|@team1306|Facebook: BadgerBOTS
2016 FIRST Championship Tesla Division | 2016 Wisconsin Regional Engineering Inspiration Award

2015 FIRST Championship Carson Division | 2015 Wisconsin Regional Chairman's Award

2013 FIRST Championship Curie Division | 2013 Wisconsin Regional Chairman's Award

2012 FIRST Championship Archimedes Division | 2012 Wisconsin Regional Engineering Inspiration Award, Woodie Flowers Finalist Award (Lead Mentor Ben Senson)

Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 12:52.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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