Go to Post ...our football team was a state champion, but i don't see -them- going to atlanta and winning there! :D - Sam Lipscomb [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 19-02-2007, 19:16
Lavapicker's Avatar
Lavapicker Lavapicker is offline
Registered User
FRC #1056 (Hot Rocks)
Team Role: Mentor
 
Join Date: Jul 2004
Rookie Year: 2003
Location: Hilo, HI
Posts: 101
Lavapicker is just really niceLavapicker is just really niceLavapicker is just really niceLavapicker is just really nice
Programming "sleep" function

We need to move our arm in autonomous but can't figure out how to program in a delay to regulate how long the motor stays on for. How is everyone else doing this??
  #2   Spotlight this post!  
Unread 19-02-2007, 19:50
Bongle's Avatar
Bongle Bongle is offline
Registered User
FRC #2702 (REBotics)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Waterloo
Posts: 1,069
Bongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond repute
Send a message via MSN to Bongle
Re: Programming "sleep" function

Declare a global int counter, or a static int counter.

Suppose your autonomous mode can be divided into stages, like:
Stage 1: Drive closer to rack
Stage 2: Use camera to detect rack
Stage 3: Drive to vision target
Stage 4: Position Arm
Stage 5: Place ringer

Inside your autonomous routine, have something like this:

if(counter >= 0 && counter < STAGE_ONE_END)
{ // actions to do in stage 1
}
else if(counter >= STAGE_ONE_END && counter < STAGE_TWO_END)
{ // actions to do in stage 2
}
else if(counter >= STAGE_TWO_END && counter < STAGE_THREE_END)
{ // actions to do in stage 3
}
... // more if statements

counter++;

The actual values of STAGE_ONE_END and so on would be determined experimentally. Or you could decide for exactly how long you want each stage to run, then take the cycle rate of the CPU (xx.x milliseconds) and determine how many iterations are equivalent to your desired time.

Last edited by Bongle : 19-02-2007 at 19:52.
  #3   Spotlight this post!  
Unread 19-02-2007, 20:21
SuperBK's Avatar
SuperBK SuperBK is offline
Registered User
AKA: BrianK
FRC #1225 (Amperage Robotics)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2006
Location: Henersonville, NC
Posts: 358
SuperBK is just really niceSuperBK is just really niceSuperBK is just really niceSuperBK is just really nice
Thumbs up Re: Programming "sleep" function

Use a counter. Its 26.2 ms for each time User_Autonomous_Code() is called.

Code:
#define STAGE_1 0   
#define STAGE_2 1
#define STAGE_3 2

inside User_Autonomous_Code()

static stage;
int counter;

state = STAGE_1;


  while (autonomous_mode)   /* DO NOT CHANGE! */
  {
switch (stage) { case STAGE_1: // turn motor on here counter = 0; stage = STAGE_2; break; case STAGE_2: ++counter; if (counter = 38) // 1 second { // turn motor off here stage = STAGE_3 } break; }
}
__________________
Brian K
Team 1225 Robotics Mentor
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
MOEmentum: FYI - Post-ship "So, May I Sleep Now?" Mr MOE General Forum 1 22-02-2006 00:54
"call of function without prototype" railerobotics Programming 7 21-01-2006 19:59
New NEMO White Papers! "Creating a Killer Packet" and "25 Ways to Sponsor" Jessica Boucher Team Organization 0 10-08-2005 10:55
I'm having difficulties locating the programming code "gift" Flynn Programming 3 09-01-2005 22:01
"Thunderbirds" Vs. "Team America" Which one will rule the box office? Elgin Clock Chit-Chat 3 07-09-2004 19:53


All times are GMT -5. The time now is 04:45.

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