Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multicopter land detector: do not update parameters every cycle #13212

Merged
merged 4 commits into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 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,12 @@ 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();
}
_update_total_flight_time();
julianoes marked this conversation as resolved.
Show resolved Hide resolved
}

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