0
0
Drone Programmingprogramming~20 mins

Sending custom MAVLink commands in Drone Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
MAVLink Command Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this MAVLink command send code?

Consider this Python snippet using pymavlink to send a custom MAVLink command to a drone. What will be printed?

Drone Programming
from pymavlink import mavutil

master = mavutil.mavlink_connection('udpout:localhost:14550')

master.target_system = 1
master.target_component = 1

# Send a command_long message with command ID 3000 and parameters 1,2,3,4,5,6
master.mav.command_long_send(
    master.target_system,
    master.target_component,
    3000,  # custom command ID
    0,     # confirmation
    1, 2, 3, 4, 5, 6, 0
)

print('Command sent with ID 3000 and params 1-6')
ACommand sent with ID 3000 and params 1-6
BSyntaxError: missing parentheses in call to 'print'
CTypeError: command_long_send() missing 1 required positional argument
DRuntimeError: connection not established
Attempts:
2 left
💡 Hint

Check the print statement and the parameters passed to command_long_send.

🧠 Conceptual
intermediate
1:30remaining
Which parameter in command_long_send specifies the target system?

In the command_long_send function of pymavlink, which argument represents the target system ID?

AThe second argument
BThe fourth argument
CThe third argument
DThe first argument
Attempts:
2 left
💡 Hint

Look at the function signature: command_long_send(target_system, target_component, command, confirmation, param1, ...)

🔧 Debug
advanced
2:30remaining
Why does this custom MAVLink command fail to send?

Review this code snippet that attempts to send a custom MAVLink command but fails. What is the likely cause?

Drone Programming
from pymavlink import mavutil

master = mavutil.mavlink_connection('udpout:localhost:14550')

# Missing target_system and target_component arguments
master.mav.command_long_send(
    3000,  # command ID
    0,     # confirmation
    1, 2, 3, 4, 5, 6, 0
)

print('Command sent')
AThe connection string 'udpout:localhost:14550' is incorrect
BThe command ID 3000 is invalid and causes failure
CThe command_long_send call is missing required target_system and target_component arguments
DThe print statement causes a runtime error
Attempts:
2 left
💡 Hint

Check the function signature and the number of arguments passed.

📝 Syntax
advanced
2:00remaining
Which option correctly sends a custom MAVLink command with parameters?

Choose the correct Python code snippet that sends a custom MAVLink command with ID 4000 and parameters 10, 20, 30.

Amaster.mav.command_long_send(4000, 0, 10, 20, 30, 0, 0, 0)
Bmaster.mav.command_long_send(master.target_system, master.target_component, 4000, 0, 10, 20, 30, 0, 0, 0, 0)
Cmaster.mav.command_long_send(master.target_system, 4000, master.target_component, 0, 10, 20, 30, 0, 0, 0)
Dmaster.mav.command_long_send(master.target_component, master.target_system, 4000, 0, 10, 20, 30, 0, 0, 0)
Attempts:
2 left
💡 Hint

Remember the order of arguments: target_system, target_component, command, confirmation, params...

🚀 Application
expert
1:30remaining
How many parameters can you send in a single custom MAVLink command_long message?

The command_long_send method allows sending parameters with the command. How many parameters can you include in one command?

A7 parameters
B8 parameters
C6 parameters
D10 parameters
Attempts:
2 left
💡 Hint

Check the MAVLink COMMAND_LONG message definition.