Quote:
Originally Posted by LFRobotics
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!