From 3fc3039cb63c67a9ee2b50b4bd0f457e1ee448a4 Mon Sep 17 00:00:00 2001 From: Matthias Grob Date: Thu, 12 Dec 2024 13:30:21 +0100 Subject: [PATCH] Use defines instead of hardcoded magic values for maximum number of output channels and rpm filter time constant --- src/drivers/camera_capture/camera_capture.cpp | 2 +- .../camera_trigger/interfaces/src/camera_interface.cpp | 3 ++- src/drivers/pps_capture/PPSCapture.cpp | 2 +- src/drivers/rpm_capture/RPMCapture.cpp | 4 ++-- src/drivers/rpm_capture/RPMCapture.hpp | 1 + 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/drivers/camera_capture/camera_capture.cpp b/src/drivers/camera_capture/camera_capture.cpp index 77386f272616..843020902089 100644 --- a/src/drivers/camera_capture/camera_capture.cpp +++ b/src/drivers/camera_capture/camera_capture.cpp @@ -71,7 +71,7 @@ CameraCapture::CameraCapture() : _p_camera_capture_edge = param_find("CAM_CAP_EDGE"); param_get(_p_camera_capture_edge, &_camera_capture_edge); - for (unsigned i = 0; i < 16 && _capture_channel == -1; ++i) { + for (unsigned i = 0; i < PWM_OUTPUT_MAX_CHANNELS && _capture_channel == -1; ++i) { char param_name[17]; snprintf(param_name, sizeof(param_name), "%s_%s%d", PARAM_PREFIX, "FUNC", i + 1); param_t function_handle = param_find(param_name); diff --git a/src/drivers/camera_trigger/interfaces/src/camera_interface.cpp b/src/drivers/camera_trigger/interfaces/src/camera_interface.cpp index e15468b03a88..cf601ef41456 100644 --- a/src/drivers/camera_trigger/interfaces/src/camera_interface.cpp +++ b/src/drivers/camera_trigger/interfaces/src/camera_interface.cpp @@ -32,6 +32,7 @@ ****************************************************************************/ #include "camera_interface.h" +#include #include #include @@ -44,7 +45,7 @@ void CameraInterface::get_pins() unsigned pin_index = 0; - for (unsigned i = 0; i < 16 && pin_index < arraySize(_pins); ++i) { + for (unsigned i = 0; i < PWM_OUTPUT_MAX_CHANNELS && pin_index < arraySize(_pins); ++i) { char param_name[17]; snprintf(param_name, sizeof(param_name), "%s_%s%d", PARAM_PREFIX, "FUNC", i + 1); param_t function_handle = param_find(param_name); diff --git a/src/drivers/pps_capture/PPSCapture.cpp b/src/drivers/pps_capture/PPSCapture.cpp index 8a13c48c3584..9bb8d47fba8d 100644 --- a/src/drivers/pps_capture/PPSCapture.cpp +++ b/src/drivers/pps_capture/PPSCapture.cpp @@ -63,7 +63,7 @@ bool PPSCapture::init() { bool success = false; - for (unsigned i = 0; i < 16; ++i) { + for (unsigned i = 0; i < PWM_OUTPUT_MAX_CHANNELS; ++i) { char param_name[17]; snprintf(param_name, sizeof(param_name), "%s_%s%d", PARAM_PREFIX, "FUNC", i + 1); param_t function_handle = param_find(param_name); diff --git a/src/drivers/rpm_capture/RPMCapture.cpp b/src/drivers/rpm_capture/RPMCapture.cpp index 8330f77d1305..127fc633c315 100644 --- a/src/drivers/rpm_capture/RPMCapture.cpp +++ b/src/drivers/rpm_capture/RPMCapture.cpp @@ -59,7 +59,7 @@ bool RPMCapture::init() { bool success = false; - for (unsigned i = 0; i < 16; ++i) { + for (unsigned i = 0; i < PWM_OUTPUT_MAX_CHANNELS; ++i) { char param_name[17]; snprintf(param_name, sizeof(param_name), "%s_%s%d", PARAM_PREFIX, "FUNC", i + 1); param_t function_handle = param_find(param_name); @@ -138,7 +138,7 @@ void RPMCapture::Run() // Don't update RPM filter with outliers const float dt = math::min((now - _timestamp_last_update) * 1e-6f, 1.f); _timestamp_last_update = now; - _rpm_filter.setParameters(dt, 0.5f); + _rpm_filter.setParameters(dt, RPM_FILTER_TIME_CONSTANT); _rpm_filter.update(_rpm_median_filter.apply(rpm_raw)); } diff --git a/src/drivers/rpm_capture/RPMCapture.hpp b/src/drivers/rpm_capture/RPMCapture.hpp index 61281257118c..63d742684840 100644 --- a/src/drivers/rpm_capture/RPMCapture.hpp +++ b/src/drivers/rpm_capture/RPMCapture.hpp @@ -72,6 +72,7 @@ class RPMCapture : public ModuleBase, public px4::ScheduledWorkItem, private: static constexpr hrt_abstime RPM_PULSE_TIMEOUT = 1_s; static constexpr float RPM_MAX_VALUE = 50e3f; + static constexpr float RPM_FILTER_TIME_CONSTANT = .5f; void Run() override;