![]() |
Xbox Controller
I got help earlier but I have tried to program one in and just cant figure it out. I am completely lost and need lots of help so if anyone out there is willing id be forever grateful.
THANKS! |
Re: Xbox Controller
Its just like any other controller, except with more axes and buttons. See the following post: http://www.chiefdelphi.com/forums/sh...51&postcount=4. Go to "Run" on your computer and type in "joy.cpl" (without quotes, with the controller plugged in). Then go to properties to see the button numbers.
|
Re: Xbox Controller
|
Re: Xbox Controller
I sorry but I have tried for hours now and just cant seem to figure out how to implement both your ways. Like how do I use buttons - because the regular "button.whenPressed(new exampleCommand());" isn't working. How do I make it work with tankdrive when there are not two joysticks connected but rather one controller. I am sooooo confused and I tried to figure it out on my own but I have gotten nowhere.
THANKS for the help. |
Re: Xbox Controller
Can we see the code you have so far?
Assuming you're using a RobotDrive object to control your drivetrain, and the tankDrive method, your Xbox controller (like ekapalka said) should behave much like a pair of joysticks in tank drive - with each Xbox stick controlling one side of the drivetrain. Code:
drive.tankDrive(gamepad.getLeftStickY(), gamepad.getRightStickY(); |
Re: Xbox Controller
Okay - im still confused about how to implement it in my DriveTele command and how to make buttons work.
Here's is the Chassis subsystem - I think I have this figured out: Code:
package edu.wpi.first.XBoxBot2014.subsystems;Code:
package edu.wpi.first.XBoxBot2014.subsystems;Code:
boolean button = xcon2.getWHATEVER()Code:
button.whenPressed or button.when releasedCode:
package edu.wpi.first.XBoxBot2014; |
Re: Xbox Controller
Quote:
The JoystickButton constructor takes a human interface device (Xbox controller object) and a button number as parameters. In your code, you could do the following: Code:
package edu.wpi.first.XBoxBot2014;Code:
public void driveTele(Joystick leftStick, Joystick rightStick){Replace the parameters with doubles, and take advantage of the fact that tankDrive() will also take a leftValue and rightValue as input: Code:
public void driveTele(double leftValue, double rightValue){Hope it works! |
Re: Xbox Controller
Thanks soooo much. It all worked except for the
Code:
private Button button = new JoystickButton(xcon2, 1);Quote:
|
Re: Xbox Controller
Quote:
So for the A button it would be: Code:
Joystick joystick = new Joystick(1);Code:
oi.joystick.getRawAxis(7); //Left stick-create getter methods for each of the buttons and axis -create static constants that hold the mapped button numbers and axis If you'd like more information on how to do this I can assist you there too. |
Re: Xbox Controller
Quote:
Code:
public class XBoxController extends GenericHID{notmattlythgoe's suggestion is much better, but for a quick fix right now this should work. |
Re: Xbox Controller
Okay I get it - but why cant I just continue to use
Code:
Joystick joystick = new Joystick(1);Code:
private Button button = new JoystickButton(joystick, joystick.getRawButton(0));And if it is completely necessary to do so I would need some help - I have an idea of what to do but I would still need some guidance. THANKS! |
Re: Xbox Controller
Quote:
Just using the JoystickButton along with the Joystick class is a perfectly fine way to do it. So for you I'd suggest you stick with the below for now. Code:
Joystick joystick = new Joystick(1); |
Re: Xbox Controller
@NWChen I tried that but it didn't work - THANKS though!
@notmattlythgoe In that case id like to do it - wouldn't it be a lot like the XBoxController class other than the fact that it extends the Joystick class - at least the getters would be the same |
Re: Xbox Controller
Quote:
You'll want to get rid of the getRaw...() methods from the XBoxController class because you get those automatically from extending the Joystick class. Also remove the port and driver station fields since the Joystick class takes care of that communication for you. Don't forget to include a single parameter constructor that calls the Joystick constructor. Then what you'll want to do is create a list of static final variables that hold the mapping values for the buttons, this way you don't have to memorize what button maps to what value. I would also suggest using these static fields as the values in the getter methods, this way if you ever have to change the value you only have to change it in one place. Example: Code:
public static final int A_BUTTON = 0;Code:
public boolean getButtonA() {Code:
XBoxController joystick = new XBoxController(1); |
Re: Xbox Controller
Ok AWESOME - now this may seem like a dumb question to you but im a beginner programmer so here it is
How exactly do I extend the Joystick class - I tried it like this: Code:
public class XBox extends Joystick {When you say Quote:
Quote:
|
| All times are GMT -5. The time now is 10:42. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi