Go to Post P.S. Who doesn't have CD as there homepage! (I mean, come on people. It's not like there's anything else to do on the net... :)) - Ryan M. [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 10-03-2013, 01:34
F22Rapture's Avatar
F22Rapture F22Rapture is offline
College Student, Mentor
AKA: Daniel A
FRC #3737 (4H Rotoraptors)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Goldsboro, NC
Posts: 476
F22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant future
Best way to implement a timed action

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?
__________________
Research is what I’m doing when I don’t know what I’m doing.
- Wernher von Braun
Attending: Raleigh NC Regional
  #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
  #3   Spotlight this post!  
Unread 10-03-2013, 03:47
The Lucas's Avatar
The Lucas The Lucas is offline
CaMOElot, it is a silly place
AKA: My First Name is really "The" (or Brian)
FRC #0365 (The Miracle Workerz); FRC#1495 (AGR); FRC#4342 (Demon)
Team Role: Mentor
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Dela-Where?
Posts: 1,564
The Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond repute
Send a message via AIM to The Lucas
Re: Best way to implement a timed action

You could use the WPI Notifier Class (Anyone know if there is a Java equivalent and details on how to use it?)

The upside of using an Notifier is it uses timer interrupts and handlers rather than polling/waiting yourself

To use you could init the Notifier with a TimerEventHandler that reverses the motor. Every time you want to fire, set the motor forward and call StartSingle(delay) for the Notifier (make sure to only do this once per cycle).
__________________
Electrical & Programming Mentor ---Team #365 "The Miracle Workerz"
Programming Mentor ---Team #4342 "Demon Robotics"
Founding Mentor --- Team #1495 Avon Grove High School
2007 CMP Chairman's Award - Thanks to all MOE members (and others) past and present who made it a reality.
Robot Inspector
"I don't think I'm ever more ''aware'' than I am right after I burn my thumb with a soldering iron"
  #4   Spotlight this post!  
Unread 10-03-2013, 04:41
westin444's Avatar
westin444 westin444 is offline
C++ Programmer
AKA: Westin Miller
FRC #1983 (Skunkworks)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2011
Location: Seattle, WA
Posts: 7
westin444 is on a distinguished road
Send a message via MSN to westin444
Re: Best way to implement a timed action

Assuming that you want to implement this as a command you can do something where you use the FPGA timer to time the 'halfway point' of the command.
In the command initialize you set a start time variable for the command to the current time.
In the execute you do something along the lines of setting the solenoid to forward when the start time + delay time is less than the current time, and set in to reverse otherwise.
In the is finished you can then check to see if the delay has passed and the limit switch is active.

In C++ this would be something like this:
https://gist.github.com/Equinox-/5127682

Last edited by westin444 : 10-03-2013 at 04:53. Reason: Example
  #5   Spotlight this post!  
Unread 10-03-2013, 22:21
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: Best way to implement a timed action

If you're using Java, anonymous classes can make adding two commands seem much less annoying:
Code:
addSequential(new Command(X/1000.0) {
    protected void initialize() {
        injector.actuateForward();
    }
    protected void execute() {}
    protected boolean isFinished() {
        return isTimedOut();
    }
    protected void end() {
        injector.stopActuating();
    }
    protected void interrupted() {
        end();
    }
});
addSequential(new Command() {
    protected void initialize() {
        injector.actuateBackward();
    }
    protected void execute() {}
    protected boolean isFinished() {
        return microswitch.isTriggered();
    }
    protected void end() {
        injector.stopActuating();
    }
    protected void interrupted() {
        end();
    }
});
Unfortunately, this will only stop the injector within whatever time increment Scheduler.run() is called, which if it's being run in periodic() is the period between driver station packets are coming, or about 20ms. A thread may be a better choice if you need finer resolution.
__________________
I code stuff.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 03:02.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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