Copter: use ins.wait_for_sample() for main loop

this takes advantage of the INS specific method to wait for a sample
This commit is contained in:
Andrew Tridgell 2013-10-08 17:30:43 +11:00
parent 8e5d1430da
commit 4b68dd48f7
2 changed files with 26 additions and 27 deletions

View File

@ -953,40 +953,37 @@ static void perf_update(void)
void loop() void loop()
{ {
// wait for an INS sample
if (!ins.wait_for_sample(1000)) {
Log_Write_Error(ERROR_SUBSYSTEM_MAIN, ERROR_CODE_INS_DELAY);
return;
}
uint32_t timer = micros(); uint32_t timer = micros();
// We want this to execute fast // check loop time
// ---------------------------- perf_info_check_loop_time(timer - fast_loopTimer);
if (ins.sample_available()) {
// check loop time // used by PI Loops
perf_info_check_loop_time(timer - fast_loopTimer); G_Dt = (float)(timer - fast_loopTimer) / 1000000.f;
fast_loopTimer = timer;
G_Dt = (float)(timer - fast_loopTimer) / 1000000.f; // used by PI Loops // for mainloop failure monitoring
fast_loopTimer = timer; mainLoop_count++;
// for mainloop failure monitoring // Execute the fast loop
mainLoop_count++; // ---------------------
fast_loop();
// Execute the fast loop // tell the scheduler one tick has passed
// --------------------- scheduler.tick();
fast_loop();
// tell the scheduler one tick has passed // run all the tasks that are due to run. Note that we only
scheduler.tick(); // have to call this once per loop, as the tasks are scheduled
// in multiples of the main loop tick. So if they don't run on
// run all the tasks that are due to run. Note that we only // the first call to the scheduler they won't run on a later
// have to call this once per loop, as the tasks are scheduled // call until scheduler.tick() is called again
// in multiples of the main loop tick. So if they don't run on uint32_t time_available = (timer + 10000) - micros();
// the first call to the scheduler they won't run on a later scheduler.run(time_available - 500);
// call until scheduler.tick() is called again
uint32_t time_available = (timer + 10000) - micros();
scheduler.run(time_available - 500);
}
if ((timer - fast_loopTimer) < 8500) {
// we have plenty of time - be friendly to multi-tasking OSes
hal.scheduler->delay(1);
}
} }

View File

@ -449,6 +449,8 @@ enum ap_message {
#define ERROR_CODE_COMPASS_FAILED_TO_READ 2 #define ERROR_CODE_COMPASS_FAILED_TO_READ 2
// subsystem specific error codes -- gps // subsystem specific error codes -- gps
#define ERROR_CODE_GPS_GLITCH 2 #define ERROR_CODE_GPS_GLITCH 2
// subsystem specific error codes -- main
#define ERROR_CODE_INS_DELAY 1