diff --git a/src/modules/land_detector/LandDetector.cpp b/src/modules/land_detector/LandDetector.cpp index b9fd50c9a40a..0d2da366921a 100644 --- a/src/modules/land_detector/LandDetector.cpp +++ b/src/modules/land_detector/LandDetector.cpp @@ -57,7 +57,7 @@ LandDetector::~LandDetector() void LandDetector::start() { - _update_params(true); + _update_params(); ScheduleOnInterval(LAND_DETECTOR_UPDATE_INTERVAL); } @@ -65,7 +65,10 @@ void LandDetector::Run() { perf_begin(_cycle_perf); - _update_params(); + if (_parameter_update_sub.updated()) { + _update_params(); + } + _actuator_armed_sub.update(&_actuator_armed); _update_topics(); _update_state(); @@ -131,16 +134,13 @@ void LandDetector::Run() } } -void LandDetector::_update_params(const bool force) +void LandDetector::_update_params() { - // check for parameter updates - if (_parameter_update_sub.updated() || force) { - // clear update - parameter_update_s param_update; - _parameter_update_sub.copy(¶m_update); + parameter_update_s param_update; + _parameter_update_sub.copy(¶m_update); - _update_total_flight_time(); - } + updateParams(); + _update_total_flight_time(); } void LandDetector::_update_state() diff --git a/src/modules/land_detector/LandDetector.h b/src/modules/land_detector/LandDetector.h index b4a84fcb7965..361538a5ab46 100644 --- a/src/modules/land_detector/LandDetector.h +++ b/src/modules/land_detector/LandDetector.h @@ -97,10 +97,9 @@ class LandDetector : public ModuleBase, ModuleParams, px4::Schedul protected: /** - * Updates parameters if changes have occurred or if forced. - * @var force Forces a parameter update. + * Updates parameters. */ - virtual void _update_params(const bool force = false); + virtual void _update_params(); /** * Updates subscribed uORB topics. @@ -148,6 +147,7 @@ class LandDetector : public ModuleBase, ModuleParams, px4::Schedul actuator_armed_s _actuator_armed{}; vehicle_acceleration_s _vehicle_acceleration{}; + vehicle_land_detected_s _land_detected = { .timestamp = 0, .alt_max = -1.0f, @@ -156,14 +156,11 @@ class LandDetector : public ModuleBase, ModuleParams, px4::Schedul .maybe_landed = true, .landed = true, }; + vehicle_local_position_s _vehicle_local_position{}; uORB::Publication _vehicle_land_detected_pub{ORB_ID(vehicle_land_detected)}; - uORB::Subscription _actuator_armed_sub{ORB_ID(actuator_armed)}; - uORB::Subscription _vehicle_acceleration_sub{ORB_ID(vehicle_acceleration)}; - uORB::Subscription _vehicle_local_position_sub{ORB_ID(vehicle_local_position)}; - private: void Run() override; @@ -179,7 +176,10 @@ class LandDetector : public ModuleBase, ModuleParams, px4::Schedul perf_counter_t _cycle_perf{perf_alloc(PC_ELAPSED, "land_detector_cycle")}; + uORB::Subscription _actuator_armed_sub{ORB_ID(actuator_armed)}; uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)}; + uORB::Subscription _vehicle_acceleration_sub{ORB_ID(vehicle_acceleration)}; + uORB::Subscription _vehicle_local_position_sub{ORB_ID(vehicle_local_position)}; DEFINE_PARAMETERS_CUSTOM_PARENT( ModuleParams, diff --git a/src/modules/land_detector/MulticopterLandDetector.cpp b/src/modules/land_detector/MulticopterLandDetector.cpp index 72c3dffc7cb1..5eaf2f0fff94 100644 --- a/src/modules/land_detector/MulticopterLandDetector.cpp +++ b/src/modules/land_detector/MulticopterLandDetector.cpp @@ -95,9 +95,9 @@ void MulticopterLandDetector::_update_topics() _vehicle_local_position_setpoint_sub.update(&_vehicle_local_position_setpoint); } -void MulticopterLandDetector::_update_params(const bool force) +void MulticopterLandDetector::_update_params() { - LandDetector::_update_params(force); + LandDetector::_update_params(); _freefall_hysteresis.set_hysteresis_time_from(false, (hrt_abstime)(1e6f * _param_lndmc_ffall_ttri.get())); diff --git a/src/modules/land_detector/MulticopterLandDetector.h b/src/modules/land_detector/MulticopterLandDetector.h index 4db1a7e43798..8746acbd697b 100644 --- a/src/modules/land_detector/MulticopterLandDetector.h +++ b/src/modules/land_detector/MulticopterLandDetector.h @@ -62,7 +62,7 @@ class MulticopterLandDetector : public LandDetector MulticopterLandDetector(); protected: - void _update_params(const bool force = false) override; + void _update_params() override; void _update_topics() override; bool _get_landed_state() override;