|
Re: How to make timed sequences in java?
You should not do it in main. As a general rule, you should not sleep or wait in any main function.
Any sleep() command you provide will cause the current thread to sleep. If this is done in main() the main function will sleep. The SimpleRobot Project and IterativeRobot project are single threaded by default, so if you use either of those constructs, and call the sleep command the entire robot will sleep. You should run your code in a separate thread so you are not sleeping the main thread. Failure to do that will cause your entire robot to wait 2 seconds. You can create threads in Java by implementing the Runnable Interface or Extending one of the many Thread classes in the java.util.concurrancy package. In either case you will overide the "run" method which opens a solenoid, sleeps, and closes the solenoid but executes in its own thread.
(i.e Public MyClass extends Thread{
do stuff
}
As Jarad mentioned, using the CommandBase construct is helpful in this sense because CommandBase is multithreaded by default. So if this double solenoid was apart of an Arm subsystem. You could simply create a CommandGroup which calls the command to open the solenoid, waits 2 seconds, then calls the command which closes the solenoid. Each command/CommandGroup executes in its own thread, therefore any waits or sleeps will not hault the entire program.
__________________
Controls Engineer, Team 2168 - The Aluminum Falcons
[2016 Season] - World Championship Controls Award, District Controls Award, 3rd BlueBanner
-World Championship- #45 seed in Quals, World Championship Innovation in Controls Award - Curie
-NE Championship- #26 seed in Quals, winner(195,125,2168)
[2015 Season] - NE Championship Controls Award, 2nd Blue Banner
-NE Championship- #26 seed in Quals, NE Championship Innovation in Controls Award
-MA District Event- #17 seed in Quals, Winner(2168,3718,3146)
[2014 Season] - NE Championship Controls Award & Semi-finalists, District Controls Award, Creativity Award, & Finalists
-NE Championship- #36 seed in Quals, SemiFinalist(228,2168,3525), NE Championship Innovation in Controls Award
-RI District Event- #7 seed in Quals, Finalist(1519,2168,5163), Innovation in Controls Award
-Groton District Event- #9 seed in Quals, QuarterFinalist(2168, 125, 5112), Creativity Award
[2013 Season] - WPI Regional Winner - 1st Blue Banner
|