// RobotBuilder Version: 0.0.2
//
// This file was generated by RobotBuilder. It contains sections of
// code that are automatically generated and assigned by robotbuilder.
// These sections will be updated in the future when you export to
// Java from RobotBuilder. Do not put any code or make any change in
// the blocks indicating autogenerated code or it will be lost on an
// update. Deleting the comments indicating the section will prevent
// it from being updated in th future.
package org.usfirst.frc330.Beachbot2013Java.commands;
import edu.wpi.first.wpilibj.command.AutoSpreadsheetCommand;
import edu.wpi.first.wpilibj.command.Command;
import org.usfirst.frc330.Beachbot2013Java.Robot;
/**
 *
 */
public class  TurnGyroRel extends Command implements AutoSpreadsheetCommand {
    double angle;
    boolean stopAtEnd = false;
    
    public TurnGyroRel(double angle) {
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);
        this(angle, 0, 15, false);
    }
    
    public TurnGyroRel(double angle, double tolerance)
    {
        this(angle, tolerance, 15, false);
    }
    
    public TurnGyroRel(double angle, double tolerance, double timeout, boolean stopAtEnd) {
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);
	
        // BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES
        requires(Robot.chassis);
    // END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES
        this.angle = angle;
        Robot.chassis.gyroPIDLow.setAbsoluteTolerance(tolerance);
        setTimeout(timeout);
        this.stopAtEnd = stopAtEnd;
    }
    // Called just before this Command runs the first time
    protected void initialize() {
        Robot.chassis.gyroPIDLow.setSetpoint(angle+Robot.chassis.getAngle());
        Robot.chassis.gyroPIDLow.enable();
        Robot.chassis.leftDrivePIDLow.disable();
        Robot.chassis.rightDrivePIDLow.disable();
    }
    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
        Robot.chassis.pidDrive();
    }
    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        if (Robot.chassis.gyroPIDLow.onTarget() || isTimedOut())
        {
            return true;            
        }
        else
        {
            return false;
        }
    }
    // Called once after isFinished returns true
    protected void end() {
        if (stopAtEnd)
        {
            Robot.chassis.gyroPIDLow.disable();
            Robot.chassis.tankDrive(0, 0);
        }
    }
    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {
        stopAtEnd = true;
        end();
    }
    public void setParam1(double angle) {
        this.angle = angle;
    }
    public void setParam2(double tolerance) {
        Robot.chassis.gyroPIDLow.setAbsoluteTolerance(tolerance);
    }
    public void setParam3(double param3) {
    }
    public void setStopAtEnd(boolean stopAtEnd) {
        this.stopAtEnd = stopAtEnd;
    }
    public Command copy() {
        return new TurnGyroRel(0);
    }
}

// RobotBuilder Version: 0.0.2
//
// This file was generated by RobotBuilder. It contains sections of
// code that are automatically generated and assigned by robotbuilder.
// These sections will be updated in the future when you export to
// Java from RobotBuilder. Do not put any code or make any change in
// the blocks indicating autogenerated code or it will be lost on an
// update. Deleting the comments indicating the section will prevent
// it from being updated in th future.
package org.usfirst.frc330.Beachbot2013Java.commands;
import edu.wpi.first.wpilibj.command.AutoSpreadsheetCommand;
import edu.wpi.first.wpilibj.command.Command;
import org.usfirst.frc330.Beachbot2013Java.Robot;
/**
 *
 */
public class  TurnGyroRel extends TurnGyroAbs implements AutoSpreadsheetCommand {

    
    public TurnGyroRel(double angle) {
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);
        this(angle, 0, 15, false);
    }
    
    public TurnGyroRel(double angle, double tolerance)
    {
        this(angle, tolerance, 15, false);
    }
    
    public TurnGyroRel(double angle, double tolerance, double timeout, boolean stopAtEnd) {
        super(angle,tolerance,timeout,stopAtEnd);
    }
    // Called just before this Command runs the first time
    protected void initialize() {
        super.initialize();
        if (!Robot.chassis.getShiftState())
        {
            Robot.chassis.gyroPIDLow.setSetpoint(angle+Robot.chassis.getAngle());
            Robot.chassis.gyroPIDLow.enable();
        }
        else
        {
            Robot.chassis.gyroPIDHigh.setSetpoint(angle+Robot.chassis.getAngle());
            Robot.chassis.gyroPIDHigh.enable();
        }
    }
    public Command copy() {
        return new TurnGyroRel(0);
    }
}

make extend TurnGyroAbs