mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-15 13:43:35 +08:00
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:
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user