fix multicopter land detector: do not update parameters every cycle (#13212)

And add updateParams() call in LandDetector::_update_params().
This commit is contained in:
Mark Sauder
2019-10-18 01:25:41 -06:00
committed by Beat Küng
parent cefa7ec5dc
commit e9c9fb8239
4 changed files with 20 additions and 20 deletions
+10 -10
View File
@@ -57,7 +57,7 @@ LandDetector::~LandDetector()
void LandDetector::start() void LandDetector::start()
{ {
_update_params(true); _update_params();
ScheduleOnInterval(LAND_DETECTOR_UPDATE_INTERVAL); ScheduleOnInterval(LAND_DETECTOR_UPDATE_INTERVAL);
} }
@@ -65,7 +65,10 @@ void LandDetector::Run()
{ {
perf_begin(_cycle_perf); perf_begin(_cycle_perf);
_update_params(); if (_parameter_update_sub.updated()) {
_update_params();
}
_actuator_armed_sub.update(&_actuator_armed); _actuator_armed_sub.update(&_actuator_armed);
_update_topics(); _update_topics();
_update_state(); _update_state();
@@ -131,16 +134,13 @@ void LandDetector::Run()
} }
} }
void LandDetector::_update_params(const bool force) void LandDetector::_update_params()
{ {
// check for parameter updates parameter_update_s param_update;
if (_parameter_update_sub.updated() || force) { _parameter_update_sub.copy(&param_update);
// clear update
parameter_update_s param_update;
_parameter_update_sub.copy(&param_update);
_update_total_flight_time(); updateParams();
} _update_total_flight_time();
} }
void LandDetector::_update_state() void LandDetector::_update_state()
+7 -7
View File
@@ -97,10 +97,9 @@ public:
protected: protected:
/** /**
* Updates parameters if changes have occurred or if forced. * Updates parameters.
* @var force Forces a parameter update.
*/ */
virtual void _update_params(const bool force = false); virtual void _update_params();
/** /**
* Updates subscribed uORB topics. * Updates subscribed uORB topics.
@@ -148,6 +147,7 @@ protected:
actuator_armed_s _actuator_armed{}; actuator_armed_s _actuator_armed{};
vehicle_acceleration_s _vehicle_acceleration{}; vehicle_acceleration_s _vehicle_acceleration{};
vehicle_land_detected_s _land_detected = { vehicle_land_detected_s _land_detected = {
.timestamp = 0, .timestamp = 0,
.alt_max = -1.0f, .alt_max = -1.0f,
@@ -156,14 +156,11 @@ protected:
.maybe_landed = true, .maybe_landed = true,
.landed = true, .landed = true,
}; };
vehicle_local_position_s _vehicle_local_position{}; vehicle_local_position_s _vehicle_local_position{};
uORB::Publication<vehicle_land_detected_s> _vehicle_land_detected_pub{ORB_ID(vehicle_land_detected)}; uORB::Publication<vehicle_land_detected_s> _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: private:
void Run() override; void Run() override;
@@ -179,7 +176,10 @@ private:
perf_counter_t _cycle_perf{perf_alloc(PC_ELAPSED, "land_detector_cycle")}; 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 _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( DEFINE_PARAMETERS_CUSTOM_PARENT(
ModuleParams, ModuleParams,
@@ -95,9 +95,9 @@ void MulticopterLandDetector::_update_topics()
_vehicle_local_position_setpoint_sub.update(&_vehicle_local_position_setpoint); _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())); _freefall_hysteresis.set_hysteresis_time_from(false, (hrt_abstime)(1e6f * _param_lndmc_ffall_ttri.get()));
@@ -62,7 +62,7 @@ public:
MulticopterLandDetector(); MulticopterLandDetector();
protected: protected:
void _update_params(const bool force = false) override; void _update_params() override;
void _update_topics() override; void _update_topics() override;
bool _get_landed_state() override; bool _get_landed_state() override;