Consider a drone SITL simulation script that runs a simple flight plan. What will be the output after running this code snippet?
def simulate_flight(): waypoints = [(0,0), (10,0), (10,10), (0,10)] for i, point in enumerate(waypoints): print(f"Flying to waypoint {i+1}: {point}") return "Flight complete" result = simulate_flight() print(result)
Remember that enumerate starts counting from 0 by default, but the code adds 1 to the index.
The code loops through all 4 waypoints, printing each with a 1-based index. Then it prints 'Flight complete'. Option C matches this exactly.
What is the main purpose of using Software-In-The-Loop (SITL) simulation in drone programming?
Think about why developers want to test code before flying a real drone.
SITL allows developers to run and test drone control software in a computer simulation, avoiding risks and costs of real flights. It does not replace hardware or control real drones directly.
Identify the error in this SITL flight path code snippet that causes the drone to skip the last waypoint.
waypoints = [(0,0), (5,5), (10,10)] for i in range(len(waypoints)-1): print(f"Going to waypoint {i+1}: {waypoints[i]}")
Check how the range function is used with the length of the list.
The code uses range(len(waypoints)-1) which excludes the last index. The loop should use range(len(waypoints)) to include all waypoints.
Which option contains a syntax error that will prevent the SITL script from running?
commands = ['takeoff', 'hover', 'land'] for cmd in commands print(f"Executing {cmd}")
Look for missing punctuation in the for loop syntax.
Option D is missing the colon ':' after the for statement, causing a SyntaxError. The others have correct syntax.
Given this SITL simulation code, what is the final battery percentage after executing all commands?
class DroneSim: def __init__(self): self.battery = 100 def fly(self, distance): self.battery -= distance * 2 def hover(self, time): self.battery -= time sim = DroneSim() sim.fly(10) sim.hover(5) sim.fly(10) final_battery = sim.battery print(final_battery)
Calculate battery drain step by step: flying drains 2% per distance unit, hovering drains 1% per time unit.
Starting at 100%: fly(10) drains 20% to 80%, hover(5) drains 5% to 75%, fly(10) drains 20% to 55%. Final battery is 55%.