Best practice method for establishing a UAV is ready for next command?

I hope this question makes sense, I am just diving into learning MAVLink now and want to understand how to send commands one after another from a single script.

I am writing the script with pymavlink and simulating the results with SITL. This is my first attempt at this.

I send 4 commands,

  • Change to guided mode
  • Arm
  • Take off
  • Move forward

I found if I write these one after another in one script, they don’t get executed, I am assume because the copter hasn’t finished processing the last command.

So I tried to add an if block to tested for the result of the acknowledgement message with

msg = the_connection.recv_match(type='COMMAND_ACK', blocking=True)
if(msg.result == 0):
# send next command

But this didn’t work either. So I am currently using time.sleep(4) between commands, but I think there must be a better way to check if copter is ready to execute next command.

Is there a better way to do this, thank you

Most commands are acknowledged. Listen for the ack, send the next.

1 Like

@Yuri_Rage I did that, it is in my question

Then subscribe to the messages for each state you wish to change. For example, subscribe to the arming message to ensure that arming has actually happened vice simply knowing the command was received.

can you provide an example code how to do this please

I’m afraid I’m not at a development machine where that’s easily done. There should be examples available with a modicum of searching.