What will be the output of the following Python snippet that simulates connecting to a drone via MAVLink using Mission Planner's connection parameters?
connection_string = 'COM3'
baud_rate = 57600
if connection_string.startswith('COM') and baud_rate == 57600:
print('Connected to drone on ' + connection_string)
else:
print('Connection failed')connection_string = 'COM3' baud_rate = 57600 if connection_string.startswith('COM') and baud_rate == 57600: print('Connected to drone on ' + connection_string) else: print('Connection failed')
Check the condition that verifies the connection string and baud rate.
The code checks if the connection string starts with 'COM' and the baud rate equals 57600. Both are true, so it prints the success message.
Which file format does QGroundControl primarily use to save and load mission plans?
Think about a format that is easy to read and widely used for structured data.
QGroundControl uses JSON files to save and load mission plans because JSON is lightweight and easy to parse.
Given the following Python code snippet intended to connect to a drone using Mission Planner's API, what error will it raise?
import time
connection = connect('COM5', 115200)
time.sleep(5)
status = connection.status
print(status)Assume connect is not defined anywhere.
import time connection = connect('COM5', 115200) time.sleep(5) status = connection.status print(status)
Check if all functions used are defined or imported.
The code calls connect which is not defined or imported, so Python raises a NameError.
You have a QGroundControl mission file in JSON format with the following snippet:
{
"mission": {
"items": [
{"command": 16, "param1": 0, "param2": 0},
{"command": 22, "param1": 0, "param2": 0},
{"command": 16, "param1": 0, "param2": 0}
]
}
}How many waypoints does this mission contain?
Count the number of items with command 16 (waypoints).
The mission has three items: two with command 16 (waypoints) and one with command 22 (takeoff).
What is the output of this Python code that parses a QGroundControl mission JSON and counts commands with code 16?
import json
mission_json = '''{
"mission": {
"items": [
{"command": 16, "param1": 0},
{"command": 22, "param1": 0},
{"command": 16, "param1": 1},
{"command": 16, "param1": 2}
]
}
}'''
mission = json.loads(mission_json)
count = sum(1 for item in mission['mission']['items'] if item['command'] == 16)
print(count)import json mission_json = '''{ "mission": { "items": [ {"command": 16, "param1": 0}, {"command": 22, "param1": 0}, {"command": 16, "param1": 1}, {"command": 16, "param1": 2} ] } }''' mission = json.loads(mission_json) count = sum(1 for item in mission['mission']['items'] if item['command'] == 16) print(count)
Count how many items have the command value 16.
There are three items with command 16, so the output is 3.
