Go to Post EVERYTHING in life is politics. - Amanda Morrison [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 09-02-2013, 16:40
inkspell4's Avatar
inkspell4 inkspell4 is offline
Registered User
FRC #3650 (Robo Raptors)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Maryland
Posts: 326
inkspell4 will become famous soon enough
Run Command Once When Trigger is Pressed

How do i make it so that a command runs once when the trigger is pressed?
__________________
Chesapeake Regional : 2013, 2012, 2011
Rookie Year: 2011
2013 RoboRaptors Team 3650 Programming Team Captain
Team Website : http://www.roboraptorsfrcteam3650.com/index.html
_____________________________________________
Reply With Quote
  #2   Spotlight this post!  
Unread 09-02-2013, 16:47
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,089
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Run Command Once When Trigger is Pressed

Quote:
Originally Posted by inkspell4 View Post
How do i make it so that a command runs once when the trigger is pressed?
Set a boolean TRUE on rising edge of trigger, and

Run the command when the boolean is TRUE and set the boolean OFF after running.


Reply With Quote
  #3   Spotlight this post!  
Unread 09-02-2013, 16:49
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 543
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: Run Command Once When Trigger is Pressed

yourTrigger.whileActive(yourCommand);
Reply With Quote
  #4   Spotlight this post!  
Unread 09-02-2013, 16:50
krieck's Avatar
krieck krieck is offline
Registered User
AKA: Keith
FRC #2846 (Firebears)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Minnesota
Posts: 49
krieck is an unknown quantity at this point
Re: Run Command Once When Trigger is Pressed

Try:

Joystick stick = new Joystick(1);
JoystickButton trigger = new JoystickButton(stick, 1);
trigger.whenPressed(new MyCommand));
Reply With Quote
  #5   Spotlight this post!  
Unread 09-02-2013, 16:58
inkspell4's Avatar
inkspell4 inkspell4 is offline
Registered User
FRC #3650 (Robo Raptors)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Maryland
Posts: 326
inkspell4 will become famous soon enough
Quote:
Originally Posted by Ether View Post
Set a boolean TRUE on rising edge of trigger, and

Run the command when the boolean is TRUE and set the boolean OFF after running.


Could you give me an example of how to do this
__________________
Chesapeake Regional : 2013, 2012, 2011
Rookie Year: 2011
2013 RoboRaptors Team 3650 Programming Team Captain
Team Website : http://www.roboraptorsfrcteam3650.com/index.html
_____________________________________________
Reply With Quote
  #6   Spotlight this post!  
Unread 09-02-2013, 17:02
RufflesRidge RufflesRidge is offline
Registered User
no team
 
Join Date: Jan 2012
Location: USA
Posts: 989
RufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant future
Re: Run Command Once When Trigger is Pressed

Quote:
Originally Posted by inkspell4 View Post
Could you give me an example of how to do this
If you're using the Command Based templates I second what Kriek is suggesting.

Ether's suggestion is the generic description of exactly what Kriek
suggestion does for you.
Reply With Quote
  #7   Spotlight this post!  
Unread 09-02-2013, 17:12
inkspell4's Avatar
inkspell4 inkspell4 is offline
Registered User
FRC #3650 (Robo Raptors)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Maryland
Posts: 326
inkspell4 will become famous soon enough
Quote:
Originally Posted by RufflesRidge View Post
If you're using the Command Based templates I second what Kriek is suggesting.

Ether's suggestion is the generic description of exactly what Kriek
suggestion does for you.
It doesn't work because the execute command keeps going on. Is there a way to stop the execute command and make the subsystem revert to the default command.
__________________
Chesapeake Regional : 2013, 2012, 2011
Rookie Year: 2011
2013 RoboRaptors Team 3650 Programming Team Captain
Team Website : http://www.roboraptorsfrcteam3650.com/index.html
_____________________________________________
Reply With Quote
  #8   Spotlight this post!  
Unread 09-02-2013, 17:14
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 543
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: Run Command Once When Trigger is Pressed

Quote:
Originally Posted by inkspell4 View Post
It doesn't work because the execute command keeps going on. Is there a way to stop the execute command and make the subsystem revert to the default command.
refer back to my first post.
Reply With Quote
  #9   Spotlight this post!  
Unread 09-02-2013, 17:15
inkspell4's Avatar
inkspell4 inkspell4 is offline
Registered User
FRC #3650 (Robo Raptors)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Maryland
Posts: 326
inkspell4 will become famous soon enough
Quote:
Originally Posted by Arhowk View Post
refer back to my first post.
Will that work even if the command takes more time to execute than the trigger is held for?
__________________
Chesapeake Regional : 2013, 2012, 2011
Rookie Year: 2011
2013 RoboRaptors Team 3650 Programming Team Captain
Team Website : http://www.roboraptorsfrcteam3650.com/index.html
_____________________________________________
Reply With Quote
  #10   Spotlight this post!  
