|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Run Command Once When Trigger is Pressed
How do i make it so that a command runs once when the trigger is pressed?
|
|
#2
|
||||
|
||||
|
Re: Run Command Once When Trigger is Pressed
Quote:
Run the command when the boolean is TRUE and set the boolean OFF after running. |
|
#3
|
||||
|
||||
|
Re: Run Command Once When Trigger is Pressed
yourTrigger.whileActive(yourCommand);
|
|
#4
|
||||
|
||||
|
Re: Run Command Once When Trigger is Pressed
Try:
Joystick stick = new Joystick(1); JoystickButton trigger = new JoystickButton(stick, 1); trigger.whenPressed(new MyCommand)); |
|
#5
|
||||
|
||||
|
Could you give me an example of how to do this
|
|
#6
|
|||
|
|||
|
Re: Run Command Once When Trigger is Pressed
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. |
|
#7
|
|||
|
|||
|
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 |
|
#8
|
||||
|
||||
|
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.
|
|
#9
|
||||
|
||||
|
Re: Run Command Once When Trigger is Pressed
Quote:
![]() |
|
#10
|
|||
|
|||
|
Re: Run Command Once When Trigger is Pressed
That's what isFinished() is for.
|
|
#11
|
||||
|
||||
|
Will that work even if the command takes more time to execute than the trigger is held for?
|
|
#12
|
||||
|
||||
|
Re: Run Command Once When Trigger is Pressed
Quote:
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 |
|
#13
|
||||
|
||||
|
#14
|
||||
|
||||
|
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.
|
|
#15
|
|||
|
|||
|
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. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|