Quote:
Originally Posted by Hawk_Prime
How would I go about just adding something where when you push a button on an xbox controller, a different motor goes? Thanks for the help! 
|
Ultimately I think you'll want to get to
Code:
...
SpeedController elevatorMotor;
private static final int LIFT_BUTTON=1; //or whatever button raises
private static final int LOWER_BUTTON=4; //or whatever button lowers
...
public Robot() {
...
elevatorMotor=new Talon(elevator);
...
}
public void operatorControl() {
robotDrive.setSafetyEnabled(true);
while (isOperatorControl() && isEnabled()) {
// Use the joystick X axis for lateral movement, Y axis for forward movement, and Z axis for rotation.
// This sample does not use field-oriented drive, so the gyro input is set to zero.
robotDrive.mecanumDrive_Cartesian(stick.getY(), stick.getX(), stick.getZ(), 0);
if(stick.getRawButton(LIFT_BUTTON)) {
elevatorMotor.set(0.5);
} else if(stick.getRawButton(LOWER_BUTTON)) {
elevatorMotor.set(-0.5);
} else {
elevatorMotor.set(0);
}
Timer.delay(0.010); // wait 5ms to avoid hogging CPU cycles
}
}
but to get there you need some variable representing a SpeedController such as I've shown as elevatorMotor. I showed the code if you use a Talon. If you use something else as Matt was asking about, that line would be different. If you need to call more than just the basic SpeedController interface on you Talon/Jaguar/TalonSRX/etc, you can make the line be
Code:
Talon elevatorMotor=new Talon(elevator);
Then if there is a Talon specific function that is not on the SpeedController interface, you can still call that too. Just trying to keep it simple for you.
I've not used xbox class so I don't know if getRawButton is best way to get buttons or not, or if mappings exist avoiding need for LIFT_BUTTON/LOWER_BUTTON, but using local names with explicit names for lift and lower help keep your code more understandable.