From 73d23742ea5c297f262c0e03caec61ee482977b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Thu, 10 Aug 2017 10:40:57 +0200 Subject: [PATCH] vmount: rate-limit the update of the outputs This avoids a busy-loop if the input is listening for vehicle commands and the output publishes vehicle commands. --- src/drivers/vmount/vmount.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/drivers/vmount/vmount.cpp b/src/drivers/vmount/vmount.cpp index 3496e974fa..b9734ed867 100644 --- a/src/drivers/vmount/vmount.cpp +++ b/src/drivers/vmount/vmount.cpp @@ -222,6 +222,7 @@ static int vmount_thread_main(int argc, char *argv[]) g_thread_data = &thread_data; int last_active = 0; + hrt_abstime last_output_update = 0; while (!thread_should_exit) { @@ -342,16 +343,21 @@ static int vmount_thread_main(int argc, char *argv[]) } } - //update output - int ret = thread_data.output_obj->update(control_data); + hrt_abstime now = hrt_absolute_time(); + if (now - last_output_update > 10000) { // rate-limit the update of outputs + last_output_update = now; - if (ret) { - PX4_ERR("failed to write output (%i)", ret); - break; + //update output + int ret = thread_data.output_obj->update(control_data); + + if (ret) { + PX4_ERR("failed to write output (%i)", ret); + break; + } + + thread_data.output_obj->publish(); } - thread_data.output_obj->publish(); - } else { //wait for parameter changes. We still need to wake up regularily to check for thread exit requests usleep(1e6);