Skip to content

MAVLink: speed up mavlink processing when disarmed #26024

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 11 additions & 1 deletion libraries/AP_HAL_ChibiOS/Scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,21 @@ void Scheduler::boost_end(void)
*/
void Scheduler::delay_microseconds_boost(uint16_t usec)
{
if (!_priority_boosted && in_main_thread()) {
const bool main_thread = in_main_thread();
if (!_priority_boosted && main_thread) {
set_high_priority();
_priority_boosted = true;
_called_boost = true;
}
if (main_thread && !hal.util->get_soft_armed() && usec >= 500) {
const uint32_t start_us = AP_HAL::micros();
call_delay_cb();
Copy link
Member

Choose a reason for hiding this comment

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

I guess the assumption is that this call takes less than 500us? If it does then we spend the time doing something useful rather than sleeping. Why not do the same when armed? Just because we might overrun that 500us?

const uint32_t dt_us = AP_HAL::micros() - start_us;
if (dt_us >= usec) {
return;
}
usec -= dt_us;
}
delay_microseconds(usec); //Suspends Thread for desired microseconds
}

Expand Down
17 changes: 17 additions & 0 deletions libraries/AP_HAL_SITL/Scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,23 @@ void Scheduler::delay_microseconds(uint16_t usec)
} while (true);
}

/*
delay from AP_InertialSensor wait for IMU sample
*/
void Scheduler::delay_microseconds_boost(uint16_t usec)
{
if (in_main_thread() && !hal.util->get_soft_armed() && usec >= 500) {
const uint32_t start_us = AP_HAL::micros();
call_delay_cb();
const uint32_t dt_us = AP_HAL::micros() - start_us;
if (dt_us >= usec) {
return;
}
usec -= dt_us;
}
delay_microseconds(usec);
}

void Scheduler::delay(uint16_t ms)
{
uint32_t start = AP_HAL::millis();
Expand Down
1 change: 1 addition & 0 deletions libraries/AP_HAL_SITL/Scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class HALSITL::Scheduler : public AP_HAL::Scheduler {
void init() override;
void delay(uint16_t ms) override;
void delay_microseconds(uint16_t us) override;
void delay_microseconds_boost(uint16_t us) override;

void register_timer_process(AP_HAL::MemberProc) override;
void register_io_process(AP_HAL::MemberProc) override;
Expand Down
12 changes: 8 additions & 4 deletions libraries/AP_Vehicle/AP_Vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ void AP_Vehicle::scheduler_delay_callback()
return;
#endif

static uint32_t last_1hz, last_50hz, last_5s;
static uint32_t last_1hz, last_mav_ms, last_notify_ms, last_5s;

#if HAL_LOGGING_ENABLED
AP_Logger &logger = AP::logger();
Expand All @@ -611,15 +611,19 @@ void AP_Vehicle::scheduler_delay_callback()
GCS_SEND_MESSAGE(MSG_HEARTBEAT);
GCS_SEND_MESSAGE(MSG_SYS_STATUS);
}
if (tnow - last_50hz > 20) {
last_50hz = tnow;
const uint32_t mav_period_ms = hal.util->get_soft_armed() ? 20 : 1;
if (tnow - last_mav_ms > mav_period_ms) {
last_mav_ms = tnow;
#if HAL_GCS_ENABLED
gcs().update_receive();
gcs().update_send();
#endif
}
if (tnow - last_notify_ms > 20) {
last_notify_ms = tnow;
_singleton->notify.update();
}
if (tnow - last_5s > 5000) {
if (tnow - last_5s > 5000 && !hal.scheduler->is_system_initialized()) {
last_5s = tnow;
if (AP_BoardConfig::in_config_error()) {
GCS_SEND_TEXT(MAV_SEVERITY_CRITICAL, "Config Error: fix problem then reboot");
Expand Down