Go to Post The stated goals of FIRST are to inspire a culture that values science and technology. Inspiration needs Motivation. What motivates people? Competition. - Dmentor [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 24-03-2012, 21:44
thecakeisalie's Avatar
thecakeisalie thecakeisalie is offline
Registered User
FRC #0293
 
Join Date: Mar 2012
Location: Pennington
Posts: 37
thecakeisalie is an unknown quantity at this point
Wait/Pause function?

While working out some of the kinks in our code, i stumbled upon a problem. That problem being that I could not have the robot wait for a certain period of time before continuing with its code. So now my question is this: Is there any function that can be used to pause the robot for a certain amount of time?
Thanks.

Last edited by thecakeisalie : 24-03-2012 at 21:46.
Reply With Quote
  #2   Spotlight this post!  
Unread 24-03-2012, 21:46
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,098
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Wait/Pause function?

Quote:
Originally Posted by thecakeisalie View Post
While working out some of the kinks in our code, i stumbled upon a problem. That problem being that I could not have the robot wait for a certain period of time before continuing with its code. So now my question is this: Is there any function that can be used to pause the robot for a certain amount of time?
When you say "I could not have the robot wait for a certain period of time before continuing with its code" did you mean precisely that, or did you mean when you tried to do it, the robot would stop responding to driver commands while it was waiting?


Reply With Quote
  #3   Spotlight this post!  
Unread 24-03-2012, 21:53
thecakeisalie's Avatar
thecakeisalie thecakeisalie is offline
Registered User
FRC #0293
 
Join Date: Mar 2012
Location: Pennington
Posts: 37
thecakeisalie is an unknown quantity at this point
Re: Wait/Pause function?

I tried to do it with a simple for loop:
for (int x= 0; x< 500; x++)
this was made in autonomous periodic, which I believed would count up one every 20 miliseconds, which should equal around 5 seconds. But this did not work and did not delay the robot at all.
Reply With Quote
  #4   Spotlight this post!  
Unread 24-03-2012, 22:04
rbmj rbmj is offline
Registered User
FRC #0612 (Chantilly Robotics)
Team Role: Alumni
 
Join Date: Apr 2011
Rookie Year: 2011
Location: DC Area/Fairfax County
Posts: 192
rbmj is a jewel in the roughrbmj is a jewel in the roughrbmj is a jewel in the rough
Re: Wait/Pause function?

You can try Wait(double) in Timer.h

And that's just a simple two instruction loop. It won't occupy the processor for long (though it will waste computing power when compared to a yield AFAIK), it won't be reliable (timing could change very easily based on process scheduling), and it may be optimized out by the compiler.

Last edited by rbmj : 24-03-2012 at 22:07.
Reply With Quote
  #5   Spotlight this post!  
Unread 24-03-2012, 22:09
thecakeisalie's Avatar
thecakeisalie thecakeisalie is offline
Registered User
FRC #0293
 
Join Date: Mar 2012
Location: Pennington
Posts: 37
thecakeisalie is an unknown quantity at this point
Re: Wait/Pause function?

Quote:
Originally Posted by rbmj View Post
You can try Wait(double) in Timer.h

And that's just a simple two instruction loop. It won't occupy the processor for long (though it will waste computing power when compared to a yield AFAIK), it won't be reliable (timing could change very easily based on process scheduling), and it may be optimized out by the compiler.
Thanks, I shall try your suggestion.
Reply With Quote
  #6   Spotlight this post!  
Unread 25-03-2012, 12:04
Jay Meldrum's Avatar
Jay Meldrum Jay Meldrum is offline
Registered User
FRC #0067 (H.O.T.)
Team Role: Engineer
 
Join Date: Jan 2012
Rookie Year: 2003
Location: Michigan
Posts: 42
Jay Meldrum has much to be proud ofJay Meldrum has much to be proud ofJay Meldrum has much to be proud ofJay Meldrum has much to be proud ofJay Meldrum has much to be proud ofJay Meldrum has much to be proud ofJay Meldrum has much to be proud ofJay Meldrum has much to be proud ofJay Meldrum has much to be proud of
Re: Wait/Pause function?

Something like this maybe useful for pausing. This example is directed towards auton, but can be applied in any instance of pausing

Code:
m_autoPeriodicLoops++;
//Make sure in your init you set m_autonomousCase = 1;
switch(m_autonomousCase)
{
case 1:
{
    //Reset auto counter
    m_autoPeriodicLoops = 0;
    m_autonomousCase = 2;
}
case 2:
{
     if(m_autoPeriodicLoops < 50)
     {
         //Wait for 50 loops 50 * ~20ms = ~1 second
         robotDrive->TankDrive(0.0 , 0.0);
     }
     else
     {
         //Robot will drive after the 50 loops have completed
         robotDrive->TankDrive(0.5 , 0.5);
      }
}
This will pause the robot for about one second (this can vary depending on how much other code is running, and what you have your Periodic loop set to refresh at). Default is about 20 ms.

By using this method you can have other things in the background running in your loops but you are not "stopping" the cRio completely by using a Wait function.
__________________
2012-2015 - FRC 67 - Programming/Controls Lead Mentor
2003-2005 - FRC 857 - Driver

Check us out at http://www.hotteam67.org
Previous year design docs, programming tutorials, and more!
Reply With Quote
  #7   Spotlight this post!  
Unread 25-03-2012, 12:14
Travis Hoffman's Avatar Unsung FIRST Hero
Travis Hoffman Travis Hoffman is offline
O-H
FRC #0048 (Delphi E.L.I.T.E.)
Team Role: Engineer
 
Join Date: Sep 2001
Rookie Year: 2001
Location: Warren, Ohio USA
Posts: 4,047
Travis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond repute
Re: Wait/Pause function?

We use a timer to implement delays. Here is our bread and butter 2-ball front of key autonomous code - this is called from AutonomousPeriodic:

Code:
void XM15::AutoThree1(void)
{
	//printf("3-PT 1 - Front of Key\n");
	
	#define	TH1_READYDWELL	4.0		//Dwell time to permit to move to shot position
	#define TH1_SHOTDELAY	0.5		//Short pause between oktoshoot signal and feeding ball
	#define	TH1_SHOT1DWELL	0.4		//0.5 OK - Feed time for first ball
	#define TH1_SHOT2DWELL	1.0		//Feed time for second ball
	#define	TH1_REGENDWELL	1.5		//Wait for shooter to regain speed = originally 2.0
	
	switch (autonStep)
	{
		case 1: //Select Front Key Three Arm Position & Spin Up Shooter 
		{

			autofrontkeythree_sw = 1;
			
			shooterstate = ON;
			
			if (delaytimer->Get() < delayset) 	//Wait until the timer times past the preset delay
			{

				//Waiting...
				
			}
			else
			{
				delaytimer->Stop();
				
				autotimer->Reset();
				
				autonStep = 2;			
			}	
			
			break;
		}
		case 2: //Wait for arm and shooter to be ready (or watchdog timeout), then fire a ball 
		{				
			
			if ( (oktoshoot == 1) || (autotimer->Get() > TH1_READYDWELL) )
			{	
				autotimer->Reset();

				autonStep = 3;
			}
		
			break;
		}
		case 3: //Wait for a short moment after arm in position before firing a ball
		{				
			
			if (autotimer->Get() > TH1_SHOTDELAY) 
			{
				autocagefeed_sw = 1;
				
				autotimer->Reset();

				autonStep = 4;
			}
		
			break;
		}			
		case 4: //Stop firing after timeout
		{
			if (autotimer->Get() > TH1_SHOT1DWELL)
			{
				autocagefeed_sw = 0;
				
				autotimer->Reset();
				
				autonStep = 5;
				//autonStep = 7;		//Debug - permits tuning of initial shot timing
			}
						
			break;
		}
		case 5: //Wait for shooter to regain speed, then fire again 
		{			
			if (autotimer->Get() > TH1_REGENDWELL)
			{
				if (speedok == 1)
				{

					autocagefeed_sw = 1;
					
					autotimer->Reset();
					
					autonStep = 6;
					
				}
			
			}
			
			break;
		}
		case 6: //Turn shooter off after 2nd ball is fired
		{		
			if (autotimer->Get() > TH1_SHOT2DWELL)
			{
				autocagefeed_sw = 0;
				
				autotimer->Reset();
				
				autonStep = 7;
			}
								
			break;
		}	
		case 7: //Program is done - turn off the shooter, place arm in load position
		{
			
			shooterstate = OFF;
			
			//autofrontkeythree_sw = 0;
			
			//autoloadball_sw = 1;
		
			break;
		}
		
	}
	
}
__________________

Travis Hoffman, Enginerd, FRC Team 48 Delphi E.L.I.T.E.
Encouraging Learning in Technology and Engineering - www.delphielite.com
NEOFRA - Northeast Ohio FIRST Robotics Alliance - www.neofra.com
NEOFRA / Delphi E.L.I.T.E. FLL Regional Partner
Reply With Quote
  #8   Spotlight this post!  
Unread 26-03-2012, 10:25
adein adein is offline
Registered User
AKA: Aaron
FRC #0094 (TechnoJays)
Team Role: Mentor
 
Join Date: Mar 2012
Rookie Year: 2011
Location: Metro Detroit
Posts: 1
adein is an unknown quantity at this point
Re: Wait/Pause function?

I use a state system and a Timer object inside of an 'iterable' function. The function returns false until the operation is complete. This works well if you use the 'Iterable' robot template that comes with WindRiver.

The state variable 'state_' must be set to kPhase1 before the function is called the first time (make sure you don't keep setting the state to kPhase1 each time through the control loop). The timer will have a resolution equal to the duration of the calling control loop.

Code:
bool TechnoJays::SomeFunction() {
	double time_left = 0.0;
	// Get the timer value since the last event
	double elapsed_time = timer_->Get();

	switch (state_) {
	// Start the timer and move to phase 2
	case kPhase1:
		timer_->Stop();
		timer_->Reset();
		timer_->Start();
		elapsed_time = timer_->Get();
		state_ = kPhase2;
		// Fall through into kPhase2
	// Do nothing until the time has elapsed
	case kPhase2:
		// Calculate time left
		time_left = delay_time_ - elapsed_time;
		// If enough time has passed, continue
		if (time_left <= 0.0) {
			timer_->Stop();
			state_ = kPhase3;
			// Fall through to kPhase3
		} else {
			break;
		}
	// The time delay is finished, continue on
	case kPhase3:
		// Return true indicating that the function is complete
		state_ = kNotRunning;
		return true;
	default:
		state_ = kNotRunning;
		return true;
	}

	return false;
}
Reply With Quote
  #9   Spotlight this post!  
Unread 04-04-2012, 13:27
enrique's Avatar
enrique enrique is offline
Registered User
FRC #1251 (Tech Tigers)
Team Role: Electrical
 
Join Date: Jan 2010
Rookie Year: 2010
Location: Florida
Posts: 87
enrique will become famous soon enough
Send a message via Yahoo to enrique
Re: Wait/Pause function?

Quote:
Originally Posted by thecakeisalie View Post
While working out some of the kinks in our code, i stumbled upon a problem. That problem being that I could not have the robot wait for a certain period of time before continuing with its code. So now my question is this: Is there any function that can be used to pause the robot for a certain amount of time?
Thanks.
Wait(1.0);
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 03:00.

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