Skip to content

Commit 317bc0b

Browse files
committed
RpmControl: simplify the entire control logic
1 parent ca17768 commit 317bc0b

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

src/modules/control_allocator/ActuatorEffectiveness/RpmControl.cpp

+20-22
Original file line numberDiff line numberDiff line change
@@ -37,47 +37,45 @@
3737

3838
using namespace time_literals;
3939

40-
RpmControl::RpmControl(ModuleParams *parent) : ModuleParams(parent) {};
40+
RpmControl::RpmControl(ModuleParams *parent) : ModuleParams(parent)
41+
{
42+
_pid.setOutputLimit(PID_OUTPUT_LIMIT);
43+
_pid.setIntegralLimit(PID_OUTPUT_LIMIT);
44+
};
4145

4246
void RpmControl::setSpoolupProgress(float spoolup_progress)
4347
{
4448
_spoolup_progress = spoolup_progress;
4549
_pid.setSetpoint(_spoolup_progress * _param_ca_heli_rpm_sp.get());
4650

47-
if (_spoolup_progress < .8f) {
51+
if (_spoolup_progress < SPOOLUP_PROGRESS_WITH_CONTROLLER_ENGAGED) {
4852
_pid.resetIntegral();
4953
}
5054
}
5155

5256
float RpmControl::getActuatorCorrection()
5357
{
58+
hrt_abstime now = hrt_absolute_time();
59+
60+
// RPM measurement update
5461
if (_rpm_sub.updated()) {
5562
rpm_s rpm{};
5663

5764
if (_rpm_sub.copy(&rpm)) {
58-
_rpm_estimate = rpm.rpm_estimate;
59-
_timestamp_last_rpm_measurement = rpm.timestamp;
65+
const float dt = math::min((now - _timestamp_last_measurement) * 1e-6f, 1.f);
66+
_timestamp_last_measurement = rpm.timestamp;
67+
68+
const float gain_scale = math::interpolate(_spoolup_progress, .8f, 1.f, 0.f, 1e-3f);
69+
_pid.setGains(_param_ca_heli_rpm_p.get() * gain_scale, _param_ca_heli_rpm_i.get() * gain_scale, 0.f);
70+
_actuator_correction = _pid.update(rpm.rpm_estimate, dt, true);
6071
}
6172
}
6273

63-
hrt_abstime now = hrt_absolute_time();
64-
const float dt = math::constrain((now - _timestamp_last_update) * 1e-6f, 1e-3f, 1.f);
65-
_timestamp_last_update = now;
66-
67-
const bool rpm_measurement_timeout = (now - _timestamp_last_rpm_measurement) < 1_s;
68-
69-
if (rpm_measurement_timeout) {
70-
const float gain_scale = math::max((_spoolup_progress - .8f) * 5.f, 0.f) * 1e-3f;
71-
_pid.setGains(_param_ca_heli_rpm_p.get() * gain_scale, _param_ca_heli_rpm_i.get() * gain_scale, 0.f);
72-
73-
} else {
74-
_pid.setGains(0.f, 0.f, 0.f);
74+
// Timeout
75+
if (now > _timestamp_last_measurement + 1_s) {
76+
_pid.resetIntegral();
77+
_actuator_correction = 0.f;
7578
}
7679

77-
_pid.setOutputLimit(.5f);
78-
_pid.setIntegralLimit(.5f);
79-
80-
float output = _pid.update(_rpm_estimate, dt, true);
81-
82-
return output;
80+
return _actuator_correction;
8381
}

src/modules/control_allocator/ActuatorEffectiveness/RpmControl.hpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,14 @@ class RpmControl : public ModuleParams
5959
float getActuatorCorrection();
6060

6161
private:
62-
uORB::Subscription _rpm_sub{ORB_ID(rpm)};
62+
static constexpr float SPOOLUP_PROGRESS_WITH_CONTROLLER_ENGAGED = .8f; // [0,1]
63+
static constexpr float PID_OUTPUT_LIMIT = .5f; // [0,1]
6364

64-
float _rpm_estimate{0.f};
65-
float _spoolup_progress{0.f};
65+
uORB::Subscription _rpm_sub{ORB_ID(rpm)};
6666
PID _pid;
67-
hrt_abstime _timestamp_last_rpm_measurement{0};
68-
hrt_abstime _timestamp_last_update{0};
67+
float _spoolup_progress{0.f}; // [0,1]
68+
hrt_abstime _timestamp_last_measurement{0}; // for dt and timeout
69+
float _actuator_correction{0.f};
6970

7071
DEFINE_PARAMETERS(
7172
(ParamFloat<px4::params::CA_HELI_RPM_SP>) _param_ca_heli_rpm_sp,

0 commit comments

Comments
 (0)