Go to Post Just because its a robotics competition does not mean everybody is a big dork. - Taxi Quinn [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

 
 
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
  #9   Spotlight this post!  
Unread 08-01-2014, 10:32
omalleyj omalleyj is offline
Registered User
AKA: Jim O'Malley
FRC #1279 (Cold Fusion)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2008
Location: New Jersey
Posts: 132
omalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to behold
Re: How to make timed sequences in java?

Because many embedded programming environments do not use operating systems I generally avoid threads for dealing with this sort of situation. (threads are a perfectly valid and useful approach in those environments)

In your main loop (either explicit in Simple or implicit in Iterative) just check the time you start and the current time, e.g.: (all from memory, and I usualy code C, so treat this as pseudocode)

Code:
double pistonTimer = 0.0;

while (isTeleop() && isEnabled()){//implicit in Iterative

	//check for the condition that starts the piston
	if (joystick1.RawButton(5)){
		//...stuff that turns on/off the right solenoids...
		pistonTimer = Timer.GetTime();//I believe this is now a double, in seconds
	}

//lots of other things like driving code mixed in

        //check if its done yet
	if (pistonTimer > 0.0 //important so you know you've started timing
	 && Timer.GetTime() - pistonTimer > 2.0){
		//...stuff that turns on/off the other right solenoids...
		pistonTimer = 0.0; //don't forget to reset it
	}

}
While polling like this isn't super efficient it is easy to implement and follow.
HTH
 


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 22:47.

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