Skip to content

Commit

Permalink
fix multicopter land detector: do not update parameters every cycle (#…
Browse files Browse the repository at this point in the history
…13212)

And add updateParams() call in LandDetector::_update_params().
  • Loading branch information
mcsauder authored and bkueng committed Oct 18, 2019
1 parent cefa7ec commit e9c9fb8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
20 changes: 10 additions & 10 deletions src/modules/land_detector/LandDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,18 @@ LandDetector::~LandDetector()

void LandDetector::start()
{
_update_params(true);
_update_params();
ScheduleOnInterval(LAND_DETECTOR_UPDATE_INTERVAL);
}

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();
Expand Down Expand Up @@ -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(&param_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()
Expand Down
14 changes: 7 additions & 7 deletions src/modules/land_detector/LandDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,9 @@ class LandDetector : public ModuleBase<LandDetector>, 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.
Expand Down Expand Up @@ -148,6 +147,7 @@ class LandDetector : public ModuleBase<LandDetector>, 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,
Expand All @@ -156,14 +156,11 @@ class LandDetector : public ModuleBase<LandDetector>, ModuleParams, px4::Schedul
.maybe_landed = true,
.landed = true,
};

vehicle_local_position_s _vehicle_local_position{};

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:

void Run() override;
Expand All @@ -179,7 +176,10 @@ class LandDetector : public ModuleBase<LandDetector>, 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,
Expand Down
4 changes: 2 additions & 2 deletions src/modules/land_detector/MulticopterLandDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));

Expand Down
2 changes: 1 addition & 1 deletion src/modules/land_detector/MulticopterLandDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e9c9fb8

Please sign in to comment.