Unread 09-02-2013, 17:20
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 543
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: Run Command Once When Trigger is Pressed

Quote:
Originally Posted by inkspell4 View Post
Will that work even if the command takes more time to execute than the trigger is held for?
No.

if you use whenPressed (or whenActive), it will activate when the button is pressed and wont stop untill isFinished returns true

if you use whileHeld (or whileActive), it will activate when the button is pressed and wont stop untill isFinished returns true OR the button is released (if the button is released, the command is cancelled but the "end" method will not run and the "interrupted" method will. Keep that in mind when setting things like shooter jags)

Last edited by Arhowk : 09-02-2013 at 17:22. Reason: made wording more clear
Reply With Quote
  #11   Spotlight this post!  
Unread 09-02-2013, 17:21
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 590
BradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant future
Re: Run Command Once When Trigger is Pressed

Here is an example of running commands whenever a joystick button is pressed. You can also associate commands with buttons from the Cypress module or any arbitrary polled trigger (see Trigger class).

http://Wpilib.screenstepslive.com/s/3120/m/7952/l/97457

Besides using whenPressed() you can also call whenReleased() to get a command to run when the button is released or whileHeld() to get a command to repeatedly run while the button is pressed.

Brad
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
Reply With Quote
  #12   Spotlight this post!  
Unread 09-02-2013, 17:21
RufflesRidge RufflesRidge is offline
Registered User
no team
 
Join Date: Jan 2012
Location: USA
Posts: 989
RufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant future
Re: Run Command Once When Trigger is Pressed

Quote:
Originally Posted by inkspell4 View Post
It doesn't work because the execute command keeps going on. Is there a way to stop the execute command and make the subsystem revert to the default command.
That's what isFinished() is for.
Reply With Quote
  #13   Spotlight this post!  
Unread 09-02-2013, 17:22
inkspell4's Avatar
inkspell4 inkspell4 is offline
Registered User
FRC #3650 (Robo Raptors)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Maryland
Posts: 326
inkspell4 will become famous soon enough
Quote:
Originally Posted by RufflesRidge View Post
That's what isFinished() is for.
Forgot about that, Thanks
__________________
Chesapeake Regional : 2013, 2012, 2011
Rookie Year: 2011
2013 RoboRaptors Team 3650 Programming Team Captain
Team Website : http://www.roboraptorsfrcteam3650.com/index.html
_____________________________________________
Reply With Quote
  #14   Spotlight this post!  
Unread 10-02-2013, 19:54
Peragore's Avatar
Peragore Peragore is offline
CEO of Black Magic
AKA: Philip Mulford
FRC #3373 (Team Robohawk)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: US
Posts: 50
Peragore is an unknown quantity at this point
Re: Run Command Once When Trigger is Pressed

Probably already solved, but what I would do is assign a flag to whether the code is required to run. so, when the trigger is pressed (>= .01, maybe), you set the flag to true. the method runs when the method is true, and at the end of the method, it sets the flag to false. Granted this is using SimpleRobot template.
__________________


Code:
 
while (life){
  frcObsession = true;
  obs.ProgramAndObsess();
}
if (!life) life = true;
Reply With Quote
  #15   Spotlight this post!  
Unread 12-02-2013, 20:35
NotInControl NotInControl is offline
Controls Engineer
AKA: Kevin
FRC #2168 (Aluminum Falcons)
Team Role: Engineer
 
Join Date: Oct 2011
Rookie Year: 2004
Location: Groton, CT
Posts: 261
NotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond repute
Re: Run Command Once When Trigger is Pressed

Simply set the isFinsihed() method to return true;


The execute method will run once, isfinsih() will be true and then the command will call the end() method and die.
__________________
Controls Engineer, Team 2168 - The Aluminum Falcons
[2016 Season] - World Championship Controls Award, District Controls Award, 3rd BlueBanner
-World Championship- #45 seed in Quals, World Championship Innovation in Controls Award - Curie
-NE Championship- #26 seed in Quals, winner(195,125,2168)
[2015 Season] - NE Championship Controls Award, 2nd Blue Banner
-NE Championship- #26 seed in Quals, NE Championship Innovation in Controls Award
-MA District Event- #17 seed in Quals, Winner(2168,3718,3146)
[2014 Season] - NE Championship Controls Award & Semi-finalists, District Controls Award, Creativity Award, & Finalists
-NE Championship- #36 seed in Quals, SemiFinalist(228,2168,3525), NE Championship Innovation in Controls Award
-RI District Event- #7 seed in Quals, Finalist(1519,2168,5163), Innovation in Controls Award
-Groton District Event- #9 seed in Quals, QuarterFinalist(2168, 125, 5112), Creativity Award
[2013 Season] - WPI Regional Winner - 1st Blue Banner
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 11:46.

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