@@ -1486,8 +1486,19 @@ Commander::run()
1486
1486
1487
1487
sp_man_sub.update (&sp_man);
1488
1488
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;
1491
1502
offboard_control_mode_sub.copy (&offboard_control_mode);
1492
1503
1493
1504
if (old.ignore_thrust != offboard_control_mode.ignore_thrust ||
@@ -1499,13 +1510,16 @@ Commander::run()
1499
1510
old.ignore_velocity != offboard_control_mode.ignore_velocity ||
1500
1511
old.ignore_acceleration_force != offboard_control_mode.ignore_acceleration_force ||
1501
1512
old.ignore_alt_hold != offboard_control_mode.ignore_alt_hold ) {
1513
+
1502
1514
status_changed = true ;
1503
1515
}
1504
1516
}
1505
1517
1506
1518
if (offboard_control_mode.timestamp != 0 &&
1507
1519
offboard_control_mode.timestamp + OFFBOARD_TIMEOUT > hrt_absolute_time ()) {
1520
+
1508
1521
if (status_flags.offboard_control_signal_lost ) {
1522
+
1509
1523
status_flags.offboard_control_signal_lost = false ;
1510
1524
status_flags.offboard_control_loss_timeout = false ;
1511
1525
status_changed = true ;
0 commit comments