Skip to content

Commit

Permalink
add low pass filtering on yaw mc rate control
Browse files Browse the repository at this point in the history
co-authored-by: danielmellinger <[email protected]>
co-authored-by: Eric Katzfey <[email protected]>
  • Loading branch information
3 people committed Jan 6, 2025
1 parent 8070a9b commit 0519289
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/lib/mathlib/math/filter/AlphaFilter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ class AlphaFilter
return true;
}

void setCutoffFreq(float cutoff_freq)
{
if (cutoff_freq > FLT_EPSILON) {
_time_constant = 1.f / (M_TWOPI_F * cutoff_freq);

} else {
_time_constant = 0.f;
}
}

/**
* Set filter parameter alpha directly without time abstraction
*
Expand Down
7 changes: 6 additions & 1 deletion src/modules/mc_rate_control/MulticopterRateControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ MulticopterRateControl::parameters_updated()
// manual rate control acro mode rate limits
_acro_rate_max = Vector3f(radians(_param_mc_acro_r_max.get()), radians(_param_mc_acro_p_max.get()),
radians(_param_mc_acro_y_max.get()));

_output_lpf_yaw.setCutoffFreq(_param_mc_yawrate_fc.get());
}

void
Expand Down Expand Up @@ -214,9 +216,12 @@ MulticopterRateControl::Run()
}

// run rate controller
const Vector3f torque_setpoint =
Vector3f torque_setpoint =
_rate_control.update(rates, _rates_setpoint, angular_accel, dt, _maybe_landed || _landed);

// apply low-pass filtering on yaw axis to reduce high frequency torque caused by rotor acceleration
torque_setpoint(2) = _output_lpf_yaw.update(torque_setpoint(2), dt);

// publish rate controller status
rate_ctrl_status_s rate_ctrl_status{};
_rate_control.getRateControlStatus(rate_ctrl_status);
Expand Down
4 changes: 4 additions & 0 deletions src/modules/mc_rate_control/MulticopterRateControl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#pragma once

#include <lib/rate_control/rate_control.hpp>
#include <lib/mathlib/math/filter/AlphaFilter.hpp>
#include <lib/matrix/matrix/math.hpp>
#include <lib/perf/perf_counter.h>
#include <px4_platform_common/defines.h>
Expand Down Expand Up @@ -129,6 +130,8 @@ class MulticopterRateControl : public ModuleBase<MulticopterRateControl>, public
float _energy_integration_time{0.0f};
float _control_energy[4] {};

AlphaFilter<float> _output_lpf_yaw;

DEFINE_PARAMETERS(
(ParamFloat<px4::params::MC_ROLLRATE_P>) _param_mc_rollrate_p,
(ParamFloat<px4::params::MC_ROLLRATE_I>) _param_mc_rollrate_i,
Expand All @@ -150,6 +153,7 @@ class MulticopterRateControl : public ModuleBase<MulticopterRateControl>, public
(ParamFloat<px4::params::MC_YAWRATE_D>) _param_mc_yawrate_d,
(ParamFloat<px4::params::MC_YAWRATE_FF>) _param_mc_yawrate_ff,
(ParamFloat<px4::params::MC_YAWRATE_K>) _param_mc_yawrate_k,
(ParamFloat<px4::params::MC_YAWRATE_FC>) _param_mc_yawrate_fc,

(ParamFloat<px4::params::MC_ACRO_R_MAX>) _param_mc_acro_r_max,
(ParamFloat<px4::params::MC_ACRO_P_MAX>) _param_mc_acro_p_max,
Expand Down
14 changes: 14 additions & 0 deletions src/modules/mc_rate_control/mc_rate_control_params.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,17 @@ PARAM_DEFINE_FLOAT(MC_YAWRATE_K, 1.0f);
* @group Multicopter Rate Control
*/
PARAM_DEFINE_INT32(MC_BAT_SCALE_EN, 0);

/**
* First order low pass filter cutoff frequency for yaw rate control
*
* Reduces vibrations by lowering high frequency torque caused by rotor acceleration.
* 0 disables the filter
*
* @min 0
* @max 10
* @unit Hz
* @decimal 3
* @group Multicopter Rate Control
*/
PARAM_DEFINE_FLOAT(MC_YAWRATE_FC, 2.f);

0 comments on commit 0519289

Please sign in to comment.