Thread: Arm Issue
View Single Post
  #3   Spotlight this post!  
Unread 23-01-2015, 15:34
michaelyork michaelyork is offline
Registered User
FRC #3680 (Elemental Dragons)
Team Role: Programmer
 
Join Date: Mar 2014
Rookie Year: 2014
Location: Statesville, NC, United States
Posts: 18
michaelyork is an unknown quantity at this point
Re: Arm Issue

Quote:
Originally Posted by lopsided98 View Post
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
Code:
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
Code:
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!
Reply With Quote