/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.stuy.subsystems;

import edu.stuy.RobotMap;
import edu.stuy.commands.AcquirerStop;
import edu.stuy.util.StallDetectingVictor;
import edu.wpi.first.wpilibj.Relay;
import edu.wpi.first.wpilibj.command.Subsystem;

/**
 *
 * @author Kevin Wang
 */
public class Acquirer extends Subsystem {
    public StallDetectingVictor roller;
    private boolean isAcquiring;
    private Relay light;

    // WARNING: The acquirer runs on a FisherPrice motor, meaning you CANNOT use a floating point value between 0 and 1!
    public static final int FWD = 1;
    public static final int OFF = 0;
    public static final int REV = -1;

    
    // Put methods for controlling this subsystem
    // here. Call these from Commands.
    
    public Acquirer() {
        roller = new StallDetectingVictor(RobotMap.ACQUIRER_ROLLER, RobotMap.CURRENT_THING_CHANNEL);
        isAcquiring = false;
        light = new Relay(RobotMap.STALL_LIGHT);
        light.setDirection(Relay.Direction.kForward);
    }

    public void initDefaultCommand() {
        // Set the default command for a subsystem here.
        setDefaultCommand(new AcquirerStop());
    }
    
    /**
     * Rolls the acquirer forwards, backwards, or stops.
     * 
     * WARNING: The acquirer runs on a FisherPrice motor, meaning you 
     * CANNOT use a floating point value between 0 and 1!
     * 
     * @param speed Either 1, 0, or -1.
     */
    private void roll(double speed) {
        roller.set(speed);
        checkWhenStalled();
    }

    public void stop() {
        roll(OFF);// WARNING: The acquirer runs on a FisherPrice motor, meaning you CANNOT use a floating point value between 0 and 1!
        isAcquiring = false;
        checkWhenStalled();
    }

    public void acquire() {
        isAcquiring = true;
        roll(FWD); // WARNING: The acquirer runs on a FisherPrice motor, meaning you CANNOT use a floating point value between 0 and 1!
        checkWhenStalled();
    }

    public void acquireReverse() {
        isAcquiring = false;
        roll(REV);// WARNING: The acquirer runs on a FisherPrice motor, meaning you CANNOT use a floating point value between 0 and 1!
        checkWhenStalled();
    }

    public double getRollerSpeed() {
        return roller.get();
    }

    public boolean isAcquiring() {
        return isAcquiring;
    }

    /**
     * will check whether the StallDetectingVitor believes it's in danger of failing
     * and act accordingly
     */
    public void checkWhenStalled(){
        if (roller.checkCurrentFail()){
            light.set(Relay.Value.kOn);
        }
        else{
            light.set(Relay.Value.kOff);
        }
    }
}

@@ -1792,42 +1792,14 @@
 se;%0A
-        checkWhenStalled();%0A
     %7D%0A
+
 %0A   
@@ -1991,36 +1991,8 @@
  1!%0A
-        checkWhenStalled();%0A
     
@@ -2050,32 +2050,32 @@
 uiring = false;%0A
+
         roll(REV
@@ -2197,36 +2197,8 @@
  1!%0A
-        checkWhenStalled();%0A
     

Remove duplicate stall checks in Acquirer.