Go to Post What is the airspeed velocity of an unladen wiffle ball? - The Doctor [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 20-01-2014, 17:05
mmolo mmolo is offline
Registered User
FRC #4241
 
Join Date: Jan 2014
Location: Joliet
Posts: 2
mmolo is an unknown quantity at this point
Java Autonomous Periodic

Hey everyone, my team is just starting to code our robot in Java. We have some decent Java experience, but we have a question about how autonomousPeriodic is ran. Basically, since the Periodic methods are going to be called every ~20ms if we have code like this:
Code:
    
public void autonomousPeriodic() {
        drive.drive(0.5, 0.0);
        Timer.delay(3000);
        drive.drive(0.0, 0.0);
        piston.set(true);
        Timer.delay(2000);
        piston.set(false);
    }
Will this code be called every 20ms and attempt to drive forward and set the pistons 50 times per second?

If so I'm guessing we would just have to wrap it in an if statement that will set a boolean that it's checking to false as soon as it runs, so it only runs the first time.

Thanks in advance!
Reply With Quote
  #2   Spotlight this post!  
Unread 20-01-2014, 17:07
joelg236 joelg236 is offline
4334 Retired Mentor & Alumni
AKA: Joel Gallant
no team
Team Role: Mentor
 
Join Date: Dec 2011
Rookie Year: 2012
Location: Calgary
Posts: 733
joelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond repute
Re: Java Autonomous Periodic

Use initAutonomous() instead to only have it run once. Your code will not run 50 times per second, but it will loop back every time the method finishes (until autonomous is complete)
__________________
All opinions are my own.
Reply With Quote
  #3   Spotlight this post!  
Unread 20-01-2014, 17:12
mmolo mmolo is offline
Registered User
FRC #4241
 
Join Date: Jan 2014
Location: Joliet
Posts: 2
mmolo is an unknown quantity at this point
Re: Java Autonomous Periodic

Ah, thank you. That would make more sense.
Reply With Quote
  #4   Spotlight this post!  
Unread 20-01-2014, 21:08
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 434
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: Java Autonomous Periodic

In the Iterative robot project. The AutonomousInit() method is called once, each time the auto mode is entered (this is triggered by the field). It is meant to aid in initializing variables/components to known states.

Putting code in this method which delays for any significant length of time is not what it was designed for. I've take a look through the source code for the IterativeRobot class, and I can't find anything indicating that it won't work (that's not saying that it will). Just know that the Timer.delay() method should never be used in any of the periodic methods within the IterativeRobot project.

The SimpleRobot class, on the other hand, will work perfectly fine with such delays in the auto/teleop methods. You might consider using that class instead if you anticipate needing to use delays in other areas of your code.
__________________
http://team2168.org
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 12:42.

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