View Single Post
  #17   Spotlight this post!  
Unread 27-01-2015, 10:09
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,715
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: Command Based Programming (Threads?)

Quote:
Originally Posted by Ether View Post

Thanks for the response. I hope you don't mind some follow-up questions:



What does the waitCommand() do, "under the hood". i.e., how is it implemented?



Is there a "recommended" or "best practice" way to implement that approach?


I haven't looked at the wait command under the hood, but this is how I believe it works. I can look under the hood tonight at the source code and see if I'm correct.

Code:
public class WaitCommand extends Command {

     private double waitTime;

     public WaitCommand(double waitTime) {
          this.waitTime = waitTime;
     }

     public boolean isFinished() {
          return timeSinceInitialized >= waitTme;
     }
}

As to the second question. Something like this would work for a single command doing multiple things based on time.

Code:
public void execute() {
     if (timeSinceInitialized() < sometime) {
          do something;
     } else if(timeSinceInitialized() < some bigger time) {
          do something 2;
     } else {
          do something 3;
     }
}

Last edited by notmattlythgoe : 27-01-2015 at 10:20.
Reply With Quote