Skip to content

Commit

Permalink
Copter: added main_loop_ready() function
Browse files Browse the repository at this point in the history
this tells us when the main loop is ready to run. MAVLink won't send a
message if the main loop could run.
  • Loading branch information
Andrew Tridgell committed Jan 7, 2013
1 parent b39166b commit d952ccf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
15 changes: 12 additions & 3 deletions ArduCopter/ArduCopter.pde
Original file line number Diff line number Diff line change
Expand Up @@ -927,15 +927,24 @@ void setup() {
init_ardupilot();
}

/*
return true if the main loop is ready to run. This is used by
potentially expensive functions that are not timing critical, to
defer the expensive processing until after the main loop has run.
*/
static bool main_loop_ready(void)
{
return ins.num_samples_available() >= 2;
}


void loop()
{
uint32_t timer = micros();
uint16_t num_samples;

// We want this to execute fast
// ----------------------------
num_samples = ins.num_samples_available();
if (num_samples >= 2) {
if (main_loop_ready()) {

#if DEBUG_FAST_LOOP == ENABLED
Log_Write_Data(DATA_FAST_LOOP, (int32_t)(timer - fast_loopTimer));
Expand Down
7 changes: 7 additions & 0 deletions ArduCopter/GCS_Mavlink.pde
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,13 @@ static bool mavlink_try_send_message(mavlink_channel_t chan, enum ap_message id,
return false;
}

// if the ins has new data for the main loop then don't send a
// mavlink message. We want to prioritise the main flight control
// loop over communications
if (main_loop_ready()) {
return false;
}

switch(id) {
case MSG_HEARTBEAT:
CHECK_PAYLOAD_SIZE(HEARTBEAT);
Expand Down

0 comments on commit d952ccf

Please sign in to comment.