Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Command-based while button presed (http://www.chiefdelphi.com/forums/showthread.php?t=111763)

Arhowk 21-01-2013 19:23

Command-based while button presed
 
I want to run a specific command but i only want to run it when the button is pressed but i cant find the specific function for that

Code:

            OI.controlDriver.buttonA.whenPressed(RobotMap.intakeIn);
            OI.controlDriver.buttonA.whenReleased(RobotMap.intakeIn);
            OI.controlDriver.buttonB.whileHeld(RobotMap.intakeOut);

they just continually run the command

F22Rapture 21-01-2013 19:34

Re: Command-based while button presed
 
Quote:

Originally Posted by Arhowk (Post 1219705)
I want to run a specific command but i only want to run it when the button is pressed but i cant find the specific function for that

Code:

            OI.controlDriver.buttonA.whenPressed(RobotMap.intakeIn);
            OI.controlDriver.buttonA.whenReleased(RobotMap.intakeIn);
            OI.controlDriver.buttonB.whileHeld(RobotMap.intakeOut);

they just continually run the command

The problem isn't in the button call itself. You need to set the isFinished() method in your command to something other than "false," otherwise it will never complete.

Psuedocode:

Code:

isFinished() {
      when (frisbeeIsLoaded)
              return true;
}

or

Code:

isFinished() {
      return isTimedOut();
}

When isFinished() returns true, it calls end() and stops the command. If it never returns true, end() is never called.

Mastonevich 21-01-2013 19:44

We found somewhere in the documentation where u need to put it in the interrupted function and it worked for us.

Arhowk 21-01-2013 20:03

Re: Command-based while button presed
 
Quote:

Originally Posted by Mastonevich (Post 1219716)
We found somewhere in the documentation where u need to put it in the interrupted function and it worked for us.

Yeah.... was about to say that putting the cancel functions in interrupted and not end worked.

On a slightly related topic, can I wipe the commands currently linked to a button?

i can do

button.whilePressed();

but can i do

button.releaseCommands();

so that it no longer runs the commands issued by .whilePressed()


All times are GMT -5. The time now is 09:50.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi