Thread: Xbox Controller
View Single Post
  #7   Spotlight this post!  
Unread 23-06-2014, 02:13
NWChen's Avatar
NWChen NWChen is offline
Alum
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: New York City
Posts: 205
NWChen is a splendid one to beholdNWChen is a splendid one to beholdNWChen is a splendid one to beholdNWChen is a splendid one to beholdNWChen is a splendid one to beholdNWChen is a splendid one to beholdNWChen is a splendid one to behold
Re: Xbox Controller

Quote:
Originally Posted by LFRobotics View Post
Code:
button.whenPressed or button.when released
does not work with boolean values
whenPressed() and whenReleased() are methods of the Button class, not of booleans. As a result, if you want to perform a command when a button is being pressed or released you need to call the method on a Button object, not a boolean.

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;

import edu.wpi.first.XBoxBot2014.subsystems.XBoxController;

public class OI {
    public XBoxController xcon2 = new XBoxController(RobotMap.conPort);
    private Button button = new JoystickButton(xcon2, 1); //Button A = 1

    public OI() {
         button.whenPressed(doThing());
   }    
}
As for driveTele(), you don't need to take a leftStick and a rightStick as parameters if you don't use them in the method. Instead, drive.tankDrive() takes values from the xcon2 object in oi:
Code:
public void driveTele(Joystick leftStick, Joystick rightStick){
    drive.tankDrive(oi.xcon2.getLeftJoyY(), oi.xcon2.getRightJoyY());
}
I don't have much expertise with command-based programming (sorry), but here's what I'd do to fix that problem with your current setup:
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){
    drive.tankDrive(leftValue, rightValue);
}
Your DriveTele() command will then look something like this.

Hope it works!
__________________
2012 - 2015 • Team 2601


Last edited by NWChen : 23-06-2014 at 02:33.
Reply With Quote