Arm Issue

I have tried almost everything to fix this. I need some help. :confused:

Below is my OI code, and below that is my ArmClose code. My ArmOpen code is almost exactly the same as that, but the ArmClose code does not work.


package org.usfirst.frc3680.RecycleRush;

import org.usfirst.frc3680.RecycleRush.commands.*;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj.*;
import edu.wpi.first.wpilibj.buttons.*;


/**
 * This class is the glue that binds the controls on the physical operator
 * interface to the commands and command groups that allow control of the robot.
 */
public class OI {
    //// CREATING BUTTONS
    // One type of button is a joystick button which is any button on a joystick.
    // You create one by telling it which joystick it's on and which button
    // number it is.
    // Joystick stick = new Joystick(port);
    // Button button = new JoystickButton(stick, buttonNumber);
    
    // There are a few additional built in buttons you can use. Additionally,
    // by subclassing Button you can create custom triggers and bind those to
    // commands the same as any other Button.
    
    //// TRIGGERING COMMANDS WITH BUTTONS
    // Once you have a button, it's trivial to bind it to a button in one of
    // three ways:
    
    // Start the command when the button is pressed and let it run the command
    // until it is finished as determined by it's isFinished method.
    // button.whenPressed(new ExampleCommand());
    
    // Run the command while the button is being held down and interrupt it once
    // the button is released.
    // button.whileHeld(new ExampleCommand());
    
    // Start the command when the button is released  and let it run the command
    // until it is finished as determined by it's isFinished method.
    // button.whenReleased(new ExampleCommand());

    
    // BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS
    public JoystickButton button10;
    public JoystickButton button11;
    public JoystickButton button6;
    public JoystickButton button7;
    public Joystick joystick1;
    public Joystick joystick2;

    // END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS

    public OI() {
        // BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS

        joystick2 = new Joystick(1);
        
        joystick1 = new Joystick(0);
        
        button6 = new JoystickButton(joystick1, 6);
        button6.whenPressed(new ArmOpen());
        button7 = new JoystickButton(joystick1, 7);
        button7.whenPressed(new ArmClose());
        button11 = new JoystickButton(joystick1, 11);
        button11.whenPressed(new ArmUp());
        button10 = new JoystickButton(joystick1, 10);
        button10.whenPressed(new ArmDown());

	    
        // SmartDashboard Buttons
        SmartDashboard.putData("ArmUp", new ArmUp());

        SmartDashboard.putData("ArmDown", new ArmDown());

        SmartDashboard.putData("Autonomous Command", new AutonomousCommand());

        SmartDashboard.putData("ArmOpen", new ArmOpen());

        SmartDashboard.putData("ArmClose", new ArmClose());
        

    // END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS
    }
    
    // BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=FUNCTIONS
    public Joystick getJoystick1() {
        return joystick1;
    }

    public Joystick getJoystick2() {
        return joystick2;
    }


    // END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=FUNCTIONS
}


package org.usfirst.frc3680.RecycleRush.commands;

import edu.wpi.first.wpilibj.command.Command;

import org.usfirst.frc3680.RecycleRush.Robot;
import org.usfirst.frc3680.RecycleRush.RobotMap;

import edu.wpi.first.wpilibj.*;


/**
 *
 */
public class  ArmClose extends Command {

    public ArmClose() {
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);

        // BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES
        requires(Robot.armOpenClose);

    // END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES
    }

    // Called just before this Command runs the first time
    protected void initialize() {
        Robot.armOpenClose.initializeCounter();
    	
    	Robot.armOpenClose.armClose();
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
    	
    }

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        
        return Robot.armOpenClose.isSwitch1Set();
    }

    // Called once after isFinished returns true
    protected void end() {
    	Robot.armOpenClose.armStop();
    }

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

Help?

The first thing I would try is putting print statements in the initialize() method (or a breakpoint and debug it) to make sure it is being called when you think it is.

If that works, then check to make sure Robot.armOpenClose.armClose() is actually doing what you think it is.

I figured out that it was a wiring issue. Now we try it and it does what we want, except for one thing. When I hold down the limit switch, it allows the armClose() function to run. I believe it is because it is recognizing the limit switch as normally closed when it is held down, because when I let go it stops. Below is my revised code, I have tried everything I can think of. Thanks for the help!

ArmClose.java


package org.usfirst.frc3680.RecycleRush.commands;

import edu.wpi.first.wpilibj.command.Command;

import org.usfirst.frc3680.RecycleRush.Robot;
import org.usfirst.frc3680.RecycleRush.RobotMap;
import edu.wpi.first.wpilibj.*;


/**
 *
 */
public class  ArmClose extends Command {

    public ArmClose() {
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);

        // BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES
        requires(Robot.armOpenClose);

    // END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES
    }

    // Called just before this Command runs the first time
    protected void initialize() {
       
        //
    	Robot.armOpenClose.counter2init();
    	if(Robot.armOpenClose.isSwitch2Set() == true){
    	System.out.println("limit pressed");
    	
    	}else{Robot.armOpenClose.counter2init();
    	Robot.armOpenClose.armClose();
    	}
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
    	System.out.println("ArmClose Ran");
    }

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        
        return Robot.armOpenClose.isSwitch2Set();
    }

    // Called once after isFinished returns true
    protected void end() {
    	Robot.armOpenClose.armStop();
    	Robot.armOpenClose.counter2init();
    }

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

ArmOpenClose.java


package org.usfirst.frc3680.RecycleRush.subsystems;

import org.usfirst.frc3680.RecycleRush.Robot;
import org.usfirst.frc3680.RecycleRush.RobotMap;
import org.usfirst.frc3680.RecycleRush.commands.*;

import edu.wpi.first.wpilibj.*;
import edu.wpi.first.wpilibj.command.Subsystem;


/**
 *
 */
public class ArmOpenClose extends Subsystem {
    // BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS
    SpeedController smallerMotor = RobotMap.armOpenCloseSmallerMotor;
    DigitalInput limitSwitch1 = new DigitalInput(1);
    DigitalInput limitSwitch2 = new DigitalInput(2);
    Counter counter = new Counter(limitSwitch1);
    Counter counter2 = new Counter(limitSwitch2);
    // END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS
    
    
    // Put methods for controlling this subsystem
    // here. Call these from Commands.
    
    
    public boolean isSwitch1Set() {
    	return counter.get() > 0;
    }
    public boolean isSwitch2Set() {
    	return counter2.get() > 0;
    } 
    public void initializeCounter() {
    	counter.reset();
    	
    }
    public void counter2init() {
    	counter2.reset();
    }
    
    public void armOpen() {
    	RobotMap.armOpenCloseSmallerMotor.set(-0.1);
    }
    
    public void armClose() {
    	RobotMap.armOpenCloseSmallerMotor.set(0.2);
    	
    }
    
    public void armStop() {
    	RobotMap.armOpenCloseSmallerMotor.set(0);
    }
    public void initDefaultCommand() {
        // BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DEFAULT_COMMAND

    // END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DEFAULT_COMMAND
	
        // Set the default command for a subsystem here.
        //setDefaultCommand(new MySpecialCommand());
    }
}

Thanks!

Figured it out! Thanks for the help! I took a look at Team 1160’s method of limit-switching. It is a whole lot simpler.