Log in

View Full Version : Tank Drive with one xbox controller


CyberTeam5713
16-02-2016, 15:19
This is Tank Drive with one controller using left analog to control left drive train and right analog to control right drive.


public class Robot extends IterativeRobot {

RobotDrive Leftdrive;
RobotDrive Rightdrive;
Joystick mXboxController;
Joystick controlStick;
Talon frontLeft,frontRight, rearLeft, rearRight;

public void robotInit() { // this code will be ran each time we power on the robot

mXboxController = new Joystick(1); // depends on the usb connected to computer
controlStick = new Joystick(0);
frontLeft = new Talon(2);
frontLeft.setInverted(true);
frontRight = new Talon(1);

rearLeft = new Talon(3);
rearRight = new Talon(0);
rearRight.setInverted(true);
Leftdrive = new RobotDrive(frontLeft, rearLeft);
Rightdrive = new RobotDrive(frontRight, rearRight);
}


public void autonomousInit() { // triggers when we enter autonomous


}


public void autonomousPeriodic() { // this code runs periodically in autonomous
while (isAutonomous() && isEnabled()) {
Leftdrive.drive(0.5, 0.0);
Rightdrive.drive(0.5, 0.0);
Timer.delay(0.5);
Leftdrive.drive(0.0, 0.0);
Rightdrive.drive(0.0, 0.0);

}
}




public void teleopInit(){ // This triggers every time we enter telop mode.

mXboxController = new Joystick(0); // the number within the parathesis depends on the controllers usb order always check
controlStick = new Joystick(1);

}




public void teleopPeriodic() {
while (isOperatorControl() && isEnabled()) {
Leftdrive.setSafetyEnabled(true);
Rightdrive.setSafetyEnabled(true);
Leftdrive.tankDrive(mXboxController.getRawAxis(1), mXboxController.getRawAxis(1));
Rightdrive.tankDrive(mXboxController.getRawAxis(5) , mXboxController.getRawAxis(5));
Timer.delay(0.01); } } // this will constantly update motors and speed controllers periodically


At the speedcontroller setInverted you do not have to invert the controller thats just how ours was set up