Skip to content

Commit b2795bc

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

File tree

2 files changed

+52
-25
lines changed

2 files changed

+52
-25
lines changed

src/modules/vtol_att_control/vtol_att_control_main.cpp

+42-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,46 @@ 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+
273+
_previous_vtol_mode = current_vtol_mode;
274+
}
275+
276+
void
277+
VtolAttitudeControl::register_mc_callbacks()
278+
{
279+
_vehicle_torque_setpoint_virtual_fw_sub.unregisterCallback();
280+
_vehicle_torque_setpoint_virtual_mc_sub.registerCallback();
281+
}
282+
283+
void
284+
VtolAttitudeControl::register_fw_callbacks()
285+
{
286+
_vehicle_torque_setpoint_virtual_mc_sub.unregisterCallback();
287+
_vehicle_torque_setpoint_virtual_fw_sub.registerCallback();
288+
}
289+
275290
void
276291
VtolAttitudeControl::Run()
277292
{
278293
if (should_exit()) {
279294
_vehicle_torque_setpoint_virtual_fw_sub.unregisterCallback();
280295
_vehicle_torque_setpoint_virtual_mc_sub.unregisterCallback();
281-
_vehicle_thrust_setpoint_virtual_fw_sub.unregisterCallback();
282-
_vehicle_thrust_setpoint_virtual_mc_sub.unregisterCallback();
283296
exit_and_cleanup();
284297
return;
285298
}
@@ -298,6 +311,7 @@ VtolAttitudeControl::Run()
298311
if (!_initialized) {
299312

300313
if (_vtol_type->init()) {
314+
update_registrations();
301315
_initialized = true;
302316

303317
} else {
@@ -315,8 +329,13 @@ VtolAttitudeControl::Run()
315329

316330
// run on actuator publications corresponding to VTOL mode
317331
bool should_run = false;
332+
mode current_vtol_mode = _vtol_type->get_mode();
333+
334+
if (current_vtol_mode != _previous_vtol_mode) {
335+
update_registrations();
336+
}
318337

319-
switch (_vtol_type->get_mode()) {
338+
switch (current_vtol_mode) {
320339
case mode::TRANSITION_TO_FW:
321340
case mode::TRANSITION_TO_MC:
322341
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)