|
37 | 37 |
|
38 | 38 | using namespace time_literals;
|
39 | 39 |
|
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 | +}; |
41 | 45 |
|
42 | 46 | void RpmControl::setSpoolupProgress(float spoolup_progress)
|
43 | 47 | {
|
44 | 48 | _spoolup_progress = spoolup_progress;
|
45 | 49 | _pid.setSetpoint(_spoolup_progress * _param_ca_heli_rpm_sp.get());
|
46 | 50 |
|
47 |
| - if (_spoolup_progress < .8f) { |
| 51 | + if (_spoolup_progress < SPOOLUP_PROGRESS_WITH_CONTROLLER_ENGAGED) { |
48 | 52 | _pid.resetIntegral();
|
49 | 53 | }
|
50 | 54 | }
|
51 | 55 |
|
52 | 56 | float RpmControl::getActuatorCorrection()
|
53 | 57 | {
|
| 58 | + hrt_abstime now = hrt_absolute_time(); |
| 59 | + |
| 60 | + // RPM measurement update |
54 | 61 | if (_rpm_sub.updated()) {
|
55 | 62 | rpm_s rpm{};
|
56 | 63 |
|
57 | 64 | 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); |
60 | 71 | }
|
61 | 72 | }
|
62 | 73 |
|
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; |
75 | 78 | }
|
76 | 79 |
|
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; |
83 | 81 | }
|
0 commit comments