Skip to content

Commit

Permalink
vtol_att_control: limit excessive scheduling
Browse files Browse the repository at this point in the history
  • Loading branch information
dagar committed Jul 20, 2020
1 parent 2adc23f commit 3eee3f4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/modules/vtol_att_control/vtol_att_control_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include <uORB/Publication.hpp>

using namespace matrix;
using namespace time_literals;

VtolAttitudeControl::VtolAttitudeControl() :
WorkItem(MODULE_NAME, px4::wq_configurations::rate_ctrl),
Expand Down Expand Up @@ -342,6 +343,15 @@ VtolAttitudeControl::Run()
return;
}

const hrt_abstime now = hrt_absolute_time();

// prevent excessive scheduling (> 500 Hz)
if (now - _last_run_timestamp < 2_ms) {
return;
}

_last_run_timestamp = now;

if (!_initialized) {
parameters_update(); // initialize parameter cache

Expand Down
2 changes: 2 additions & 0 deletions src/modules/vtol_att_control/vtol_att_control_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ class VtolAttitudeControl : public ModuleBase<VtolAttitudeControl>, public px4::
param_t mpc_land_alt2;
} _params_handles{};

hrt_abstime _last_run_timestamp{0};

/* for multicopters it is usual to have a non-zero idle speed of the engines
* for fixed wings we want to have an idle speed of zero since we do not want
* to waste energy when gliding. */
Expand Down

0 comments on commit 3eee3f4

Please sign in to comment.