diff --git a/src/modules/commander/commander.cpp b/src/modules/commander/commander.cpp index 79d0811b72..b6a2846773 100644 --- a/src/modules/commander/commander.cpp +++ b/src/modules/commander/commander.cpp @@ -1494,6 +1494,18 @@ int commander_thread_main(int argc, char *argv[]) /* copy avionics voltage */ status.avionics_power_rail_voltage = system_power.voltage5V_v; + + if (status.usb_connected && !system_power.usb_connected) { + /* + * apparently the USB cable went away but we are still powered, + * so lets reset to a classic non-usb state. + */ + usleep(100000); + mavlink_log_critical(mavlink_fd, "USB disconnected, rebooting.") + usleep(400000); + px4_systemreset(false); + } + status.usb_connected = system_power.usb_connected; } } diff --git a/src/modules/commander/state_machine_helper.cpp b/src/modules/commander/state_machine_helper.cpp index d44f1f3506..3b169068d4 100644 --- a/src/modules/commander/state_machine_helper.cpp +++ b/src/modules/commander/state_machine_helper.cpp @@ -737,5 +737,12 @@ int prearm_check(const struct vehicle_status_s *status, const int mavlink_fd) checkAirspeed = true; } - return !Commander::preflightCheck(mavlink_fd, true, true, true, true, checkAirspeed, !(status->rc_input_mode == vehicle_status_s::RC_IN_MODE_OFF), !status->circuit_breaker_engaged_gpsfailure_check, true); + bool prearm_ok = Commander::preflightCheck(mavlink_fd, true, true, true, true, checkAirspeed, !(status->rc_input_mode == vehicle_status_s::RC_IN_MODE_OFF), !status->circuit_breaker_engaged_gpsfailure_check, true); + + if (status->usb_connected) { + prearm_ok = false; + mavlink_log_critical(mavlink_fd, "NOT ARMING: Flying with USB connected prohibited"); + } + + return !prearm_ok; }