Skip to content

Commit

Permalink
AP_Soaring: Rate limit the NVF publishers to 4Hz
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Friedman <[email protected]>
  • Loading branch information
Ryanf55 authored and peterbarker committed Jan 28, 2025
1 parent 864491d commit 3a5a2f6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
17 changes: 13 additions & 4 deletions libraries/AP_Soaring/AP_Soaring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include <GCS_MAVLink/GCS.h>
#include <stdint.h>

#if HAL_SOARING_NVF_EKF_ENABLED
static constexpr uint32_t NVF_PUBLISHER_DELAY_MS = 250;
#endif // HAL_SOARING_NVF_EKF_ENABLED

// ArduSoar parameters
const AP_Param::GroupInfo SoaringController::var_info[] = {
// @Param: ENABLE
Expand Down Expand Up @@ -370,10 +374,15 @@ void SoaringController::update_thermalling()
(double)wind_drift.y,
(double)_thermalability);
#if HAL_SOARING_NVF_EKF_ENABLED
gcs().send_named_float("SOAREKFX0", (float)_ekf.X[0]);
gcs().send_named_float("SOAREKFX1", (float)_ekf.X[1]);
gcs().send_named_float("SOAREKFX2", (float)_ekf.X[2]);
gcs().send_named_float("SOAREKFX3", (float)_ekf.X[3]);
auto const now_ms = AP_HAL::millis();
if (now_ms - _prev_nvf_pub_time_ms > NVF_PUBLISHER_DELAY_MS) {
gcs().send_named_float("SOAREKFX0", (float)_ekf.X[0]);
gcs().send_named_float("SOAREKFX1", (float)_ekf.X[1]);
gcs().send_named_float("SOAREKFX2", (float)_ekf.X[2]);
gcs().send_named_float("SOAREKFX3", (float)_ekf.X[3]);
_prev_nvf_pub_time_ms = now_ms;
}

#endif // HAL_SOARING_NVF_EKF_ENABLED
#endif
}
Expand Down
5 changes: 5 additions & 0 deletions libraries/AP_Soaring/AP_Soaring.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ class SoaringController {
// store time of last update
uint64_t _prev_update_time;

// store time of last NVT publish
#if HAL_SOARING_NVF_EKF_ENABLED
uint32_t _prev_nvf_pub_time_ms;
#endif // #if HAL_SOARING_NVF_EKF_ENABLED

bool _throttle_suppressed;

float McCready(float alt);
Expand Down

0 comments on commit 3a5a2f6

Please sign in to comment.