Go to Post This makes me want to squeal like the teenage girl I am. - ZipTie3182 [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 28-03-2014, 21:26
Accentuate's Avatar
Accentuate Accentuate is offline
Registered User
FRC #4587 (Jersey Voltage)
Team Role: Programmer
 
Join Date: Jul 2013
Rookie Year: 2013
Location: Houston, TX
Posts: 2
Accentuate is an unknown quantity at this point
Java Timer.delay help

So we are trying to move away from Timer.Delay in our robot code because we are aware of the lag it brings to the whole robot when we are trying to reload the shooter. I am trying to find a way to implement a wait function with the Timer.getFPGATimestamp, but I'm drawing blanks on how to implement it.

I'm postulating that I'd have to implement by resetting the timer, then implementing something like this:
Quote:
public boolean hasPeriodPassed(double period) {
if (timer.getFPGATimestamp() < period * 1000000) {
return true;
}
else {
return false;
}
}
}
But we got no results when we tried it like this.

An example of where we implement Timer.delay looks like this:
Quote:
public void Fire() {
IntakeDown.set(false);
IntakeUp.set(true);
isIntakeUp = true;
Timer.delay(0.25);
shooterLatch.set(false);
shooterUnlatch.set(true);
Timer.delay(1.0);
isLatched = false;
isBottom = false;
isReset = false;
isFired = true;

}
If someone could point me in the right direction, it would be greatly appreciated.
Reply With Quote
  #2   Spotlight this post!  
Unread 28-03-2014, 23:15
cgmv123's Avatar
cgmv123 cgmv123 is offline
FRC RI/FLL Field Manager
AKA: Max Vrany
FRC #1306 (BadgerBOTS)
Team Role: College Student
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Madison, WI
Posts: 2,085
cgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond repute
Re: Java Timer.delay help

You don't need to multiply period. Timer.getFPGATimestamp() returns seconds; not milliseconds, microseconds or nanoseconds.
__________________
BadgerBOTS Robotics|@team1306|Facebook: BadgerBOTS
2016 FIRST Championship Tesla Division | 2016 Wisconsin Regional Engineering Inspiration Award

2015 FIRST Championship Carson Division | 2015 Wisconsin Regional Chairman's Award

2013 FIRST Championship Curie Division | 2013 Wisconsin Regional Chairman's Award

2012 FIRST Championship Archimedes Division | 2012 Wisconsin Regional Engineering Inspiration Award, Woodie Flowers Finalist Award (Lead Mentor Ben Senson)

Reply With Quote
  #3   Spotlight this post!  
Unread 28-03-2014, 23:28
Accentuate's Avatar
Accentuate Accentuate is offline
Registered User
FRC #4587 (Jersey Voltage)
Team Role: Programmer
 
Join Date: Jul 2013
Rookie Year: 2013
Location: Houston, TX
Posts: 2
Accentuate is an unknown quantity at this point
Re: Java Timer.delay help

Yeah I figured that, but when I deleted that part. It still did not work correctly.
Reply With Quote
  #4   Spotlight this post!  
Unread 28-03-2014, 23:51
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,590
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Java Timer.delay help

You need to save the current value of Timer.getFPGATimestamp() to compare it to, since it wont always be 0.
Reply With Quote
  #5   Spotlight this post!  
Unread 30-03-2014, 18:09
pblankenbaker pblankenbaker is offline
Registered User
FRC #0868
 
Join Date: Feb 2012
Location: Carmel, IN, USA
Posts: 108
pblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of light
Re: Java Timer.delay help

Here is an example of setting/tracking a start time as you transition through your fire sequence. It is broken out into one private attribute (time the sequence was started) and three helper methods.

NOTE: This assumes you are programming using the SimpleRobot framework.

Code:
    // This will be set to the time when the fire sequence was started. It
    // will be reset to 0 when the fire sequence completes

    private double fireSequenceStart = 0.0;

    /**
     * Helper method to indicate whether we are currently firing.
     */

    public boolean isFiring() {
        // When the fire start time is set to a non-zero value, then
        // we are firing
        return (fireSequenceStart != 0);
    }

    /**
     * Helper method to start the fire sequence (call this after a certain
     * button has been pressed during operatorControl(), or call it from
     * autonomous() if you want to fire then).
     */
    public void fire() {
        // Don't start a second fire sequence until the first completes
        if (isFiring() == false) {

            // Save time the fire sequence was started at
            fireSequenceStart = Timer.getFPGATimestamp();

            // Not sure if you want this, but you may want to clear your
            // internal "isFired" flag here if you don't clear it elsewhere
            // isFired = false;
        }
    }

    /**
     * Repeatedly call this method from your main loop in operatorControl() or
     * autonomous(). It should take you through your fire sequence without
     * blocking (requires no Timer.delay() calls).
     *
     * ***WARNING*** Make sure your other code does not block or have delays in
     * it, or this timing sequence may fail!
     */

    public void updateFireState() {
        if (isFiring() == true) {
            // Determine number of seconds into fire sequence
            double secsElapsed = Timer.getFPGATimestamp() - fireSequenceStart;

            // This is an attempt to refactor your original Fire() code
            // to change states based on the time elapsed (but with no Timer.delay() calls)
            if (secsElapsed < 0.25) {
                // State for first quarter second (0.0 to 0.25)
                IntakeDown.set(false);
                IntakeUp.set(true);
                isIntakeUp = true;
            } else if (secsElapsed < 1.25) {
                // State for the next second (0.25 to 1.0)
                shooterLatch.set(false);
                shooterUnlatch.set(true);
                // Hmmm, shouldn't isIntakeUp be set to false here?
            } else {
                // Finished (1.25 seconds have elapsed)

                // Reset start time to 0 (indicates we are done with the fire sequence)
                fireSequenceStart = 0;
                isLatched = false;
                isBottom = false;
                isReset = false;
                isFired = true;
            }
        }
    }
Hope that helps.
Reply With Quote
  #6   Spotlight this post!  
Unread 30-03-2014, 18:49
SousVide SousVide is offline
Registered User
no team
 
Join Date: Jan 2011
Location: CA
Posts: 91
SousVide is a splendid one to beholdSousVide is a splendid one to beholdSousVide is a splendid one to beholdSousVide is a splendid one to beholdSousVide is a splendid one to beholdSousVide is a splendid one to beholdSousVide is a splendid one to behold
Re: Java Timer.delay help

We use edu.wpi.first.wpilibj.Timer liberally. See our Catapult subsystem code:

https://github.com/team3453/team3453.../Catapult.java
Reply With Quote
Reply


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 13:26.

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