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

vtol_att_control: limit excessive scheduling #15383

Merged
merged 1 commit into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 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,19 @@ VtolAttitudeControl::Run()
return;
}

const hrt_abstime now = hrt_absolute_time();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not put it inside?

#if !defined(ENABLE_LOCKSTEP_SCHEDULER)

	const hrt_abstime now = hrt_absolute_time();

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

	_last_run_timestamp = now;

#endif // !ENABLE_LOCKSTEP_SCHEDULER

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No real reason, I thought the timestamp might be useful later and didn't want to put more ifdefs in the header.


#if !defined(ENABLE_LOCKSTEP_SCHEDULER)

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

#endif // !ENABLE_LOCKSTEP_SCHEDULER

_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