Go to Post I dunno, with those Chucks, I'd be inclined to say he out-dresses the better part of DC... - Nuttyman54 [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Events   CD-Media   CD-Spy   FRC-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 02-20-2004, 08:38 PM
Yellow Eyes's Avatar
Yellow Eyes Yellow Eyes is offline
Programmer
AKA: Brian Novak
#0250 (Dynamos)
Team Role: Programmer
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Albany NY
Posts: 15
Yellow Eyes is on a distinguished road
Send a message via AIM to Yellow Eyes Send a message via MSN to Yellow Eyes
sleep()

In our code, we want to use the sleep() function. When we try to compile we get an error saying it can't find the function sleep(). What would we need to include in order to get this to work?
__________________
  #2   Spotlight this post!  
Unread 02-20-2004, 08:40 PM
KenWittlief KenWittlief is offline
.
no team
Team Role: Engineer
 
Join Date: Mar 2003
Location: Rochester, NY
Posts: 4,213
KenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond repute
Re: sleep()

I dont think you want to use any of the sleep modes - there is code that has to run for the RC to function correctly - the code runs in one continious loop - if you put the uP to sleep, it will stop till an interrupt occurs - I think it would cause the RC to lock up or reset on you.

Sleep modes are normally for low power applications, like PDAs or cell phone - your bot will be drawing 50 to 100 amps during a match, so whats 0.1 Amps more or less going to accomplish?
  #3   Spotlight this post!  
Unread 02-20-2004, 08:43 PM
Yellow Eyes's Avatar
Yellow Eyes Yellow Eyes is offline
Programmer
AKA: Brian Novak
#0250 (Dynamos)
Team Role: Programmer
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Albany NY
Posts: 15
Yellow Eyes is on a distinguished road
Send a message via AIM to Yellow Eyes Send a message via MSN to Yellow Eyes
Re: sleep()

what about a pause function? Same results?
__________________
  #4   Spotlight this post!  
Unread 02-20-2004, 08:48 PM
KenWittlief KenWittlief is offline
.
no team
Team Role: Engineer
 
Join Date: Mar 2003
Location: Rochester, NY
Posts: 4,213
KenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond repute
Re: sleep()

same problem, you have to let the main loop run, or the code that is buried in the RC (that we dont see) will say "hey, the user code stopped running, turn off all the victors and relays until it comes back"

( of course it says that in binary: 00011000101010101101101 :c)
  #5   Spotlight this post!  
Unread 02-20-2004, 09:06 PM
Yellow Eyes's Avatar
Yellow Eyes Yellow Eyes is offline
Programmer
AKA: Brian Novak
#0250 (Dynamos)
Team Role: Programmer
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Albany NY
Posts: 15
Yellow Eyes is on a distinguished road
Send a message via AIM to Yellow Eyes Send a message via MSN to Yellow Eyes
Re: sleep()

I was just informed it will be sleep(1); will that 1 millisecond make a difference and cause those problems?
__________________
  #6   Spotlight this post!  
Unread 02-20-2004, 10:33 PM
SeanCassidy's Avatar
SeanCassidy SeanCassidy is offline
Antiregistered User
#0263 (Aftershock)
Team Role: Programmer
 
Join Date: Oct 2003
Location: Holtsville, NY
Posts: 37
SeanCassidy is an unknown quantity at this point
Re: sleep()

What you could do(for autononmous) was have a start time and an end time to all things. Sort of like this:
Code:
//Autonomous code
go(1,0,18);   //Go forward (1 = fwd, 2 = rev), start at 0, and end at 1800ms
turn(1,19,25);  //Turn (1 = left, 2 = right), start at 1900ms end at 2500ms
//Notice the 1000ms delay!
moveArm(2,35,40); //Move arm ( 1 = up, 2 = down), start at 3500ms end at 4000ms
Of course, you'll need to use interrupts (use the white paper from Innovation First), and add a static counter to the t100msDelay, for increments of 100ms. More precision that using seconds. But, the way you should do it is it just sets a pwm (or whatever) equal to the correct value, and move on, when it comes back (you'll have to make it know that it already completed one and it's time to finish up) just set it to 127 or whatever. Very useful and very effective.
  #7   Spotlight this post!  
Unread 02-21-2004, 08:33 PM
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
An inspired alumnus
AKA: Jamie Bliss
no team (previously 904 (D-cubed) and 1227 (Techno-Gremlins))
Team Role: Alumni
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Send a message via ICQ to Astronouth7303 Send a message via AIM to Astronouth7303 Send a message via MSN to Astronouth7303 Send a message via Yahoo to Astronouth7303
Re: sleep()

