From 79b8b150530c23980683456a485d15251e1ffe75 Mon Sep 17 00:00:00 2001 From: Gustavo Jose de Sousa Date: Tue, 28 Jul 2015 11:13:23 -0300 Subject: [PATCH] ArduCopter: use designated initializers for tasks structs Makes code less prone to break build and semantics (e.g., when a new field is added). --- ArduCopter/ArduCopter.cpp | 83 ++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/ArduCopter/ArduCopter.cpp b/ArduCopter/ArduCopter.cpp index 2637ac7c94..a616f184a5 100644 --- a/ArduCopter/ArduCopter.cpp +++ b/ArduCopter/ArduCopter.cpp @@ -75,7 +75,10 @@ #include "Copter.h" -#define SCHED_TASK(func) FUNCTOR_BIND(&copter, &Copter::func, void) +#define SCHED_TASK(func, _interval_ticks, _max_time_micros) {\ + .function = FUNCTOR_BIND(&copter, &Copter::func, void),\ + .interval_ticks = _interval_ticks,\ + .max_time_micros = _max_time_micros} /* scheduler table for fast CPUs - all regular tasks apart from the fast_loop() @@ -94,64 +97,64 @@ */ const AP_Scheduler::Task Copter::scheduler_tasks[] PROGMEM = { - { SCHED_TASK(rc_loop), 4, 130 }, - { SCHED_TASK(throttle_loop), 8, 75 }, - { SCHED_TASK(update_GPS), 8, 200 }, + SCHED_TASK(rc_loop, 4, 130), + SCHED_TASK(throttle_loop, 8, 75), + SCHED_TASK(update_GPS, 8, 200), #if OPTFLOW == ENABLED - { SCHED_TASK(update_optical_flow), 2, 160 }, + SCHED_TASK(update_optical_flow, 2, 160), #endif - { SCHED_TASK(update_batt_compass), 40, 120 }, - { SCHED_TASK(read_aux_switches), 40, 50 }, - { SCHED_TASK(arm_motors_check), 40, 50 }, - { SCHED_TASK(auto_trim), 40, 75 }, - { SCHED_TASK(update_altitude), 40, 140 }, - { SCHED_TASK(run_nav_updates), 8, 100 }, - { SCHED_TASK(update_thr_average), 4, 90 }, - { SCHED_TASK(three_hz_loop), 133, 75 }, - { SCHED_TASK(compass_accumulate), 8, 100 }, - { SCHED_TASK(barometer_accumulate), 8, 90 }, + SCHED_TASK(update_batt_compass, 40, 120), + SCHED_TASK(read_aux_switches, 40, 50), + SCHED_TASK(arm_motors_check, 40, 50), + SCHED_TASK(auto_trim, 40, 75), + SCHED_TASK(update_altitude, 40, 140), + SCHED_TASK(run_nav_updates, 8, 100), + SCHED_TASK(update_thr_average, 4, 90), + SCHED_TASK(three_hz_loop, 133, 75), + SCHED_TASK(compass_accumulate, 8, 100), + SCHED_TASK(barometer_accumulate, 8, 90), #if PRECISION_LANDING == ENABLED - { SCHED_TASK(update_precland), 8, 50 }, + SCHED_TASK(update_precland, 8, 50), #endif #if FRAME_CONFIG == HELI_FRAME - { SCHED_TASK(check_dynamic_flight), 8, 75 }, + SCHED_TASK(check_dynamic_flight, 8, 75), #endif - { SCHED_TASK(update_notify), 8, 90 }, - { SCHED_TASK(one_hz_loop), 400, 100 }, - { SCHED_TASK(ekf_check), 40, 75 }, - { SCHED_TASK(landinggear_update), 40, 75 }, - { SCHED_TASK(lost_vehicle_check), 40, 50 }, - { SCHED_TASK(gcs_check_input), 1, 180 }, - { SCHED_TASK(gcs_send_heartbeat), 400, 110 }, - { SCHED_TASK(gcs_send_deferred), 8, 550 }, - { SCHED_TASK(gcs_data_stream_send), 8, 550 }, - { SCHED_TASK(update_mount), 8, 75 }, - { SCHED_TASK(ten_hz_logging_loop), 40, 350 }, - { SCHED_TASK(fifty_hz_logging_loop), 8, 110 }, - { SCHED_TASK(full_rate_logging_loop),1, 100 }, - { SCHED_TASK(perf_update), 4000, 75 }, - { SCHED_TASK(read_receiver_rssi), 40, 75 }, - { SCHED_TASK(rpm_update), 40, 200 }, + SCHED_TASK(update_notify, 8, 90), + SCHED_TASK(one_hz_loop, 400, 100), + SCHED_TASK(ekf_check, 40, 75), + SCHED_TASK(landinggear_update, 40, 75), + SCHED_TASK(lost_vehicle_check, 40, 50), + SCHED_TASK(gcs_check_input, 1, 180), + SCHED_TASK(gcs_send_heartbeat, 400, 110), + SCHED_TASK(gcs_send_deferred, 8, 550), + SCHED_TASK(gcs_data_stream_send, 8, 550), + SCHED_TASK(update_mount, 8, 75), + SCHED_TASK(ten_hz_logging_loop, 40, 350), + SCHED_TASK(fifty_hz_logging_loop, 8, 110), + SCHED_TASK(full_rate_logging_loop, 1, 100), + SCHED_TASK(perf_update, 4000, 75), + SCHED_TASK(read_receiver_rssi, 40, 75), + SCHED_TASK(rpm_update, 40, 200), #if FRSKY_TELEM_ENABLED == ENABLED - { SCHED_TASK(frsky_telemetry_send), 80, 75 }, + SCHED_TASK(frsky_telemetry_send, 80, 75), #endif #if EPM_ENABLED == ENABLED - { SCHED_TASK(epm_update), 40, 75 }, + SCHED_TASK(epm_update, 40, 75), #endif #ifdef USERHOOK_FASTLOOP - { SCHED_TASK(userhook_FastLoop), 4, 75 }, + SCHED_TASK(userhook_FastLoop, 4, 75), #endif #ifdef USERHOOK_50HZLOOP - { SCHED_TASK(userhook_50Hz), 8, 75 }, + SCHED_TASK(userhook_50Hz, 8, 75), #endif #ifdef USERHOOK_MEDIUMLOOP - { SCHED_TASK(userhook_MediumLoop), 40, 75 }, + SCHED_TASK(userhook_MediumLoop, 40, 75), #endif #ifdef USERHOOK_SLOWLOOP - { SCHED_TASK(userhook_SlowLoop), 120, 75 }, + SCHED_TASK(userhook_SlowLoop, 120, 75), #endif #ifdef USERHOOK_SUPERSLOWLOOP - { SCHED_TASK(userhook_SuperSlowLoop),400, 75 }, + SCHED_TASK(userhook_SuperSlowLoop, 400, 75), #endif };