View Single Post
  #2   Spotlight this post!  
Unread 10-03-2013, 01:42
Kusha's Avatar
Kusha Kusha is offline
Crimpin' ain't easy
AKA: Kusha Gharahi
no team (Looking for a team)
Team Role: College Student
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Dallas, Texas
Posts: 207
Kusha is a jewel in the roughKusha is a jewel in the roughKusha is a jewel in the roughKusha is a jewel in the rough
Re: Best way to implement a timed action

Quote:
Originally Posted by F22Rapture View Post
We need to have our frisbee injector (which is an arm attached to a window motor) actuate forward for exactly X milliseconds, and then retract backwards until it triggers a limit switch. I know there are a couple different ways to do this but I was wondering how it would be best to do so.

1. Spawn off a second thread, set to actuate forward, Timer.delay() for X milliseconds, actuate backward, and then return isFinished() as true when the microswitch is triggered. I could have sworn I'd seen a team do it this way, but then I came across some comments saying that creating a Thread inside a command is a bad idea, etc.

2. Create 2 commands (which I would prefer not to do), the first of which is timed using isTimedOut(), the second of which triggers via the microswitch, and call them sequentially in a command group

3. Ways I haven't thought of

Thoughts?
Why don't you use the FPGA timer?

In java you could do something like
int amountOfTimeToRun = 0;//insert amount of time here to run in milliseconds
//button press or something here
int timeStamp = Timer.getFPGATimestamp();//records time
while(Timer.getFPGATimestamp() - timeStamp <= amountOfTimeToRun)
{actuate forward}
__________________
https://kusha.me