View Single Post
  #5   Spotlight this post!  
Unread 16-10-2015, 15:31
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,715
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: Help first time programmer

Quote:
Originally Posted by dwhite View Post
I still see one issue with notmattlythgoe's solution: since the buttonPressed is always equal to the state of the button, the modes will only be switched while the button is being held down and return to the default mode when the button is released.
You could then do something like this:
Code:
public void teleopPeriodic() {
        boolean buttonPressed = false;
	if (stick.getRawButton(3)) {
                buttonPressed = !buttonPressed;
        }

	if (buttonPressed) {
		drive1.arcadeDrive(stick);
	} else {
		drive.arcadeDrive(stick);
	}
}
However, then the modes would keep switching as long is the button is held. Really what you care about is when the button state changes from false to true. You can keep track of this with two booleans, one for the old state and one for the new.
So what you actually want is this:
Code:
public void teleopInit(){
	oldButtonState = false;
	newButtonState = false;
}
public void teleopPeriodic() {
        newButtonState = stick.getRawButton(3);

	if (newButtonState && !oldButtonState) {
		drive1.arcadeDrive(stick);
	} else {
		drive.arcadeDrive(stick);
	}
        oldButtonState = newButtonState;
}
Also add declarations for oldButtonState and newButtonState as booleans with the rest of your declarations.
There might be a more elegant solution, but hopefully that works.
Hope that helps!
Good catch.
Reply With Quote