Go to Post So if you were a rookie team in this division what would you do? Watch.Experience.Learn. - dodar [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 03-02-2014, 13:08
vandle879 vandle879 is offline
Registered User
FRC #0558
 
Join Date: Feb 2014
Location: Connecticut
Posts: 2
vandle879 is an unknown quantity at this point
Toggle When Pressed Option

First year doing Java and I don't have a robot yet to test on so I was wondering about the toggleWhenPressed option.

Does it simply just switch between the execute and end in whatever command its mapped to each time the same button is pressed?

Ex. Is this the correct usage?

OI

joystickButton1.toggleWhenPressed(new FireSolenoid());


FireSolenoid

...
protected void execute() {
Robot.shooter.pistonUp();
}
...
protected void end() {
Robot.shooter.pistonDown();
}



Will this just switch between pistonUp and pistonDown each time I press button 1?
Reply With Quote
  #2   Spotlight this post!  
Unread 03-02-2014, 13:14
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: Toggle When Pressed Option

Quote:
Originally Posted by vandle879 View Post
First year doing Java and I don't have a robot yet to test on so I was wondering about the toggleWhenPressed option.

Does it simply just switch between the execute and end in whatever command its mapped to each time the same button is pressed?

Ex. Is this the correct usage?

OI

joystickButton1.toggleWhenPressed(new FireSolenoid());


FireSolenoid

...
protected void execute() {
Robot.shooter.pistonUp();
}
...
protected void end() {
Robot.shooter.pistonDown();
}



Will this just switch between pistonUp and pistonDown each time I press button 1?
I'm assuming it doesn't use the end() but the interrupted() method. The whileHeld() method cancels the command that was running, so I'd assume the toggle would do the same thing.

Do you at least have a crio you could plug into and run the code. If you do you could put print statements into those methods to verify that they are being called the way you think they are.
Reply With Quote
  #3   Spotlight this post!  
Unread 08-02-2014, 10:45
vandle879 vandle879 is offline
Registered User
FRC #0558
 
Join Date: Feb 2014
Location: Connecticut
Posts: 2
vandle879 is an unknown quantity at this point
Re: Toggle When Pressed Option

Quote:
Originally Posted by notmattlythgoe View Post
I'm assuming it doesn't use the end() but the interrupted() method. The whileHeld() method cancels the command that was running, so I'd assume the toggle would do the same thing.
Finally got around to trying this out on a cRIO and you were right the interrupted method is what is used to toggle the command.

Thanks for the help!
Reply With Quote
  #4   Spotlight this post!  
Unread 08-02-2014, 23:49
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: Toggle When Pressed Option

The implementation may make things clearer (from Toggle.java in WPILibJ):
Code:
   /**
     * Toggles a command when the trigger becomes active
     * @param command the command to toggle
     */
    public void toggleWhenActive(final Command command) {
         new ButtonScheduler() {

            boolean pressedLast = grab();

            public void execute() {
                if (grab()) {
                    if (!pressedLast) {
                        pressedLast = true;
                        if (command.isRunning()){
                            command.cancel();
                        } else{
                            command.start();
                        }
                    }
                } else {
                    pressedLast = false;
                }
            }
        }.start();
    }
__________________
I code stuff.
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 09:34.

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