Questions about mavlink commands and the pymavlink documentation

    master.mav.command_long_send(
        master.target_system, master.target_component,
        mavutil.mavlink.MAV_CMD_SET_MESSAGE_INTERVAL, 0,
        message_id, # The MAVLink message ID
        1e6 / frequency_hz, # The interval between two messages in microseconds. Set to -1 to disable and 0 to request default rate.

     -->0, # Target address of message stream (if message has target address fields). 0: Flight-stack default (recommended), 1: address of requestor, 2: broadcast.
        0, 0, 0, -->0)

Recently I have been reading the mavlink message format in order to learn more of the mavlink protocol. If I have read this correctly, a Command_long command message needs to take in:

  1. the target system
  2. the target component
  3. the command message ID (which for the message interval command would be 511)
  4. message confirmation

and then 7 parameters based on the command type.

I have two questions regarding this.

  1. Some commands require less than 7 parameters, for example the MAV_CMD_DO_SET_MODE command requires 3. When sending a command_long_send() message, do we send zeros for the parameters that aren’t specified? Does the autopilot just disregard those parameters regardless of the values sent?
  2. In the pymavlink documentation for requesting a message interval (given above), the “0” after the 1e6/frequency argument (the first arrow. In parameter 2’s position) is explained to be the target address of message stream. But, when I check the mavlink message documentation, it is the 7th argument that determines the target address. This confused me and that is why I am asking. Does the autopilot use the 2nd position in place of the 7th because there are no other parameters in between? Unlike some other mavlink commands, the unused parameter “slots” in the MAV_CMD_SET_MESSAGE_INTERVAL aren’t labeled as “empty” either.

This may come across as nitpicky but I think others may experience the same confusion.
Could someone explain this situation please?
Thanks for your time. :slight_smile:

Hi @VioletCheese,

By convention we tend to send zeros for unused/empty parameters, yes. Most autopilots should disregard parameters that are unspecified or specified as empty in the message definition, but if a custom autopilot has some extra functionality shoehorned into a given message then it’s possible that sending arbitrary values could have unintended consequences.

Yes, that seems to be a mistake in our example. I’ve made a pull request correcting that here, so it should be fixed soon:

As it turns out, it seems like the ArduPilot implementation is missing that parameter entirely, so I’ve raised an issue about that as well, here.

The MAVLink specification is a little inconsistent in terms of how empty parameters are specified (presumably that’s changed somewhat over time, and hasn’t been backported to older definitions). There are various other messages that have a gap before the 7th parameter, some of which don’t explicitly specify Empty parameters in between.

Nitpicks/clarification of docs and examples is always welcomed - we want them to be as clear and understandable as possible :slight_smile:

2 Likes