Skip to content

Commit 14c65e1

Browse files
committed
vtol: reduce schedule frequency, which causes DSHOT150 problems
1 parent 9027dc1 commit 14c65e1

File tree

2 files changed

+51
-25
lines changed

2 files changed

+51
-25
lines changed

src/modules/vtol_att_control/vtol_att_control_main.cpp

+41-23
Original file line numberDiff line numberDiff line change
@@ -94,26 +94,7 @@ VtolAttitudeControl::~VtolAttitudeControl()
9494
bool
9595
VtolAttitudeControl::init()
9696
{
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();
11798
return true;
11899
}
119100

@@ -272,14 +253,45 @@ VtolAttitudeControl::parameters_update()
272253
}
273254
}
274255

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+
275289
void
276290
VtolAttitudeControl::Run()
277291
{
278292
if (should_exit()) {
279293
_vehicle_torque_setpoint_virtual_fw_sub.unregisterCallback();
280294
_vehicle_torque_setpoint_virtual_mc_sub.unregisterCallback();
281-
_vehicle_thrust_setpoint_virtual_fw_sub.unregisterCallback();
282-
_vehicle_thrust_setpoint_virtual_mc_sub.unregisterCallback();
283295
exit_and_cleanup();
284296
return;
285297
}
@@ -298,6 +310,7 @@ VtolAttitudeControl::Run()
298310
if (!_initialized) {
299311

300312
if (_vtol_type->init()) {
313+
update_registrations();
301314
_initialized = true;
302315

303316
} else {
@@ -315,8 +328,13 @@ VtolAttitudeControl::Run()
315328

316329
// run on actuator publications corresponding to VTOL mode
317330
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+
}
318336

319-
switch (_vtol_type->get_mode()) {
337+
switch (current_vtol_mode) {
320338
case mode::TRANSITION_TO_FW:
321339
case mode::TRANSITION_TO_MC:
322340
should_run = updated_fw_in || updated_mc_in;

src/modules/vtol_att_control/vtol_att_control_main.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
#include "standard.h"
8888
#include "tailsitter.h"
8989
#include "tiltrotor.h"
90+
#include "vtol_type.h"
9091

9192
using namespace time_literals;
9293

@@ -149,8 +150,8 @@ class VtolAttitudeControl : public ModuleBase<VtolAttitudeControl>, public Modul
149150
void Run() override;
150151
uORB::SubscriptionCallbackWorkItem _vehicle_torque_setpoint_virtual_fw_sub{this, ORB_ID(vehicle_torque_setpoint_virtual_fw)};
151152
uORB::SubscriptionCallbackWorkItem _vehicle_torque_setpoint_virtual_mc_sub{this, ORB_ID(vehicle_torque_setpoint_virtual_mc)};
152-
uORB::SubscriptionCallbackWorkItem _vehicle_thrust_setpoint_virtual_fw_sub{this, ORB_ID(vehicle_thrust_setpoint_virtual_fw)};
153-
uORB::SubscriptionCallbackWorkItem _vehicle_thrust_setpoint_virtual_mc_sub{this, ORB_ID(vehicle_thrust_setpoint_virtual_mc)};
153+
uORB::Subscription _vehicle_thrust_setpoint_virtual_fw_sub{ORB_ID(vehicle_thrust_setpoint_virtual_fw)};
154+
uORB::Subscription _vehicle_thrust_setpoint_virtual_mc_sub{ORB_ID(vehicle_thrust_setpoint_virtual_mc)};
154155

155156
uORB::SubscriptionInterval _parameter_update_sub{ORB_ID(parameter_update), 1_s};
156157

@@ -223,6 +224,7 @@ class VtolAttitudeControl : public ModuleBase<VtolAttitudeControl>, public Modul
223224
uint8_t _nav_state_prev;
224225

225226
VtolType *_vtol_type{nullptr}; // base class for different vtol types
227+
mode _previous_vtol_mode;
226228

227229
bool _initialized{false};
228230

@@ -236,6 +238,12 @@ class VtolAttitudeControl : public ModuleBase<VtolAttitudeControl>, public Modul
236238

237239
void parameters_update();
238240

241+
void update_registrations();
242+
243+
void register_mc_callbacks();
244+
245+
void register_fw_callbacks();
246+
239247
DEFINE_PARAMETERS(
240248
(ParamInt<px4::params::VT_TYPE>) _param_vt_type,
241249
(ParamFloat<px4::params::VT_SPOILER_MC_LD>) _param_vt_spoiler_mc_ld

0 commit comments

Comments
 (0)