@@ -94,26 +94,7 @@ VtolAttitudeControl::~VtolAttitudeControl()
94
94
bool
95
95
VtolAttitudeControl::init ()
96
96
{
97
- if (!_vehicle_torque_setpoint_virtual_fw_sub.registerCallback ()) {
98
- PX4_ERR (" callback registration failed" );
99
- return false ;
100
- }
101
-
102
- if (!_vehicle_torque_setpoint_virtual_mc_sub.registerCallback ()) {
103
- PX4_ERR (" callback registration failed" );
104
- return false ;
105
- }
106
-
107
- if (!_vehicle_thrust_setpoint_virtual_fw_sub.registerCallback ()) {
108
- PX4_ERR (" callback registration failed" );
109
- return false ;
110
- }
111
-
112
- if (!_vehicle_thrust_setpoint_virtual_mc_sub.registerCallback ()) {
113
- PX4_ERR (" callback registration failed" );
114
- return false ;
115
- }
116
-
97
+ ScheduleNow ();
117
98
return true ;
118
99
}
119
100
@@ -272,14 +253,45 @@ VtolAttitudeControl::parameters_update()
272
253
}
273
254
}
274
255
256
+ void
257
+ VtolAttitudeControl::update_registrations ()
258
+ {
259
+ mode current_vtol_mode = _vtol_type->get_mode ();
260
+
261
+ switch (current_vtol_mode) {
262
+ case mode::TRANSITION_TO_FW:
263
+ case mode::TRANSITION_TO_MC:
264
+ case mode::ROTARY_WING:
265
+ register_mc_callbacks ();
266
+ break ;
267
+
268
+ case mode::FIXED_WING:
269
+ register_fw_callbacks ();
270
+ break ;
271
+ }
272
+ _previous_vtol_mode = current_vtol_mode;
273
+ }
274
+
275
+ void
276
+ VtolAttitudeControl::register_mc_callbacks ()
277
+ {
278
+ _vehicle_torque_setpoint_virtual_fw_sub.unregisterCallback ();
279
+ _vehicle_torque_setpoint_virtual_mc_sub.registerCallback ();
280
+ }
281
+
282
+ void
283
+ VtolAttitudeControl::register_fw_callbacks ()
284
+ {
285
+ _vehicle_torque_setpoint_virtual_mc_sub.unregisterCallback ();
286
+ _vehicle_torque_setpoint_virtual_fw_sub.registerCallback ();
287
+ }
288
+
275
289
void
276
290
VtolAttitudeControl::Run ()
277
291
{
278
292
if (should_exit ()) {
279
293
_vehicle_torque_setpoint_virtual_fw_sub.unregisterCallback ();
280
294
_vehicle_torque_setpoint_virtual_mc_sub.unregisterCallback ();
281
- _vehicle_thrust_setpoint_virtual_fw_sub.unregisterCallback ();
282
- _vehicle_thrust_setpoint_virtual_mc_sub.unregisterCallback ();
283
295
exit_and_cleanup ();
284
296
return ;
285
297
}
@@ -298,6 +310,7 @@ VtolAttitudeControl::Run()
298
310
if (!_initialized) {
299
311
300
312
if (_vtol_type->init ()) {
313
+ update_registrations ();
301
314
_initialized = true ;
302
315
303
316
} else {
@@ -315,8 +328,13 @@ VtolAttitudeControl::Run()
315
328
316
329
// run on actuator publications corresponding to VTOL mode
317
330
bool should_run = false ;
331
+ mode current_vtol_mode = _vtol_type->get_mode ();
332
+
333
+ if (current_vtol_mode != _previous_vtol_mode) {
334
+ update_registrations ();
335
+ }
318
336
319
- switch (_vtol_type-> get_mode () ) {
337
+ switch (current_vtol_mode ) {
320
338
case mode::TRANSITION_TO_FW:
321
339
case mode::TRANSITION_TO_MC:
322
340
should_run = updated_fw_in || updated_mc_in;
0 commit comments