View Single Post
  #7   Spotlight this post!  
Unread 13-02-2015, 12:04
cstelter cstelter is offline
Programming Mentor
AKA: Craig Stelter
FRC #3018 (Nordic Storm)
Team Role: Mentor
 
Join Date: Apr 2012
Rookie Year: 2012
Location: Mankato, MN
Posts: 77
cstelter will become famous soon enough
Re: Using Hall Effect Sensors

Quote:
Originally Posted by fireXtract View Post
Now i'm able to get the elevator to stop in response to the hall effect sensor, but once it use it to go up i cant press it to go up again, and if i go down i can only go down once. Pressing the button multiple times to add to count does nothing. What am i missing here?
Since your command is ending when done==true, how are you getting another command to run? I think if you tie it to a button with whenPressed() or something like that, it reuses the same object each time. So you have to reinitialize everything in initialize.

Code:
	protected void initialize() {
                //reset fields to values defaulted to on construction
                go=0;
                done=false;
                count=0;
		System.out.println(this);
	}
I suspect you will also want to remember your setpoint and assign that to tcount in the initializer as well since it is being reassigned during execute()

Code:
public class MagicElevator extends Command {

        ...
        int mySetpoint;
        ...

	public MagicElevator(int setpoint) {
		// Use requires() here to declare subsystem dependencies
		requires(Robot.elevator);
		mySetpoint=setpoint;
	}

	// Called just before this Command runs the first time
	protected void initialize() {
                go=0;
                done=false;
                count=0;
		tcount=mySetpoint;
		System.out.println(this);
	}
Reply With Quote