|
|
@ -899,7 +899,7 @@ static byte gps_watchdog; |
|
|
|
// Time in microseconds of main control loop |
|
|
|
// Time in microseconds of main control loop |
|
|
|
static uint32_t fast_loopTimer; |
|
|
|
static uint32_t fast_loopTimer; |
|
|
|
// Time in microseconds of 50hz control loop |
|
|
|
// Time in microseconds of 50hz control loop |
|
|
|
static uint32_t fiftyhz_loopTimer; |
|
|
|
static uint32_t fiftyhz_loopTimer = 0; |
|
|
|
// Counters for branching from 10 hz control loop |
|
|
|
// Counters for branching from 10 hz control loop |
|
|
|
static byte medium_loopCounter; |
|
|
|
static byte medium_loopCounter; |
|
|
|
// Counters for branching from 3 1/3hz control loop |
|
|
|
// Counters for branching from 3 1/3hz control loop |
|
|
@ -981,11 +981,12 @@ void setup() { |
|
|
|
void loop() |
|
|
|
void loop() |
|
|
|
{ |
|
|
|
{ |
|
|
|
uint32_t timer = micros(); |
|
|
|
uint32_t timer = micros(); |
|
|
|
bool spare_time = true; |
|
|
|
static bool run_50hz_loop = false; |
|
|
|
|
|
|
|
|
|
|
|
// We want this to execute fast |
|
|
|
// We want this to execute fast |
|
|
|
// ---------------------------- |
|
|
|
// ---------------------------- |
|
|
|
if ((timer - fast_loopTimer) >= 10000 && imu.new_data_available()) { |
|
|
|
if( imu.num_samples_available() >= NUM_IMU_SAMPLES_FOR_100HZ ) { |
|
|
|
|
|
|
|
|
|
|
|
#if DEBUG_FAST_LOOP == ENABLED |
|
|
|
#if DEBUG_FAST_LOOP == ENABLED |
|
|
|
Log_Write_Data(50, (int32_t)(timer - fast_loopTimer)); |
|
|
|
Log_Write_Data(50, (int32_t)(timer - fast_loopTimer)); |
|
|
|
#endif |
|
|
|
#endif |
|
|
@ -996,71 +997,69 @@ void loop() |
|
|
|
|
|
|
|
|
|
|
|
// Execute the fast loop |
|
|
|
// Execute the fast loop |
|
|
|
// --------------------- |
|
|
|
// --------------------- |
|
|
|
fast_loop(); |
|
|
|
fast_loop();//// |
|
|
|
spare_time = false; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
#ifdef DESKTOP_BUILD |
|
|
|
|
|
|
|
usleep(1000); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// port manipulation for external timing of main loops |
|
|
|
// run the 50hz loop 1/2 the time |
|
|
|
//PORTK &= B11101111; |
|
|
|
run_50hz_loop = !run_50hz_loop; |
|
|
|
|
|
|
|
|
|
|
|
if ((timer - fiftyhz_loopTimer) >= 20000) { |
|
|
|
if( run_50hz_loop ) { |
|
|
|
|
|
|
|
|
|
|
|
#if DEBUG_MED_LOOP == ENABLED |
|
|
|
#if DEBUG_MED_LOOP == ENABLED |
|
|
|
Log_Write_Data(51, (int32_t)(timer - fiftyhz_loopTimer)); |
|
|
|
Log_Write_Data(51, (int32_t)(timer - fiftyhz_loopTimer)); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
// store the micros for the 50 hz timer |
|
|
|
// store the micros for the 50 hz timer |
|
|
|
fiftyhz_loopTimer = timer; |
|
|
|
fiftyhz_loopTimer = timer; |
|
|
|
|
|
|
|
|
|
|
|
// port manipulation for external timing of main loops |
|
|
|
// port manipulation for external timing of main loops |
|
|
|
//PORTK |= B01000000; |
|
|
|
//PORTK |= B01000000; |
|
|
|
|
|
|
|
|
|
|
|
// reads all of the necessary trig functions for cameras, throttle, etc. |
|
|
|
// reads all of the necessary trig functions for cameras, throttle, etc. |
|
|
|
// -------------------------------------------------------------------- |
|
|
|
// -------------------------------------------------------------------- |
|
|
|
update_trig(); |
|
|
|
update_trig(); |
|
|
|
|
|
|
|
|
|
|
|
// Rotate the Nav_lon and nav_lat vectors based on Yaw |
|
|
|
// Rotate the Nav_lon and nav_lat vectors based on Yaw |
|
|
|
// --------------------------------------------------- |
|
|
|
// --------------------------------------------------- |
|
|
|
calc_loiter_pitch_roll(); |
|
|
|
calc_loiter_pitch_roll(); |
|
|
|
|
|
|
|
|
|
|
|
// check for new GPS messages |
|
|
|
// check for new GPS messages |
|
|
|
// -------------------------- |
|
|
|
// -------------------------- |
|
|
|
update_GPS(); |
|
|
|
update_GPS(); |
|
|
|
|
|
|
|
|
|
|
|
// perform 10hz tasks |
|
|
|
// perform 10hz tasks |
|
|
|
// ------------------ |
|
|
|
// ------------------ |
|
|
|
medium_loop(); |
|
|
|
medium_loop(); |
|
|
|
|
|
|
|
|
|
|
|
// Stuff to run at full 50hz, but after the med loops |
|
|
|
// Stuff to run at full 50hz, but after the med loops |
|
|
|
// -------------------------------------------------- |
|
|
|
// -------------------------------------------------- |
|
|
|
fifty_hz_loop(); |
|
|
|
fifty_hz_loop(); |
|
|
|
|
|
|
|
|
|
|
|
counter_one_herz++; |
|
|
|
counter_one_herz++; |
|
|
|
|
|
|
|
|
|
|
|
// trgger our 1 hz loop |
|
|
|
// trgger our 1 hz loop |
|
|
|
if(counter_one_herz >= 50) { |
|
|
|
if(counter_one_herz >= 50) { |
|
|
|
super_slow_loop(); |
|
|
|
super_slow_loop(); |
|
|
|
counter_one_herz = 0; |
|
|
|
counter_one_herz = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
perf_mon_counter++; |
|
|
|
perf_mon_counter++; |
|
|
|
if (perf_mon_counter > 600 ) { |
|
|
|
if (perf_mon_counter > 600 ) { |
|
|
|
if (g.log_bitmask & MASK_LOG_PM) |
|
|
|
if (g.log_bitmask & MASK_LOG_PM) |
|
|
|
Log_Write_Performance(); |
|
|
|
Log_Write_Performance(); |
|
|
|
|
|
|
|
|
|
|
|
gps_fix_count = 0; |
|
|
|
gps_fix_count = 0; |
|
|
|
perf_mon_counter = 0; |
|
|
|
perf_mon_counter = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//PORTK &= B10111111; |
|
|
|
} |
|
|
|
} |
|
|
|
//PORTK &= B10111111; |
|
|
|
} else { |
|
|
|
spare_time = false; |
|
|
|
#ifdef DESKTOP_BUILD |
|
|
|
|
|
|
|
usleep(1000); |
|
|
|
|
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (spare_time && g.compass_enabled) { |
|
|
|
// port manipulation for external timing of main loops |
|
|
|
compass.accumulate(); |
|
|
|
//PORTK &= B11101111; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// PORTK |= B01000000; |
|
|
|
// PORTK |= B01000000; |
|
|
|
// PORTK &= B10111111; |
|
|
|
// PORTK &= B10111111; |
|
|
|