mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-29 03:36:07 +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:
@@ -2,3 +2,6 @@ uint64 timestamp # time since system start (microseconds)
|
|||||||
|
|
||||||
float32 indicated_frequency_rpm # indicated rotor Frequency in Revolution per minute
|
float32 indicated_frequency_rpm # indicated rotor Frequency in Revolution per minute
|
||||||
float32 estimated_accurancy_rpm # estimated accuracy in Revolution per minute
|
float32 estimated_accurancy_rpm # estimated accuracy in Revolution per minute
|
||||||
|
|
||||||
|
float32 rpm_raw # measured rpm
|
||||||
|
float32 rpm_estimate # filtered rpm
|
||||||
|
|||||||
@@ -99,13 +99,34 @@ void RPMCapture::Run()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hrt_abstime now = hrt_absolute_time();
|
||||||
|
const hrt_abstime period = _hrt_timestamp - _hrt_timestamp_prev;
|
||||||
|
|
||||||
pwm_input_s pwm_input{};
|
pwm_input_s pwm_input{};
|
||||||
pwm_input.timestamp = hrt_absolute_time();
|
pwm_input.timestamp = now;
|
||||||
pwm_input.period = _hrt_timestamp - _hrt_timestamp_prev;
|
pwm_input.period = period;
|
||||||
pwm_input.error_count = _error_count;
|
pwm_input.error_count = _error_count;
|
||||||
_hrt_timestamp_prev = _hrt_timestamp;
|
_hrt_timestamp_prev = _hrt_timestamp;
|
||||||
_value_processed.store(true);
|
_value_processed.store(true);
|
||||||
_pwm_input_pub.publish(pwm_input);
|
_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)
|
int RPMCapture::gpio_interrupt_callback(int irq, void *context, void *arg)
|
||||||
|
|||||||
@@ -34,12 +34,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <drivers/drv_hrt.h>
|
#include <drivers/drv_hrt.h>
|
||||||
|
#include <lib/mathlib/math/filter/AlphaFilter.hpp>
|
||||||
#include <px4_arch/micro_hal.h>
|
#include <px4_arch/micro_hal.h>
|
||||||
#include <px4_platform_common/module.h>
|
#include <px4_platform_common/module.h>
|
||||||
#include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
|
#include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
|
||||||
#include <uORB/Publication.hpp>
|
#include <uORB/Publication.hpp>
|
||||||
#include <uORB/Subscription.hpp>
|
#include <uORB/Subscription.hpp>
|
||||||
#include <uORB/topics/pwm_input.h>
|
#include <uORB/topics/pwm_input.h>
|
||||||
|
#include <uORB/topics/rpm.h>
|
||||||
|
|
||||||
using namespace time_literals;
|
using namespace time_literals;
|
||||||
|
|
||||||
@@ -71,9 +73,13 @@ private:
|
|||||||
int _channel{-1};
|
int _channel{-1};
|
||||||
uint32_t _rpm_capture_gpio{0};
|
uint32_t _rpm_capture_gpio{0};
|
||||||
uORB::Publication<pwm_input_s> _pwm_input_pub{ORB_ID(pwm_input)};
|
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{0};
|
||||||
hrt_abstime _hrt_timestamp_prev{0};
|
hrt_abstime _hrt_timestamp_prev{0};
|
||||||
uint32_t _error_count{0};
|
uint32_t _error_count{0};
|
||||||
px4::atomic<bool> _value_processed{true};
|
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