![]() |
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?
|
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? |
Re: sleep()
what about a pause function? Same results?
|
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) |
Re: sleep()
I was just informed it will be sleep(1); will that 1 millisecond make a difference and cause those problems?
|
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 |
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);.
|
Re: sleep()
Quote:
|
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. |
Re: sleep()
Quote:
|
Re: sleep()
Quote:
Code:
for(initiazation; test; increment)Code:
// Somewhere at the topNote 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. |
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.
|
Re: sleep()
Quote:
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. |
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;Code: Code:
void delay(unsigned int count)Code: Code:
Getdata(&rxdata); /* DO NOT DELETE, or you will be stuck here forever! */Most of this might not compile. .. A certain programmer on my team who is unnamed is tooo shy to post this himself! ;D |
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.
|
| All times are GMT -5. The time now is 20:50. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi