Skip to content

Commit 0a6e380

Browse files
committed
vtol_att_control_main: refactor callback handling
1 parent 51c38d6 commit 0a6e380

File tree

2 files changed

+12
-26
lines changed

2 files changed

+12
-26
lines changed

src/modules/vtol_att_control/vtol_att_control_main.cpp

+11-21
Original file line numberDiff line numberDiff line change
@@ -254,41 +254,31 @@ VtolAttitudeControl::parameters_update()
254254
}
255255

256256
void
257-
VtolAttitudeControl::update_registrations()
257+
VtolAttitudeControl::update_callbacks()
258258
{
259259
mode current_vtol_mode = _vtol_type->get_mode();
260260

261261
switch (current_vtol_mode) {
262262
case mode::TRANSITION_TO_FW:
263263
case mode::TRANSITION_TO_MC:
264264
case mode::ROTARY_WING:
265-
register_mc_callbacks();
265+
if (_vehicle_torque_setpoint_virtual_mc_sub.registerCallback()) {
266+
_vehicle_torque_setpoint_virtual_fw_sub.unregisterCallback();
267+
}
268+
266269
break;
267270

268271
case mode::FIXED_WING:
269-
register_fw_callbacks();
272+
if (_vehicle_torque_setpoint_virtual_fw_sub.registerCallback()) {
273+
_vehicle_torque_setpoint_virtual_mc_sub.unregisterCallback();
274+
}
275+
270276
break;
271277
}
272278

273279
_previous_vtol_mode = current_vtol_mode;
274280
}
275281

276-
void
277-
VtolAttitudeControl::register_mc_callbacks()
278-
{
279-
if (_vehicle_torque_setpoint_virtual_mc_sub.registerCallback()) {
280-
_vehicle_torque_setpoint_virtual_fw_sub.unregisterCallback();
281-
}
282-
}
283-
284-
void
285-
VtolAttitudeControl::register_fw_callbacks()
286-
{
287-
if (_vehicle_torque_setpoint_virtual_fw_sub.registerCallback()) {
288-
_vehicle_torque_setpoint_virtual_mc_sub.unregisterCallback();
289-
}
290-
}
291-
292282
void
293283
VtolAttitudeControl::Run()
294284
{
@@ -313,7 +303,7 @@ VtolAttitudeControl::Run()
313303
if (!_initialized) {
314304

315305
if (_vtol_type->init()) {
316-
update_registrations();
306+
update_callbacks();
317307
_initialized = true;
318308

319309
} else {
@@ -334,7 +324,7 @@ VtolAttitudeControl::Run()
334324
mode current_vtol_mode = _vtol_type->get_mode();
335325

336326
if (current_vtol_mode != _previous_vtol_mode) {
337-
update_registrations();
327+
update_callbacks();
338328
}
339329

340330
switch (current_vtol_mode) {

src/modules/vtol_att_control/vtol_att_control_main.h

+1-5
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,7 @@ class VtolAttitudeControl : public ModuleBase<VtolAttitudeControl>, public Modul
238238

239239
void parameters_update();
240240

241-
void update_registrations();
242-
243-
void register_mc_callbacks();
244-
245-
void register_fw_callbacks();
241+
void update_callbacks();
246242

247243
DEFINE_PARAMETERS(
248244
(ParamInt<px4::params::VT_TYPE>) _param_vt_type,

0 commit comments

Comments
 (0)