Go to Post Doctor the drill, or doctor your hand. Easy choice. Let's all make the right one. - Molten [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 01-20-2015, 06:29 PM
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
Question Arm Issue

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

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.

Code:
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
}
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.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?

Last edited by michaelyork : 01-20-2015 at 06:57 PM. Reason: mistake
Reply With Quote
  #2   Spotlight this post!  
Unread 01-20-2015, 06:59 PM
Ben Wolsieffer Ben Wolsieffer is offline
Dartmouth 2020
AKA: lopsided98
FRC #2084 (Robots by the C)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Manchester, MA (Hanover, NH)
Posts: 520
Ben Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud of
Re: Arm Issue

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.
__________________



2016 North Shore District - Semifinalists and Excellence in Engineering Award
2015 Northeastern University District - Semifinalists and Creativity Award
2014 Granite State District - Semifinalists and Innovation in Control Award
2012 Boston Regional - Finalists
Reply With Quote
  #3   Spotlight this post!  
Unread 01-23-2015, 03:34 PM
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
  #4   Spotlight this post!  
Unread 01-23-2015, 08:17 PM
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

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.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 08:56 AM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi