Every other mavlink command not executed

Hi,
I’m trying to send mavlink commands from an external computer to the flight controller over UART, i.e. ArmDisarm, takeoff, land… etc.
I see that the commands are received by the flight controller, as I am receiving the appropriate COMMAND_ACK for each command I send. However, only every other command is actually executed by the flight controller.
So if I want to arm the quadcopter, I have to send the arm command twice. The same applies to other commands, such as takeoff and land.
I am able to arm\disarm the quadcopter directly from the mission planner using the radio telemetry. I sniffed the com port to verify that the mavlink message bytes sent by the mission planner are identical to those that I sent.

I am using a MicroPix flight controller with 3.5.4 firmware.
My UART line is connected to Serial2, with 57600 baud rate, configured as mavlink2.

Any ideas?

Thanks!

You should be getting command failed for those that are not executed.

Are your sequence numbers for the packets correct and that it is sent in-between the heartbeat packets.

Mike

Thanks for the quick reply.
Every command I send, I increase the sequence number by 1 and it wraps around at 255. Am I missing something?
What do you mean by in-between heartbeat packets? I have to wait for a HB message from the flight controller before each command I send?

There are Heartbeat packets that must be sent every second otherwise the Auto Pilot assumes you are not there and ignores you. So there are receive packet sequence numbers and send packet sequences and there should be heartbeat packet sent every second if there is nothing to send or receive.

Mike

Thank you very much!
It seems to be working now.
Don’t know how I missed this… it’s only the first thing written in any mavlink manual.

Yes, but its a tricky thing to implement since commands have to be interleaved with the Heartbeat packets.

It’s not as simple as send a command and get an answer.

Mike

If I have more than one command between two heartbeats that are say, half a second apart, should I have a problem?

You shouldn’t need to worry about interleaving things with heartbeats.

Do you have any sample code that you can share?

Are you sure that the messages you are sending are entirely being sent - not truncated due to a full buffer or similar?

It seems to be working fine, now that I’m sending heartbeat messages. Heartbeats are sent at 2Hz and there is no problem sending multiple commands between heartbeats. Thanks for the help!