Go to Post Defense is not at all anti-GP. - Wetzel [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 21-02-2007, 08:38
Slick Slick is offline
Registered User
no team
 
Join Date: Feb 2005
Location: Martinsville, VA
Posts: 21
Slick is an unknown quantity at this point
Delay Function

Can someone show me a way to write a function that can delay the robot. I would like to write a function and put it in ‘user_routines.c’ and call it anywhere in my ‘user_routines_fast.c’ file. Simply I would like to:

{
pwm13 = 167;
pwm15 = 167;
delay = 100;
}

where ‘delay =’ would pause the robot for whatever time you gave it. Your help would be appreciated. What would the function look like? Thanks...
  #2   Spotlight this post!  
Unread 21-02-2007, 09:15
bear24rw's Avatar
bear24rw bear24rw is offline
Team 11 Programming Captain
AKA: Max T
FRC #0011 (MORT)
Team Role: Programmer
 
Join Date: Sep 2005
Rookie Year: 2005
Location: Flanders, NJ
Posts: 385
bear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to behold
Send a message via AIM to bear24rw
Re: Delay Function

maybe somthing like this..
Code:
void delay(unsigned int seconds)
{
   unsigned int current = 0;
   while (current < (seconds * 1000) / 26.4) // Seconds * 1000 to get milliseconds and then / 26.4 millisecond loop
   {
      getdata(); // forget what parameter getdata takes
      current++;
      putdata(); // forget what parameter putdata takes..
   }
}
I have no idea if that will work but you can try it..
  #3   Spotlight this post!  
Unread 21-02-2007, 12:38
tdlrali tdlrali is offline
Registered User
FRC #0469 (Las Guerrillas)
Team Role: Programmer
 
Join Date: Sep 2006
Rookie Year: 2006
Location: MI
Posts: 377
tdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud of
Re: Delay Function

"Stalling" execution is generally a bad idea. I would make a "loopcounter" variable, and increase the counter every time the function runs. After a certain number of loops, make it do the next thing.

For example, here's our pump code:
Code:
void pump_routine(void) {

	static unsigned int loops = 0;   <--- Loop Counter

	if(BTN_PUMP_DISABLE) {

		if(DIGIN_PUMP_PRESSURE_SWITCH && loops>10) { <-- If more than ten loops have passed

			RLY_PUMP_ON = 0;

		}

		else if(DIGIN_PUMP_PRESSURE_SWITCH) {

			loops++; <-- Increase loop counter

			RLY_PUMP_ON = 1;

		}

		else {

			loops = 0;

			RLY_PUMP_ON = 1;

		}

	}

	else {

		RLY_PUMP_ON = 0;

		loops = 0;

	}

	RLY_PUMP_NUL = 0;

}
  #4   Spotlight this post!  
Unread 28-02-2007, 17:54
Anime-niac_2.9's Avatar
Anime-niac_2.9 Anime-niac_2.9 is offline
Japanese-crap freak(NOTE AVATAR)
AKA: Alex Abenoja, A-Squared, & Anime
FRC #0599 (Robodox)
Team Role: Programmer
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Northridge, California
Posts: 88
Anime-niac_2.9 will become famous soon enough
Re: Delay Function

i've thought about it before, and it turns out something like bear24rw's idea.

Code:
int counter=0;

void User_Autonomous_Code(void)
{
  static unsigned int i;
  const float delay = 100;
  int counter, int limit=(delay*1000)*26.4;

  for(counter=0, counter<limit, counter++)
  {
  }
}
not necessarilly a function, but the interrupt code here (the for loop) should work. all you have to do if place the for loop whereever you want it
__________________
THE ROBODOX FORUM

Reading: Suzumiya Haruhi no Yuutsu by Tanigawa Nagaru
Religion: Haruhiism
  #5   Spotlight this post!  
Unread 01-03-2007, 02:15
Dave K.'s Avatar
Dave K. Dave K. is offline
Engineer/Mentor
FRC #0930
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2005
Location: WI
Posts: 91
Dave K. is a splendid one to beholdDave K. is a splendid one to beholdDave K. is a splendid one to beholdDave K. is a splendid one to beholdDave K. is a splendid one to beholdDave K. is a splendid one to beholdDave K. is a splendid one to behold
Re: Delay Function

Quote:
Originally Posted by Slick View Post
Can someone show me a way to write a function that can delay the robot. I would like to write a function and put it in ‘user_routines.c’ and call it anywhere in my ‘user_routines_fast.c’ file. Simply I would like to:

{
pwm13 = 167;
pwm15 = 167;
delay = 100;
}

where ‘delay =’ would pause the robot for whatever time you gave it. Your help would be appreciated. What would the function look like? Thanks...
... for autonomous no doubt.

Perhaps you will find some insight in this recent thread

I'd suggest structuring your autonomous code to run every 26ms (off the SPI data updates), tuck some timers into that, and structure you code as a state machine.
__________________
--Dave
  #6   Spotlight this post!  
Unread 01-03-2007, 20:17
bear24rw's Avatar
bear24rw bear24rw is offline
Team 11 Programming Captain
AKA: Max T
FRC #0011 (MORT)
Team Role: Programmer
 
Join Date: Sep 2005
Rookie Year: 2005
Location: Flanders, NJ
Posts: 385
bear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to behold
Send a message via AIM to bear24rw
Re: Delay Function

Quote:
Originally Posted by Anime-niac_2.9 View Post
i've thought about it before, and it turns out something like bear24rw's idea.

Code:
int counter=0;

void User_Autonomous_Code(void)
{
  static unsigned int i;
  const float delay = 100;
  int counter, int limit=(delay*1000)*26.4;

  for(counter=0, counter<limit, counter++)
  {
  }
}
not necessarilly a function, but the interrupt code here (the for loop) should work. all you have to do if place the for loop whereever you want it
You need to be carefull with that loop, you need to call putdata and getdata every so often so the master processor doesnt shut down.. i forget what the actual timeout is but its not very long...
  #7   Spotlight this post!  
Unread 01-03-2007, 22:56
TimCraig TimCraig is offline
Registered User
AKA: Tim Craig
no team
 
Join Date: Aug 2004
Rookie Year: 2003
Location: San Jose, CA
Posts: 221
TimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to behold
Re: Delay Function

Quote:
Originally Posted by Anime-niac_2.9 View Post
Code:
  const float delay = 100;
  int counter, int limit=(delay*1000)*26.4;
You do realize that the range for an int is -32,768 to +32,767?
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Delay Help! waiakea2024 Programming 7 21-02-2007 12:41
VEX Ultrasonic Sensor delay P1h3r1e3d13 Programming 4 28-03-2006 13:45
NERDS Delay... Andy Grady General Forum 21 14-03-2006 21:52
Delay in autonomous mode SpeakerSilenced Programming 1 22-02-2005 10:58
Delay Gal Longin Programming 1 09-12-2004 10:37


All times are GMT -5. The time now is 00:29.

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