Introduction
When controlling a drone, it is important to know if the commands you send are received and understood. Without confirmation, you might not be sure if the drone is following your instructions or if there was a problem.
Jump into concepts and practice - no test required
Imagine you ask a friend to pass you a book across a noisy room. You shout the request, but you wait for your friend to nod or say 'got it' before you relax. If you don't get a response, you ask again or check if they heard you.
┌───────────────┐ Command ┌───────────────┐
│ Controller │────────────────────▶│ Drone │
└───────────────┘ └───────────────┘
▲ │
│ Acknowledgment │
│◀──────────────────────────────────┘
│
Timeout & Retry if no acknowledgment
What is the main purpose of command acknowledgment in drone programming?
Which of the following code snippets correctly checks if a drone command acknowledgment is received?
if response == 'ACK':
print('Command confirmed')
else:
print('No confirmation')What will be the output of this code snippet handling drone command acknowledgment?
response = 'NACK'
if response == 'ACK':
print('Command successful')
else:
print('Command failed')Identify the error in this drone command acknowledgment code snippet:
response = get_drone_response()
if response = 'ACK':
print('Command confirmed')
else:
print('No confirmation')You want to send a command to a drone and wait for acknowledgment with a timeout of 5 seconds. Which approach correctly handles this?
import time
def send_command_with_ack(command):
send_command(command)
start = time.time()
while time.time() - start < 5:
response = get_drone_response()
if response == 'ACK':
return 'Success'
return 'Timeout'