mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-28 10:46:33 +08:00
RpmControl: split into cpp source file fixing includes
This commit is contained in:
@@ -62,6 +62,7 @@ px4_add_library(ActuatorEffectiveness
|
|||||||
ActuatorEffectivenessTailsitterVTOL.hpp
|
ActuatorEffectivenessTailsitterVTOL.hpp
|
||||||
ActuatorEffectivenessRoverAckermann.hpp
|
ActuatorEffectivenessRoverAckermann.hpp
|
||||||
ActuatorEffectivenessRoverAckermann.cpp
|
ActuatorEffectivenessRoverAckermann.cpp
|
||||||
|
RpmControl.cpp
|
||||||
RpmControl.hpp
|
RpmControl.hpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
*
|
||||||
|
* Copyright (c) 2024 PX4 Development Team. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "RpmControl.hpp"
|
||||||
|
|
||||||
|
#include <drivers/drv_hrt.h>
|
||||||
|
|
||||||
|
using namespace time_literals;
|
||||||
|
|
||||||
|
RpmControl::RpmControl(ModuleParams *parent) : ModuleParams(parent) {};
|
||||||
|
|
||||||
|
void RpmControl::setSpoolupProgress(float spoolup_progress)
|
||||||
|
{
|
||||||
|
_spoolup_progress = spoolup_progress;
|
||||||
|
_pid.setSetpoint(_spoolup_progress * _param_ca_heli_rpm_sp.get());
|
||||||
|
|
||||||
|
if (_spoolup_progress < .8f) {
|
||||||
|
_pid.resetIntegral();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float RpmControl::getActuatorCorrection()
|
||||||
|
{
|
||||||
|
if (_rpm_sub.updated()) {
|
||||||
|
rpm_s rpm{};
|
||||||
|
|
||||||
|
if (_rpm_sub.copy(&rpm)) {
|
||||||
|
_rpm_estimate = rpm.rpm_estimate;
|
||||||
|
_timestamp_last_rpm_measurement = rpm.timestamp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hrt_abstime now = hrt_absolute_time();
|
||||||
|
const float dt = math::constrain((now - _timestamp_last_update) * 1e-6f, 1e-3f, 1.f);
|
||||||
|
_timestamp_last_update = now;
|
||||||
|
|
||||||
|
const bool rpm_measurement_timeout = (now - _timestamp_last_rpm_measurement) < 1_s;
|
||||||
|
|
||||||
|
if (rpm_measurement_timeout) {
|
||||||
|
const float gain_scale = math::max((_spoolup_progress - .8f) * 5.f, 0.f) * 1e-3f;
|
||||||
|
_pid.setGains(_param_ca_heli_rpm_p.get() * gain_scale, _param_ca_heli_rpm_i.get() * gain_scale, 0.f);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
_pid.setGains(0.f, 0.f, 0.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
_pid.setOutputLimit(.5f);
|
||||||
|
_pid.setIntegralLimit(.5f);
|
||||||
|
|
||||||
|
float output = _pid.update(_rpm_estimate, dt, true);
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
@@ -43,64 +43,20 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <lib/mathlib/math/filter/AlphaFilter.hpp>
|
|
||||||
#include <lib/pid/PID.hpp>
|
#include <lib/pid/PID.hpp>
|
||||||
|
#include <px4_platform_common/module_params.h>
|
||||||
#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/rpm.h>
|
#include <uORB/topics/rpm.h>
|
||||||
|
|
||||||
using namespace time_literals;
|
|
||||||
|
|
||||||
class RpmControl : public ModuleParams
|
class RpmControl : public ModuleParams
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RpmControl(ModuleParams *parent) : ModuleParams(parent) {};
|
RpmControl(ModuleParams *parent);
|
||||||
~RpmControl() = default;
|
~RpmControl() = default;
|
||||||
|
|
||||||
void setSpoolupProgress(float spoolup_progress)
|
void setSpoolupProgress(float spoolup_progress);
|
||||||
{
|
float getActuatorCorrection();
|
||||||
_spoolup_progress = spoolup_progress;
|
|
||||||
_pid.setSetpoint(_spoolup_progress * _param_ca_heli_rpm_sp.get());
|
|
||||||
|
|
||||||
if (_spoolup_progress < .8f) {
|
|
||||||
_pid.resetIntegral();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float getActuatorCorrection()
|
|
||||||
{
|
|
||||||
if (_rpm_sub.updated()) {
|
|
||||||
rpm_s rpm{};
|
|
||||||
|
|
||||||
if (_rpm_sub.copy(&rpm)) {
|
|
||||||
_rpm_estimate = rpm.rpm_estimate;
|
|
||||||
_timestamp_last_rpm_measurement = rpm.timestamp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
hrt_abstime now = hrt_absolute_time();
|
|
||||||
const float dt = math::constrain((now - _timestamp_last_update) * 1e-6f, 1e-3f, 1.f);
|
|
||||||
_timestamp_last_update = now;
|
|
||||||
|
|
||||||
const bool rpm_measurement_timeout = (now - _timestamp_last_rpm_measurement) < 1_s;
|
|
||||||
|
|
||||||
if (rpm_measurement_timeout) {
|
|
||||||
const float gain_scale = math::max((_spoolup_progress - .8f) * 5.f, 0.f) * 1e-3f;
|
|
||||||
_pid.setGains(_param_ca_heli_rpm_p.get() * gain_scale, _param_ca_heli_rpm_i.get() * gain_scale, 0.f);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
_pid.setGains(0.f, 0.f, 0.f);
|
|
||||||
}
|
|
||||||
|
|
||||||
_pid.setOutputLimit(.5f);
|
|
||||||
_pid.setIntegralLimit(.5f);
|
|
||||||
|
|
||||||
float output = _pid.update(_rpm_estimate, dt, true);
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uORB::Subscription _rpm_sub{ORB_ID(rpm)};
|
uORB::Subscription _rpm_sub{ORB_ID(rpm)};
|
||||||
|
|||||||
Reference in New Issue
Block a user