![]() |
Run Command Once When Trigger is Pressed
How do i make it so that a command runs once when the trigger is pressed?
|
Re: Run Command Once When Trigger is Pressed
Quote:
Run the command when the boolean is TRUE and set the boolean OFF after running. |
Re: Run Command Once When Trigger is Pressed
yourTrigger.whileActive(yourCommand);
|
Re: Run Command Once When Trigger is Pressed
Try:
Joystick stick = new Joystick(1); JoystickButton trigger = new JoystickButton(stick, 1); trigger.whenPressed(new MyCommand)); |
Quote:
|
Re: Run Command Once When Trigger is Pressed
Quote:
Ether's suggestion is the generic description of exactly what Kriek suggestion does for you. |
Quote:
|
Re: Run Command Once When Trigger is Pressed
Quote:
|
Quote:
|
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) |
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 |
Re: Run Command Once When Trigger is Pressed
Quote:
|
Quote:
|
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.
|
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. |
| All times are GMT -5. The time now is 10:10. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi