Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Run Command Once When Trigger is Pressed (http://www.chiefdelphi.com/forums/showthread.php?t=113131)

inkspell4 09-02-2013 16:40

Run Command Once When Trigger is Pressed
 
How do i make it so that a command runs once when the trigger is pressed?

Ether 09-02-2013 16:47

Re: Run Command Once When Trigger is Pressed
 
Quote:

Originally Posted by inkspell4 (Post 1230598)
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.



Arhowk 09-02-2013 16:49

Re: Run Command Once When Trigger is Pressed
 
yourTrigger.whileActive(yourCommand);

krieck 09-02-2013 16:50

Re: Run Command Once When Trigger is Pressed
 
Try:

Joystick stick = new Joystick(1);
JoystickButton trigger = new JoystickButton(stick, 1);
trigger.whenPressed(new MyCommand));

inkspell4 09-02-2013 16:58

Quote:

Originally Posted by Ether (Post 1230604)
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

RufflesRidge 09-02-2013 17:02

Re: Run Command Once When Trigger is Pressed
 
Quote:

Originally Posted by inkspell4 (Post 1230612)
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.

inkspell4 09-02-2013 17:12

Quote:

Originally Posted by RufflesRidge (Post 1230614)
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.

Arhowk 09-02-2013 17:14

Re: Run Command Once When Trigger is Pressed
 
Quote:

Originally Posted by inkspell4 (Post 1230619)
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. :(

inkspell4 09-02-2013 17:15

Quote:

Originally Posted by Arhowk (Post 1230620)
refer back to my first post. :(

Will that work even if the command takes more time to execute than the trigger is held for?

Arhowk 09-02-2013 17:20

Re: Run Command Once When Trigger is Pressed
 
Quote:

Originally Posted by inkspell4 (Post 1230623)
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)

BradAMiller 09-02-2013 17:21

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

RufflesRidge 09-02-2013 17:21

Re: Run Command Once When Trigger is Pressed
 
Quote:

Originally Posted by inkspell4 (Post 1230619)
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.

inkspell4 09-02-2013 17:22

Quote:

Originally Posted by RufflesRidge (Post 1230630)
That's what isFinished() is for.

Forgot about that, Thanks

Peragore 10-02-2013 19:54

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.

NotInControl 12-02-2013 20:35

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