*/
public class Constants {
- public static class OI {
- public final static int LEFT_STICK_PORT = 0;
- public final static int RIGHT_STICK_PORT = 0;
- }
+ public static class OI {
+ public final static int LEFT_STICK_PORT = 0;
+ public final static int RIGHT_STICK_PORT = 0;
+ }
- public static class DriveTrain {
- // MOTOR CONTROLLERS
- public static final int FRONT_LEFT = 0;
- public static final int FRONT_RIGHT = 0;
- public static final int REAR_LEFT = 0;
- public static final int REAR_RIGHT = 0;
+ public static class DriveTrain {
+ // MOTOR CONTROLLERS
+ public static final int FRONT_LEFT = 0;
+ public static final int FRONT_RIGHT = 0;
+ public static final int REAR_LEFT = 0;
+ public static final int REAR_RIGHT = 0;
- // ENCODERS
- public static final int ENCODER_LEFT_A = 0;
- public static final int ENCODER_LEFT_B = 0;
- public static final int ENCODER_RIGHT_A = 0;
- public static final int ENCODER_RIGHT_B = 0;
+ // ENCODERS
+ public static final int ENCODER_LEFT_A = 0;
+ public static final int ENCODER_LEFT_B = 0;
+ public static final int ENCODER_RIGHT_A = 0;
+ public static final int ENCODER_RIGHT_B = 0;
- public static final int INCHES_PER_PULSE = 0;
- }
+ public static final int INCHES_PER_PULSE = 0;
+ }
- public static enum Direction {
- LEFT, RIGHT, DOWN, UP, FORWARD, BACKWARD;
- }
+ public static enum Direction {
+ LEFT, RIGHT, DOWN, UP, FORWARD, BACKWARD;
+ }
}
*/
public class DriveDistance extends Command {
- public DriveDistance() {
- requires(Robot.getDriveTrain());
- }
-
- // Called just before this Command runs the first time
- @Override
- protected void initialize() {
- }
-
- // Called repeatedly when this Command is scheduled to run
- @Override
- protected void execute() {
- }
-
- // Make this return true when this Command no longer needs to run execute()
- @Override
- protected boolean isFinished() {
- return false;
- }
-
- // Called once after isFinished returns true
- @Override
- protected void end() {
- }
-
- // Called when another command which requires one or more of the same
- // subsystems is scheduled to run
- @Override
- protected void interrupted() {
- }
+ public DriveDistance() {
+ requires(Robot.getDriveTrain());
+ }
+
+ // Called just before this Command runs the first time
+ @Override
+ protected void initialize() {
+ }
+
+ // Called repeatedly when this Command is scheduled to run
+ @Override
+ protected void execute() {
+ }
+
+ // Make this return true when this Command no longer needs to run execute()
+ @Override
+ protected boolean isFinished() {
+ return false;
+ }
+
+ // Called once after isFinished returns true
+ @Override
+ protected void end() {
+ }
+
+ // Called when another command which requires one or more of the same
+ // subsystems is scheduled to run
+ @Override
+ protected void interrupted() {
+ }
}
*/
public class JoystickDrive extends Command {
- public JoystickDrive() {
- requires(Robot.getDriveTrain());
- }
-
- @Override
- protected void initialize() {
- }
-
- @Override
- protected void execute() {
- double left = OI.leftJoystick.getY();
- double right = OI.rightJoystick.getY();
-
- Robot.getDriveTrain().joystickDrive(left, right);
- }
-
- @Override
- protected boolean isFinished() {
- return false;
- }
-
- @Override
- protected void end() {
- Robot.getDriveTrain().stop();
- }
-
- @Override
- protected void interrupted() {
- }
+ public JoystickDrive() {
+ requires(Robot.getDriveTrain());
+ }
+
+ @Override
+ protected void initialize() {
+ }
+
+ @Override
+ protected void execute() {
+ final double left = OI.leftJoystick.getY();
+ final double right = OI.rightJoystick.getY();
+
+ Robot.getDriveTrain().joystickDrive(left, right);
+ }
+
+ @Override
+ protected boolean isFinished() {
+ return false;
+ }
+
+ @Override
+ protected void end() {
+ Robot.getDriveTrain().stop();
+ }
+
+ @Override
+ protected void interrupted() {
+ }
}
*
*/
public class TimeDrive extends Command {
- Timer timer;
- double motorVal, time;
-
- public TimeDrive(double time, double motorVal) {
- requires(Robot.getDriveTrain());
-
- timer = new Timer();
- this.time = time;
- this.motorVal = motorVal;
- }
-
- @Override
- protected void initialize() {
- timer.start();
- Robot.getDriveTrain().setMotorValues(motorVal, motorVal);
- }
-
- @Override
- protected void execute() {
- }
-
- @Override
- protected boolean isFinished() {
- return timer.get() >= time;
- }
-
- @Override
- protected void end() {
- Robot.getDriveTrain().stop();
- }
-
- @Override
- protected void interrupted() {
- end();
- }
+ Timer timer;
+ double motorVal, time;
+
+ public TimeDrive(final double time, final double motorVal) {
+ requires(Robot.getDriveTrain());
+
+ timer = new Timer();
+ this.time = time;
+ this.motorVal = motorVal;
+ }
+
+ @Override
+ protected void initialize() {
+ timer.start();
+ Robot.getDriveTrain().setMotorValues(motorVal, motorVal);
+ }
+
+ @Override
+ protected void execute() {
+ }
+
+ @Override
+ protected boolean isFinished() {
+ return timer.get() >= time;
+ }
+
+ @Override
+ protected void end() {
+ Robot.getDriveTrain().stop();
+ }
+
+ @Override
+ protected void interrupted() {
+ end();
+ }
}
*/
public class TurnForAngle extends Command {
- public TurnForAngle() {
- requires(Robot.getDriveTrain());
- }
-
- // Called just before this Command runs the first time
- @Override
- protected void initialize() {
- }
-
- // Called repeatedly when this Command is scheduled to run
- @Override
- protected void execute() {
- }
-
- // Make this return true when this Command no longer needs to run execute()
- @Override
- protected boolean isFinished() {
- return false;
- }
-
- // Called once after isFinished returns true
- @Override
- protected void end() {
- }
-
- // Called when another command which requires one or more of the same
- // subsystems is scheduled to run
- @Override
- protected void interrupted() {
- }
+ public TurnForAngle() {
+ requires(Robot.getDriveTrain());
+ }
+
+ // Called just before this Command runs the first time
+ @Override
+ protected void initialize() {
+ }
+
+ // Called repeatedly when this Command is scheduled to run
+ @Override
+ protected void execute() {
+ }
+
+ // Make this return true when this Command no longer needs to run execute()
+ @Override
+ protected boolean isFinished() {
+ return false;
+ }
+
+ // Called once after isFinished returns true
+ @Override
+ protected void end() {
+ }
+
+ // Called when another command which requires one or more of the same
+ // subsystems is scheduled to run
+ @Override
+ protected void interrupted() {
+ }
}
import org.usfirst.frc.team3501.robot.Constants;
-import com.ctre.CANTalon;
-
+import edu.wpi.first.wpilibj.CANTalon;
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.command.Subsystem;
public class DriveTrain extends Subsystem {
- private static DriveTrain driveTrain;
- private CANTalon frontLeft, frontRight, rearLeft, rearRight;
- private RobotDrive robotDrive;
- private Encoder leftEncoder, rightEncoder;
-
- private DriveTrain() {
- // MOTOR CONTROLLERS
- frontLeft = new CANTalon(Constants.DriveTrain.FRONT_LEFT);
- frontRight = new CANTalon(Constants.DriveTrain.FRONT_RIGHT);
- rearLeft = new CANTalon(Constants.DriveTrain.REAR_LEFT);
- rearRight = new CANTalon(Constants.DriveTrain.REAR_RIGHT);
-
- // ENCODERS
- leftEncoder = new Encoder(Constants.DriveTrain.ENCODER_LEFT_A,
- Constants.DriveTrain.ENCODER_LEFT_B);
- rightEncoder = new Encoder(Constants.DriveTrain.ENCODER_RIGHT_A,
- Constants.DriveTrain.ENCODER_RIGHT_B);
-
- leftEncoder.setDistancePerPulse(Constants.DriveTrain.INCHES_PER_PULSE);
- rightEncoder.setDistancePerPulse(Constants.DriveTrain.INCHES_PER_PULSE);
-
- // ROBOT DRIVE
- robotDrive = new RobotDrive(frontLeft, rearLeft, frontRight, rearRight);
- }
-
- public static DriveTrain getDriveTrain() {
- if (driveTrain == null)
- driveTrain = new DriveTrain();
- return driveTrain;
- }
-
- // DRIVE METHODS
- public void setMotorValues(double left, double right) {
- robotDrive.tankDrive(left, right);
- }
-
- public void joystickDrive(double left, double right) {
- robotDrive.tankDrive(left, right);
- }
-
- public void stop() {
- setMotorValues(0, 0);
- }
-
- public double getFrontLeftMotorVal() {
- return frontLeft.get();
- }
-
- public double getFrontRightMotorVal() {
- return frontRight.get();
- }
-
- public double getRearLeftMotorVal() {
- return frontLeft.get();
- }
-
- public double getRearRightMotorVal() {
- return frontLeft.get();
- }
-
- public CANTalon getFrontLeft() {
- return frontLeft;
- }
-
- public CANTalon getFrontRight() {
- return frontRight;
- }
-
- public CANTalon getRearLeft() {
- return rearLeft;
- }
-
- public CANTalon getRearRight() {
- return rearRight;
- }
-
- // ENCODER METHODS
-
- public double getLeftEncoder() {
- return leftEncoder.getDistance();
- }
-
- public double getRightEncoder() {
- return rightEncoder.getDistance();
- }
-
- public double getAvgEncoderDistance() {
- return (leftEncoder.getDistance() + rightEncoder.getDistance()) / 2;
- }
-
- public void resetEncoders() {
- leftEncoder.reset();
- rightEncoder.reset();
- }
-
- public double getLeftSpeed() {
- return leftEncoder.getRate();
- }
-
- public double getRightSpeed() {
- return rightEncoder.getRate();
- }
-
- public double getSpeed() {
- return (getLeftSpeed() + getRightSpeed()) / 2.0;
- }
-
- @Override
- protected void initDefaultCommand() {
- }
+ private static DriveTrain driveTrain;
+ private final CANTalon frontLeft, frontRight, rearLeft, rearRight;
+ private final RobotDrive robotDrive;
+ private final Encoder leftEncoder, rightEncoder;
+
+ private DriveTrain() {
+ // MOTOR CONTROLLERS
+ frontLeft = new CANTalon(Constants.DriveTrain.FRONT_LEFT);
+ frontRight = new CANTalon(Constants.DriveTrain.FRONT_RIGHT);
+ rearLeft = new CANTalon(Constants.DriveTrain.REAR_LEFT);
+ rearRight = new CANTalon(Constants.DriveTrain.REAR_RIGHT);
+
+ // ENCODERS
+ leftEncoder = new Encoder(Constants.DriveTrain.ENCODER_LEFT_A,
+ Constants.DriveTrain.ENCODER_LEFT_B);
+ rightEncoder = new Encoder(Constants.DriveTrain.ENCODER_RIGHT_A,
+ Constants.DriveTrain.ENCODER_RIGHT_B);
+
+ leftEncoder.setDistancePerPulse(Constants.DriveTrain.INCHES_PER_PULSE);
+ rightEncoder.setDistancePerPulse(Constants.DriveTrain.INCHES_PER_PULSE);
+
+ // ROBOT DRIVE
+ robotDrive = new RobotDrive(frontLeft, rearLeft, frontRight, rearRight);
+ }
+
+ public static DriveTrain getDriveTrain() {
+ if (driveTrain == null) {
+ driveTrain = new DriveTrain();
+ }
+ return driveTrain;
+ }
+
+ // DRIVE METHODS
+ public void setMotorValues(final double left, final double right) {
+ robotDrive.tankDrive(left, right);
+ }
+
+ public void joystickDrive(final double left, final double right) {
+ robotDrive.tankDrive(left, right);
+ }
+
+ public void stop() {
+ setMotorValues(0, 0);
+ }
+
+ public double getFrontLeftMotorVal() {
+ return frontLeft.get();
+ }
+
+ public double getFrontRightMotorVal() {
+ return frontRight.get();
+ }
+
+ public double getRearLeftMotorVal() {
+ return frontLeft.get();
+ }
+
+ public double getRearRightMotorVal() {
+ return frontLeft.get();
+ }
+
+ public CANTalon getFrontLeft() {
+ return frontLeft;
+ }
+
+ public CANTalon getFrontRight() {
+ return frontRight;
+ }
+
+ public CANTalon getRearLeft() {
+ return rearLeft;
+ }
+
+ public CANTalon getRearRight() {
+ return rearRight;
+ }
+
+ // ENCODER METHODS
+
+ public double getLeftEncoder() {
+ return leftEncoder.getDistance();
+ }
+
+ public double getRightEncoder() {
+ return rightEncoder.getDistance();
+ }
+
+ public double getAvgEncoderDistance() {
+ return (leftEncoder.getDistance() + rightEncoder.getDistance()) / 2;
+ }
+
+ public void resetEncoders() {
+ leftEncoder.reset();
+ rightEncoder.reset();
+ }
+
+ public double getLeftSpeed() {
+ return leftEncoder.getRate();
+ }
+
+ public double getRightSpeed() {
+ return rightEncoder.getRate();
+ }
+
+ public double getSpeed() {
+ return (getLeftSpeed() + getRightSpeed()) / 2.0;
+ }
+
+ @Override
+ protected void initDefaultCommand() {
+ }
}