Undefined behavior - Pixhawk reboot via Mavlink


I am raising this post as I recently noticed funny behavior when using MavLink command to reset the Pixhawk board. After resetting, the Pixhawk does not always return the HOME position (MAVLINK_MSG_ID_HOME_POSITION) back to the QGroundControl GCS.

Here are the steps I followed:

  1. Use QGC to send the Mavlink command:

_vehicle->doCommandLong(defaultComponentId(), MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);

  1. Pixhawk reboots, QGC is up again.
  2. Does not consistently receive the MAVLINK_MSG_ID_HOME_POSITION back, on each retry.
  3. Home location is not set on the GCS when connected with HIL (e.g. X-Plane)

On the Pixhawk side, this is how it is received:

if (cmd_mavlink.command == MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN && ((int)cmd_mavlink.param1) == 10) {
/* This is the link shutdown command, terminate mavlink */
warnx(“terminated by remote”);

/* terminate other threads and this thread */
_mavlink->_task_should_exit = true;

This makes me curious as to how PX4 handles this scenario of reset (flushing buffer and restarting MavLink?) and makes me wonder if that is indeed a bug with PX4 not being in the right initial state? Please notice that “resetting” the board via software is different than just disconnecting/connecting the hardware.

Any comment on this observation is appreciated.