From d1f5bcb1ab6f94b6c85048144e3c30de8bfd9b6e Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Fri, 18 Jan 2019 11:57:30 +1100 Subject: [PATCH] APM_Control: stop taking reference to dataflash, use singleton --- libraries/APM_Control/AP_AutoTune.cpp | 14 +++++++------- libraries/APM_Control/AP_AutoTune.h | 4 +--- libraries/APM_Control/AP_PitchController.h | 4 ++-- libraries/APM_Control/AP_RollController.h | 4 ++-- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/libraries/APM_Control/AP_AutoTune.cpp b/libraries/APM_Control/AP_AutoTune.cpp index 45dce5d070..35efa3b3a5 100644 --- a/libraries/APM_Control/AP_AutoTune.cpp +++ b/libraries/APM_Control/AP_AutoTune.cpp @@ -67,13 +67,11 @@ extern const AP_HAL::HAL& hal; // constructor AP_AutoTune::AP_AutoTune(ATGains &_gains, ATType _type, - const AP_Vehicle::FixedWing &parms, - DataFlash_Class &_dataflash) : + const AP_Vehicle::FixedWing &parms) : running(false), current(_gains), type(_type), aparm(parms), - dataflash(_dataflash), saturated_surfaces(false) {} @@ -268,7 +266,8 @@ void AP_AutoTune::check_save(void) */ void AP_AutoTune::log_param_change(float v, const char *suffix) { - if (!dataflash.logging_started()) { + DataFlash_Class *dataflash = DataFlash_Class::instance(); + if (!dataflash->logging_started()) { return; } char key[AP_MAX_NAME_SIZE+1]; @@ -280,7 +279,7 @@ void AP_AutoTune::log_param_change(float v, const char *suffix) strncpy(&key[9], suffix, AP_MAX_NAME_SIZE-9); } key[AP_MAX_NAME_SIZE] = 0; - dataflash.Log_Write_Parameter(key, v); + dataflash->Log_Write_Parameter(key, v); } /* @@ -328,7 +327,8 @@ void AP_AutoTune::save_gains(const ATGains &v) void AP_AutoTune::write_log(float servo, float demanded, float achieved) { - if (!dataflash.logging_started()) { + DataFlash_Class *dataflash = DataFlash_Class::instance(); + if (!dataflash->logging_started()) { return; } @@ -342,5 +342,5 @@ void AP_AutoTune::write_log(float servo, float demanded, float achieved) achieved : achieved, P : current.P.get() }; - dataflash.WriteBlock(&pkt, sizeof(pkt)); + dataflash->WriteBlock(&pkt, sizeof(pkt)); } diff --git a/libraries/APM_Control/AP_AutoTune.h b/libraries/APM_Control/AP_AutoTune.h index 71f3e7cded..65e03f9f43 100644 --- a/libraries/APM_Control/AP_AutoTune.h +++ b/libraries/APM_Control/AP_AutoTune.h @@ -34,7 +34,7 @@ public: // constructor - AP_AutoTune(ATGains &_gains, ATType type, const AP_Vehicle::FixedWing &parms, DataFlash_Class &_dataflash); + AP_AutoTune(ATGains &_gains, ATType type, const AP_Vehicle::FixedWing &parms); // called when autotune mode is entered void start(void); @@ -59,8 +59,6 @@ private: const AP_Vehicle::FixedWing &aparm; - DataFlash_Class &dataflash; - // did we saturate surfaces? bool saturated_surfaces:1; diff --git a/libraries/APM_Control/AP_PitchController.h b/libraries/APM_Control/AP_PitchController.h index e3334416b3..d2da91c2c4 100644 --- a/libraries/APM_Control/AP_PitchController.h +++ b/libraries/APM_Control/AP_PitchController.h @@ -9,9 +9,9 @@ class AP_PitchController { public: - AP_PitchController(AP_AHRS &ahrs, const AP_Vehicle::FixedWing &parms, DataFlash_Class &_dataflash) + AP_PitchController(AP_AHRS &ahrs, const AP_Vehicle::FixedWing &parms) : aparm(parms) - , autotune(gains, AP_AutoTune::AUTOTUNE_PITCH, parms, _dataflash) + , autotune(gains, AP_AutoTune::AUTOTUNE_PITCH, parms) , _ahrs(ahrs) { AP_Param::setup_object_defaults(this, var_info); diff --git a/libraries/APM_Control/AP_RollController.h b/libraries/APM_Control/AP_RollController.h index 7b243be8e2..74a9c2ecf4 100644 --- a/libraries/APM_Control/AP_RollController.h +++ b/libraries/APM_Control/AP_RollController.h @@ -9,9 +9,9 @@ class AP_RollController { public: - AP_RollController(AP_AHRS &ahrs, const AP_Vehicle::FixedWing &parms, DataFlash_Class &_dataflash) + AP_RollController(AP_AHRS &ahrs, const AP_Vehicle::FixedWing &parms) : aparm(parms) - , autotune(gains, AP_AutoTune::AUTOTUNE_ROLL, parms, _dataflash) + , autotune(gains, AP_AutoTune::AUTOTUNE_ROLL, parms) , _ahrs(ahrs) { AP_Param::setup_object_defaults(this, var_info);