Offboard mode and mavlink message for this mode

Hello,

First of all, before using it on a real copter, test it intensively with JMavSim (I’ve stayed on version 1.4.4 for now, don’t know if newer firmware version work with JMavSim). I’m using a pixhawk board for the HIL tests.

  1. Do you send an HB message faster than 1Hz (in my case i’m sending it a 3Hz). Also you need to use autopilot mavlink messages in order to know in which state your autopilot is. It is possible that some messages get corrupted hence droped. You should implement a way to repeat order if after some delay the autopilot is not in the expected state.

  2. If you switch to offboard and no companion is talking, the autopilot will reuse the previous mode set by user. That’s why it is recommended to enter Offboard mode once you are in position or hold mode.

3)You are switching of topics and use Ardupilot forum. Some information might be correct some might not apply to the PX4 firmware. The messages I use in order to do OFFBOARD are :
Order :
MAV_CMD_COMPONENT_ARM_DISARM
HEARTBEAT
MAV_CMD_NAV_GUIDED_ENABLE
SET_POSITION_TARGET_LOCAL_NED
MAV_CMD_SET_MESSAGE_INTERVAL

Status :
MAVLINK_MSG_ID_HEARTBEAT
MAVLINK_MSG_ID_LOCAL_POSITION_NED
MAVLINK_MSG_ID_GLOBAL_POSITION_INT
MAVLINK_MSG_ID_ATTITUDE
MAVLINK_MSG_ID_EXTENDED_SYS_STATE
MAVLINK_MSG_ID_SYS_STATUS
MAVLINK_MSG_ID_HOME_POSITION
MAVLINK_MSG_ID_GPS_RAW_INT

  1. Using only the set of messages above will allow you to move everywhere you need to

  2. As stated in 1), some messages might get dropped. The delay is a ‘fast and dumy’ way of sending order (it is usefull as an example of how it works and for quick tests) but if you want something more robust, you need to use the statuses reported by Autopilot. In the end you’ll have a kind of state machine.

  3. POSITION_TARGET_LOCAL_NED will indicate to you it has received your order and intend to go there. MAVLINK_MSG_ID_LOCAL_POSITION_NED can indeed be used in conjonction with MAVLINK_MSG_ID_ATTITUDE to know whether it has completed the requested movement.

  4. I think you refer to the way it is done in Ardupilot documentation. I do not know whether it is working with PX4. In my way of understanding it, as you have a companion, it is his job to wait until the UAV has reached the position before giving the next setpoint. (in my case I keep sending the desired position every 500ms, and once it has reached it, give a new one)

  5. Not sure but i think SW stand for switch and TH for threshold.

For your last question, you indeed need to set some non null speed otherwise there might be undesired behavior.

Last advice : each time you change your code in the companion, double check it on JMAVSIM even if you don’t think you have affected something vital; I’ve have crashed many virtual drone in JMavSim

If you have a spare pixhawk, you can configure it to HIL Quadcopter frame. This way you can connect your companion to the pixhawk serial port and perform Hardware In the Loop. I did not used JMavSim with UDP

Hope it helps

1 Like