Skip to content

Commit 6816f2a

Browse files
authored
commander force offboard control update when first entering mode
- fixes #12241
1 parent 048cca7 commit 6816f2a

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/modules/commander/Commander.cpp

+16-2
Original file line numberDiff line numberDiff line change
@@ -1486,8 +1486,19 @@ Commander::run()
14861486

14871487
sp_man_sub.update(&sp_man);
14881488

1489-
if (offboard_control_mode_sub.updated()) {
1490-
offboard_control_mode_s old = offboard_control_mode;
1489+
// if this is the first time entering OFFBOARD the subscription may not be active yet
1490+
bool force_offboard_update = false;
1491+
1492+
if (commander_state_s::MAIN_STATE_OFFBOARD) {
1493+
if (offboard_control_mode.timestamp == 0) {
1494+
offboard_control_mode_sub.forceInit();
1495+
force_offboard_update = true;
1496+
}
1497+
}
1498+
1499+
if (offboard_control_mode_sub.updated() || force_offboard_update) {
1500+
1501+
const offboard_control_mode_s old = offboard_control_mode;
14911502
offboard_control_mode_sub.copy(&offboard_control_mode);
14921503

14931504
if (old.ignore_thrust != offboard_control_mode.ignore_thrust ||
@@ -1499,13 +1510,16 @@ Commander::run()
14991510
old.ignore_velocity != offboard_control_mode.ignore_velocity ||
15001511
old.ignore_acceleration_force != offboard_control_mode.ignore_acceleration_force ||
15011512
old.ignore_alt_hold != offboard_control_mode.ignore_alt_hold) {
1513+
15021514
status_changed = true;
15031515
}
15041516
}
15051517

15061518
if (offboard_control_mode.timestamp != 0 &&
15071519
offboard_control_mode.timestamp + OFFBOARD_TIMEOUT > hrt_absolute_time()) {
1520+
15081521
if (status_flags.offboard_control_signal_lost) {
1522+
15091523
status_flags.offboard_control_signal_lost = false;
15101524
status_flags.offboard_control_loss_timeout = false;
15111525
status_changed = true;

0 commit comments

Comments
 (0)