So is there a way to 'wait' while still having interrupts going? this would be the easiest way to write a Autonomous Script. You know, Left=255;Right=255;Wait(600);.
  #8   Spotlight this post!  
Unread 02-22-2004, 09:14 AM
mtrawls's Avatar
mtrawls mtrawls is offline
I am JVN! (John von Neumann)
#0122 (NASA Knights)
Team Role: Programmer
 
Join Date: Mar 2003
Location: Hampton, VA
Posts: 295
mtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to behold
Send a message via AIM to mtrawls
Re: sleep()

Quote:
Originally Posted by Astronouth7303
So is there a way to 'wait' while still having interrupts going? this would be the easiest way to write a Autonomous Script. You know, Left=255;Right=255;Wait(600);.
I'm sorry, but I don't understand what the advantage is of waiting. Why would you need to pause at a specific instruction for some amount of time? What would you need to do in auton mode that couldn't be accomplished by having a state where the drive motors are sent neutral values? You could just be sitting still "waiting" for some input to come your way ... but you don't need to mess with timer's at all. I just don't see the need, so please explain if I am mistaken ...
  #9   Spotlight this post!  
Unread 02-22-2004, 11:31 AM
ChrisA's Avatar
ChrisA ChrisA is offline
Registered User
#0857 (Superior Roboworks)
Team Role: College Student
 
Join Date: Feb 2002
Location: Michigan Tech
Posts: 157
ChrisA is on a distinguished road
Send a message via AIM to ChrisA
Re: sleep()

There's something called a "FOR LOOP". In this loop, you can specify how long it stays in the loop. You could increment a variable there if you wanted to 'wait' for a certain amount of time. Or, you could use what we like to call a "TIMER". Timers count time. Time can be used for waiting.

Maybe you should be a little more specific on what you're trying to do.
__________________
Programmer
----------------
Team#857
Superior Roboworks

WildStang Alum
  #10   Spotlight this post!  
Unread 02-22-2004, 11:43 AM
deltacoder1020's Avatar
deltacoder1020 deltacoder1020 is offline
Computer Guy
AKA: Dav
#1020 (The Indiana Prank Monkeys)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Muncie, Indiana
Posts: 340
deltacoder1020 has a spectacular aura aboutdeltacoder1020 has a spectacular aura about
Send a message via AIM to deltacoder1020
Re: sleep()

Quote:
Originally Posted by ChrisA
There's something called a "FOR LOOP". In this loop, you can specify how long it stays in the loop. You could increment a variable there if you wanted to 'wait' for a certain amount of time. Or, you could use what we like to call a "TIMER". Timers count time. Time can be used for waiting.

Maybe you should be a little more specific on what you're trying to do.
but do remember that you need to call putdata every 26.2ms or so, or else the processor will shut down, which would not be a good thing in the middle of a match.
__________________
Team 1020, the Indiana Prank Monkeys (www.team1020.org)
  #11   Spotlight this post!  
Unread 02-22-2004, 01:51 PM
Ryan M. Ryan M. is offline
Programming User
FRC #1317 (Digital Fusion)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Ohio
Posts: 1,508
Ryan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud of
Re: sleep()

Quote:
Originally Posted by ChrisA
There's something called a "FOR LOOP". In this loop, you can specify how long it stays in the loop. You could increment a variable there if you wanted to 'wait' for a certain amount of time. Or, you could use what we like to call a "TIMER". Timers count time. Time can be used for waiting.

Maybe you should be a little more specific on what you're trying to do.
If you care, the struture of the for loop is this:
Code:
for(initiazation; test; increment)
{
    // body of loop
}
It is more flexible than that form indicates, but that would be the most common way to use it. A quick example of it actually being used as a "pause."
Code:
// Somewhere at the top
unsigned int i;

// Later on
for(i = 0; i < 10; i++)
{
    // Do nothing
}
This code would cause it to loop ten times and then continue.

Note that if you were using this as a timer, it would be different at different battery charges as the controller would run slower.

Anyways, if anyone cares, there it is.
__________________

  #12   Spotlight this post!  
Unread 02-22-2004, 02:18 PM
jacob_dilles's Avatar
jacob_dilles jacob_dilles is offline
Registered User
AKA: theshadow
FRC #0620 (WarBots)
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2003
Location: Vienna, VA
Posts: 245
jacob_dilles will become famous soon enough
Send a message via AIM to jacob_dilles
Re: sleep()

