0
0
Drone Programmingprogramming~10 mins

Sending custom MAVLink commands in Drone Programming - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Sending custom MAVLink commands
Start
Create MAVLink command message
Set command parameters
Send command to drone
Drone receives and processes command
Receive acknowledgment
Check if command succeeded?
NoHandle error
Yes
End
This flow shows how to build, send, and confirm a custom MAVLink command to a drone.
Execution Sample
Drone Programming
msg = create_mavlink_command(command_id=300, param1=1.0)
send_command(msg)
ack = receive_ack()
if ack.success:
    print('Command succeeded')
else:
    print('Command failed')
This code creates a custom MAVLink command, sends it, waits for acknowledgment, and prints success or failure.
Execution Table
StepActionCommand ParametersDrone ResponseOutput
1Create command messagecommand_id=300, param1=1.0NoneNone
2Send command to dronecommand_id=300, param1=1.0NoneNone
3Drone processes commandcommand_id=300, param1=1.0ProcessingNone
4Receive acknowledgmentNoneack.success=TrueNone
5Check acknowledgmentNoneack.success=TruePrint 'Command succeeded'
💡 Command acknowledged with success, so execution ends after printing success message.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 4Final
msgNone{command_id:300, param1:1.0}{command_id:300, param1:1.0}{command_id:300, param1:1.0}{command_id:300, param1:1.0}
ackNoneNoneNone{success: True}{success: True}
Key Moments - 3 Insights
Why do we wait for an acknowledgment after sending the command?
Because the drone needs to confirm it received and understood the command. See execution_table step 4 where ack.success is received.
What happens if ack.success is False?
The program would handle the error, possibly retry or alert the user. This is shown in the flow where 'Check if command succeeded?' leads to 'Handle error' if No.
Why do we set parameters like param1 when creating the command?
Parameters tell the drone what exactly to do with the command. Without them, the command might be incomplete or ignored. See execution_table step 1 for parameters.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of 'ack.success' at step 4?
ANone
BFalse
CTrue
DError
💡 Hint
Check the 'Drone Response' column at step 4 in execution_table.
At which step does the drone start processing the command?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Look at the 'Action' column in execution_table for when processing happens.
If the command parameters were missing at step 1, what would likely happen?
ADrone might ignore or error on command
BDrone processes command normally
CAcknowledgment would be success
DProgram prints 'Command succeeded'
💡 Hint
Refer to key_moments about why parameters are important.
Concept Snapshot
Sending custom MAVLink commands:
1. Create command message with command ID and parameters.
2. Send command to drone.
3. Wait for acknowledgment.
4. Check if command succeeded.
5. Handle errors if any.
Always set parameters correctly for expected behavior.
Full Transcript
This visual trace shows how to send a custom MAVLink command to a drone. First, the program creates a command message with a specific command ID and parameters. Then it sends this message to the drone. The drone processes the command and sends back an acknowledgment. The program checks if the acknowledgment indicates success. If yes, it prints a success message; if not, it handles the error. Tracking variables like the command message and acknowledgment helps understand the flow. Key points include waiting for acknowledgment to confirm command receipt and setting parameters to define command behavior.