Skip to content

Commit e05d8f2

Browse files
AlexKlimajdakejahl
andauthored
heater: fix on blips when the heater is off (#25398)
Co-authored-by: Jacob Dahl <37091262+dakejahl@users.noreply.github.com>
1 parent 947c71e commit e05d8f2

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/drivers/heater/heater.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ void Heater::Run()
201201
// Turn the heater off.
202202
_heater_on = false;
203203
heater_off();
204-
ScheduleDelayed(_controller_period_usec - _controller_time_on_usec);
204+
ScheduleDelayed(CONTROLLER_PERIOD_DEFAULT - _controller_time_on_usec);
205205

206206
} else if (_sensor_accel_sub.update(&sensor_accel)) {
207207

@@ -217,9 +217,9 @@ void Heater::Run()
217217
_integrator_value = math::constrain(_integrator_value, -0.25f, 0.25f);
218218

219219
_controller_time_on_usec = static_cast<int>((_param_sens_imu_temp_ff.get() + _proportional_value +
220-
_integrator_value) * static_cast<float>(_controller_period_usec));
220+
_integrator_value) * static_cast<float>(CONTROLLER_PERIOD_DEFAULT));
221221

222-
_controller_time_on_usec = math::constrain(_controller_time_on_usec, 0, _controller_period_usec);
222+
_controller_time_on_usec = math::constrain(_controller_time_on_usec, 0, CONTROLLER_PERIOD_DEFAULT);
223223

224224
if (fabsf(temperature_delta) < TEMPERATURE_TARGET_THRESHOLD) {
225225
_temperature_target_met = true;
@@ -229,9 +229,16 @@ void Heater::Run()
229229
_temperature_target_met = false;
230230
}
231231

232-
_heater_on = true;
233-
heater_on();
234-
ScheduleDelayed(_controller_time_on_usec);
232+
if (_controller_time_on_usec > 0) {
233+
// Turn the heater on.
234+
_heater_on = true;
235+
heater_on();
236+
ScheduleDelayed(_controller_time_on_usec);
237+
238+
} else {
239+
// Turn the heater off.
240+
ScheduleDelayed(CONTROLLER_PERIOD_DEFAULT);
241+
}
235242
}
236243

237244
publish_status();
@@ -245,7 +252,7 @@ void Heater::publish_status()
245252
status.temperature_sensor = _temperature_last;
246253
status.temperature_target = _param_sens_imu_temp.get();
247254
status.temperature_target_met = _temperature_target_met;
248-
status.controller_period_usec = _controller_period_usec;
255+
status.controller_period_usec = CONTROLLER_PERIOD_DEFAULT;
249256
status.controller_time_on_usec = _controller_time_on_usec;
250257
status.proportional_value = _proportional_value;
251258
status.integrator_value = _integrator_value;

src/drivers/heater/heater.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ class Heater : public ModuleBase<Heater>, public ModuleParams, public px4::Sched
142142
bool _heater_on = false;
143143
bool _temperature_target_met = false;
144144

145-
int _controller_period_usec = CONTROLLER_PERIOD_DEFAULT;
146145
int _controller_time_on_usec = 0;
147146

148147
float _integrator_value = 0.0f;

0 commit comments

Comments
 (0)