instead of going to sleep, i would count loops till the required delay has passed. stoping a program is a bad thing, just because of the way the program loop is structured. if that doesnt work, i would use a timer with an inturupt.
__________________
--------------------------
"You're not a real programmer until all your sentences end with semicolons;"
  #13   Spotlight this post!  
Unread 02-22-2004, 05:56 PM
KenWittlief KenWittlief is offline
.
no team
Team Role: Engineer
 
Join Date: Mar 2003
Location: Rochester, NY
Posts: 4,213
KenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond repute
Re: sleep()

Quote:
Note that if you were using this as a timer, it would be different at different battery charges as the controller would run slower.
?!?!?!?!

the microprocessor runs on 5V, regulated from the 12 or 7.2V batteries - and the timing is controlled by a crystal that doesnt care what the battery voltages are

the execution of uP instruction cycles will be dead accurate repeatable, no matter what the state of your battery is, until the battery drops far enough to cause a reset.

I think the people that are contemplating wait states, for loops, do loops or while loops in their code really need to get the default users manaul and get a grasp on how this SW runs

the program takes in inputs from the operator
then it does your processing
then it outputs the results of your processing to the victors and spikes

those three major tasks repeat continiously - you DONT want to pause or stop or put timing delays in your processing area - you want the code to continue to run and loop as fast as it can

so if you are waiting for something to happen, and it hasnt happend yet, then do nothing and check again on the next 'pass' of the SW.

Putting wait states or delays in your code is one of the surest ways to make the controller lock up, and set all your outputs to 'off' - when this happens your bot will go dead and you will have a very expensive, very fancy statue sitting on the field infront of 3000 people.
  #14   Spotlight this post!  
Unread 02-22-2004, 07:00 PM
kristen's Avatar
kristen kristen is offline
PI loves you!
#0639 (Code Red)
Team Role: Human Player
 
Join Date: Jan 2003
Location: Ithaca, NY
Posts: 283
kristen will become famous soon enough
Send a message via AIM to kristen
Re: sleep()

Ok, you'll need two global variables (put them in user_routines_fast.c, or something):
Code:
Code:
unsigned int delay_count = 0;
unsigned int delay_constant = 0;
enum {PROGRAM_RUNNING, PROGRAM_DELAY} program_state = PROGRAM_RUNNING;
Have a function:
Code:
Code:
void delay(unsigned int count)
{
    if (!delay_constant) {
        delay_constant = count;
        delay_count = 0;
        program_state = PROGRAM_DELAY;
    }
    if (delay_count >= delay_constant) {
        delay_constant = delay_count = 0;
        program_state = PROGRAM_RUNNING;
    } else {
        delay_count += 26;
    }
}
This function should be called something like this: (in user_routines_fast.c)
Code:
Code:
 Getdata(&rxdata);   /* DO NOT DELETE, or you will be stuck here forever! */

         if (PROGRAM_RUNNING == program_state) {
             /* Add your own autonomous code here. */
         } else {
             delay(0);
         }

        Putdata(&txdata);   /* DO NOT DELETE, or you will get no PWM outputs! */
    }
Now, anytime you want to set a delay, simply have a call to delay(milliseconds) somewhere in the autonomous code.

Most of this might not compile.

.. A certain programmer on my team who is unnamed is tooo shy to post this himself! ;D

Last edited by kristen : 02-22-2004 at 07:03 PM.
  #15   Spotlight this post!  
Unread 02-22-2004, 07:50 PM
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
An inspired alumnus
AKA: Jamie Bliss
no team (previously 904 (D-cubed) and 1227 (Techno-Gremlins))
Team Role: Alumni
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Send a message via ICQ to Astronouth7303 Send a message via AIM to Astronouth7303 Send a message via MSN to Astronouth7303 Send a message via Yahoo to Astronouth7303
Re: sleep()

My thought was that after it's done waiting, you set a new value. And just do a putdata and a getdata in the loop.
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
How much sleep are you going to get??? ttedrow General Forum 34 01-11-2004 01:27 AM
Sing me a SONG! Biggs717 Chit-Chat 78 05-09-2003 06:59 AM
Sweet sweet sleep DavidAusTex General Forum 26 02-24-2003 11:38 PM
LET ME SLEEP!!!!! archiver 2001 2 06-24-2002 12:08 AM
Speaking of sleep and dew....see the pic... archiver 2001 3 06-23-2002 11:54 PM


All times are GMT -5. The time now is 12:57 AM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi