Skip to content

Commit 3fc3039

Browse files
committed
Use defines instead of hardcoded magic values for maximum number of output channels and rpm filter time constant
1 parent 887ff6a commit 3fc3039

File tree

5 files changed

+7
-5
lines changed

5 files changed

+7
-5
lines changed

src/drivers/camera_capture/camera_capture.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ CameraCapture::CameraCapture() :
7171
_p_camera_capture_edge = param_find("CAM_CAP_EDGE");
7272
param_get(_p_camera_capture_edge, &_camera_capture_edge);
7373

74-
for (unsigned i = 0; i < 16 && _capture_channel == -1; ++i) {
74+
for (unsigned i = 0; i < PWM_OUTPUT_MAX_CHANNELS && _capture_channel == -1; ++i) {
7575
char param_name[17];
7676
snprintf(param_name, sizeof(param_name), "%s_%s%d", PARAM_PREFIX, "FUNC", i + 1);
7777
param_t function_handle = param_find(param_name);

src/drivers/camera_trigger/interfaces/src/camera_interface.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
****************************************************************************/
3333

3434
#include "camera_interface.h"
35+
#include <drivers/drv_pwm_output.h>
3536
#include <px4_platform_common/log.h>
3637
#include <board_config.h>
3738

@@ -44,7 +45,7 @@ void CameraInterface::get_pins()
4445

4546
unsigned pin_index = 0;
4647

47-
for (unsigned i = 0; i < 16 && pin_index < arraySize(_pins); ++i) {
48+
for (unsigned i = 0; i < PWM_OUTPUT_MAX_CHANNELS && pin_index < arraySize(_pins); ++i) {
4849
char param_name[17];
4950
snprintf(param_name, sizeof(param_name), "%s_%s%d", PARAM_PREFIX, "FUNC", i + 1);
5051
param_t function_handle = param_find(param_name);

src/drivers/pps_capture/PPSCapture.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ bool PPSCapture::init()
6363
{
6464
bool success = false;
6565

66-
for (unsigned i = 0; i < 16; ++i) {
66+
for (unsigned i = 0; i < PWM_OUTPUT_MAX_CHANNELS; ++i) {
6767
char param_name[17];
6868
snprintf(param_name, sizeof(param_name), "%s_%s%d", PARAM_PREFIX, "FUNC", i + 1);
6969
param_t function_handle = param_find(param_name);

src/drivers/rpm_capture/RPMCapture.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ bool RPMCapture::init()
5959
{
6060
bool success = false;
6161

62-
for (unsigned i = 0; i < 16; ++i) {
62+
for (unsigned i = 0; i < PWM_OUTPUT_MAX_CHANNELS; ++i) {
6363
char param_name[17];
6464
snprintf(param_name, sizeof(param_name), "%s_%s%d", PARAM_PREFIX, "FUNC", i + 1);
6565
param_t function_handle = param_find(param_name);
@@ -138,7 +138,7 @@ void RPMCapture::Run()
138138
// Don't update RPM filter with outliers
139139
const float dt = math::min((now - _timestamp_last_update) * 1e-6f, 1.f);
140140
_timestamp_last_update = now;
141-
_rpm_filter.setParameters(dt, 0.5f);
141+
_rpm_filter.setParameters(dt, RPM_FILTER_TIME_CONSTANT);
142142
_rpm_filter.update(_rpm_median_filter.apply(rpm_raw));
143143
}
144144

src/drivers/rpm_capture/RPMCapture.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class RPMCapture : public ModuleBase<RPMCapture>, public px4::ScheduledWorkItem,
7272
private:
7373
static constexpr hrt_abstime RPM_PULSE_TIMEOUT = 1_s;
7474
static constexpr float RPM_MAX_VALUE = 50e3f;
75+
static constexpr float RPM_FILTER_TIME_CONSTANT = .5f;
7576

7677
void Run() override;
7778

0 commit comments

Comments
 (0)