RPMCapture: add hardcoded rpm processing

Such that we can continue development on this part.
The implementation was already used before porting things into the RPM capture module.
This commit is contained in:
Matthias Grob
2024-11-26 17:41:00 +01:00
parent 491ee01ac4
commit 1bcdb3ef8c
3 changed files with 32 additions and 2 deletions
+3
View File
@@ -2,3 +2,6 @@ uint64 timestamp # time since system start (microseconds)
float32 indicated_frequency_rpm # indicated rotor Frequency in Revolution per minute
float32 estimated_accurancy_rpm # estimated accuracy in Revolution per minute
float32 rpm_raw # measured rpm
float32 rpm_estimate # filtered rpm
+23 -2
View File
@@ -99,13 +99,34 @@ void RPMCapture::Run()
return;
}
hrt_abstime now = hrt_absolute_time();
const hrt_abstime period = _hrt_timestamp - _hrt_timestamp_prev;
pwm_input_s pwm_input{};
pwm_input.timestamp = hrt_absolute_time();
pwm_input.period = _hrt_timestamp - _hrt_timestamp_prev;
pwm_input.timestamp = now;
pwm_input.period = period;
pwm_input.error_count = _error_count;
_hrt_timestamp_prev = _hrt_timestamp;
_value_processed.store(true);
_pwm_input_pub.publish(pwm_input);
float rpm_raw{0.f};
if ((1 < period) && (period < 1_s)) {
// 1'000'000 / [us] -> pulses per second * 60 -> pulses per minute
rpm_raw = 60.f * 1e6f / (static_cast<float>(period) * 1.f);
}
const float dt = math::constrain((now - _timestamp_last_update) * 1e-6f, 0.01f, 1.f);
_timestamp_last_update = now;
_rpm_filter.setParameters(dt, 0.5f);
_rpm_filter.update(rpm_raw);
rpm_s rpm{};
rpm.timestamp = now;
rpm.rpm_raw = rpm_raw;
rpm.rpm_estimate = _rpm_filter.getState();
_rpm_pub.publish(rpm);
}
int RPMCapture::gpio_interrupt_callback(int irq, void *context, void *arg)
+6
View File
@@ -34,12 +34,14 @@
#pragma once
#include <drivers/drv_hrt.h>
#include <lib/mathlib/math/filter/AlphaFilter.hpp>
#include <px4_arch/micro_hal.h>
#include <px4_platform_common/module.h>
#include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
#include <uORB/Publication.hpp>
#include <uORB/Subscription.hpp>
#include <uORB/topics/pwm_input.h>
#include <uORB/topics/rpm.h>
using namespace time_literals;
@@ -71,9 +73,13 @@ private:
int _channel{-1};
uint32_t _rpm_capture_gpio{0};
uORB::Publication<pwm_input_s> _pwm_input_pub{ORB_ID(pwm_input)};
uORB::Publication<rpm_s> _rpm_pub{ORB_ID(rpm)};
hrt_abstime _hrt_timestamp{0};
hrt_abstime _hrt_timestamp_prev{0};
uint32_t _error_count{0};
px4::atomic<bool> _value_processed{true};
hrt_abstime _timestamp_last_update{0}; ///< to caluclate dt
AlphaFilter<float> _rpm_filter;
};