Consider this code snippet that checks the connection status over MAVLink:
connection_status = "connected" if mavlink.is_connected() else "disconnected" print(connection_status)
Assuming mavlink.is_connected() returns False, what will be printed?
connection_status = "connected" if mavlink.is_connected() else "disconnected" print(connection_status)
Think about what the if-else expression does when the condition is false.
The expression "connected" if mavlink.is_connected() else "disconnected" returns "disconnected" when mavlink.is_connected() is False. So the printed output is "disconnected".
When establishing a MAVLink connection over UDP, which port number is typically used by default?
It is a port number often seen in drone ground control software.
Port 14550 is the default UDP port used by many MAVLink ground control stations to communicate with drones.
Look at this Python code snippet trying to open a MAVLink connection:
from pymavlink import mavutil
master = mavutil.mavlink_connection('udp:127.0.0.1:14550')
master.wait_heartbeat()
print("Heartbeat received")But it raises a TimeoutError. What is the most likely cause?
Think about what wait_heartbeat() expects to receive.
The wait_heartbeat() method waits for a heartbeat message from a MAVLink device. If no device is sending heartbeats on the specified UDP port, it will timeout and raise a TimeoutError.
Choose the code snippet that correctly opens a MAVLink connection over a serial port at 57600 baud.
Check the parameter name for baud rate in mavlink_connection.
The correct parameter name is baud. Option A uses it properly. Option A uses baudrate which is invalid. Option A incorrectly appends baudrate in the string. Option A passes baudrate as a positional argument which is not accepted.
Given this code snippet:
from pymavlink import mavutil
master = mavutil.mavlink_connection('udp:127.0.0.1:14550')
messages = []
for _ in range(3):
msg = master.recv_match(blocking=True, timeout=1)
if msg:
messages.append(msg.get_type())
print(len(messages))If the MAVLink device sends exactly 2 messages within the timeout periods, what will be printed?
Count how many messages are appended based on the device's message sending.
The loop tries to receive 3 messages, but only 2 are sent by the device within the timeout. So only 2 messages are appended. The printed length is 2.
