Skip to content

Commit

Permalink
Use defines instead of hardcoded magic values for maximum number of o…
Browse files Browse the repository at this point in the history
…utput channels and rpm filter time constant
  • Loading branch information
MaEtUgR committed Dec 18, 2024
1 parent 887ff6a commit 3fc3039
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/drivers/camera_capture/camera_capture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
****************************************************************************/

#include "camera_interface.h"
#include <drivers/drv_pwm_output.h>
#include <px4_platform_common/log.h>
#include <board_config.h>

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/pps_capture/PPSCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/drivers/rpm_capture/RPMCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}

Expand Down
1 change: 1 addition & 0 deletions src/drivers/rpm_capture/RPMCapture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class RPMCapture : public ModuleBase<RPMCapture>, 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;

Expand Down

0 comments on commit 3fc3039

Please sign in to comment.