package edu.stuy.commands;

import static edu.stuy.RobotMap.*;
import edu.stuy.Robot;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.command.Command;

/**
 *
 */
public class DrivetrainTankDriveCommand extends Command {

    private double startTime;

    public DrivetrainTankDriveCommand() {
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);
        requires(Robot.drivetrain);
    }

    // Called just before this Command runs the first time
    protected void initialize() {
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
        double left = Robot.oi.driverPad.getLeftY();
        double right = Robot.oi.driverPad.getRightY();

        if (Math.abs(left) < .05 && Math.abs(right) < .05) {
            startTime = Timer.getFPGATimestamp();
        }

        if (Robot.oi.driverPad.getRawLeftTrigger() || Robot.oi.driverPad.getRawLeftBumper()) {
            Robot.drivetrain.setSpeedUp(false);
        }
        if (Robot.oi.driverPad.getRawRightTrigger() || Robot.oi.driverPad.getRawRightBumper()) {
            Robot.drivetrain.setSpeedUp(true);
        }

        if (Robot.drivetrain.isSpeedUp()) {
            if ((left < 0 && right > 0) || (left > 0 && right < 0)) { // Rotation does not use ramping
                Robot.drivetrain.tankDrive(-left, -right);
            } else {
                Robot.drivetrain.tankDrive(getRampSpeed(-left), getRampSpeed(-right));
            }
        } else {
            if ((left < 0 && right > 0) || (left > 0 && right < 0)) { // Rotation does not use ramping
                Robot.drivetrain.tankDrive(-left, -right);
            } else {
                Robot.drivetrain.tankDrive(getRampSpeed(-left) * DRIVETRAIN_SLOWNESS_FACTOR, getRampSpeed(-right) * DRIVETRAIN_SLOWNESS_FACTOR);
            }
        }
    }

    private double getRampSpeed(double m) {
        double t = Timer.getFPGATimestamp() - startTime;
        double speed;
        if (t < 0.5) {
            speed = 2 * t * t;
        } else if (t < 1) {
            speed = -2 * t * t + 4 * t - 1;
        } else {
            speed = 1;
        }
        return /* speed * */ m;
    }

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        // This is Drivetrain's default command.
        return false;
    }

    // Called once after isFinished returns true
    protected void end() {
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {
    }
}

@@ -753,131 +753,8 @@
 ();%0A
-%0A        if (Math.abs(left) %3C .05 && Math.abs(right) %3C .05) %7B%0A            startTime = Timer.getFPGATimestamp();%0A        %7D%0A%0A
     
@@ -1105,115 +1105,8 @@
 ) %7B%0A
-            if ((left %3C 0 && right %3E 0) %7C%7C (left %3E 0 && right %3C 0)) %7B // Rotation does not use ramping%0A    
     
@@ -1156,36 +1156,32 @@
 right);%0A        
-    
 %7D else %7B%0A       
@@ -1177,36 +1177,32 @@
 e %7B%0A            
-  
-  
 Robot.drivetrain
@@ -1216,328 +1216,13 @@
 ive(
-getRampSpeed(-left), getRampSpeed(-right));%0A            %7D%0A        %7D else %7B%0A            if ((left %3C 0 && right %3E 0) %7C%7C (left %3E 0 && right %3C 0)) %7B // Rotation does not use ramping%0A                Robot.drivetrain.tankDrive(-left, -right);%0A            %7D else %7B%0A                Robot.drivetrain.tankDrive(getRampSpeed(-left)
+-left
  * D
@@ -1252,28 +1252,14 @@
 OR, 
-getRampSpeed(
 -right
-)
  * D
@@ -1286,20 +1286,16 @@
 ACTOR);%0A
-    
         
@@ -1300,356 +1300,8 @@
   %7D%0A
-        %7D%0A    %7D%0A%0A    private double getRampSpeed(double m) %7B%0A        double t = Timer.getFPGATimestamp() - startTime;%0A        double speed;%0A        if (t %3C 0.5) %7B%0A            speed = 2 * t * t;%0A        %7D else if (t %3C 1) %7B%0A            speed = -2 * t * t + 4 * t - 1;%0A        %7D else %7B%0A            speed = 1;%0A        %7D%0A        return /* speed * */ m;%0A
     

Remove bad ramping from canner branch for book sale