Receiving telemetry data in Drone Programming - Full Explanation
Think of a drone as a friend on a long hike who sends you text messages about where they are, how tired they feel, and if they need help. You rely on these messages to know when to meet them or send supplies.
┌─────────────┐ wireless ┌───────────────┐ │ Drone │ ────────────────▶ │ Controller │ │ (sensors) │ │ (receiver & │ │ │ │ display) │ └─────────────┘ └───────────────┘
Practice
What does telemetry data from a drone usually include?
Solution
Step 1: Understand telemetry data purpose
Telemetry data provides real-time information about the drone's current state.Step 2: Identify typical telemetry contents
Common telemetry includes position coordinates and battery level, not unrelated info like color or weather.Final Answer:
Information about the drone's position and battery status -> Option AQuick Check:
Telemetry = position + battery [OK]
- Confusing telemetry with unrelated data like weather
- Thinking telemetry includes pilot personal info
- Assuming telemetry is about drone appearance
Which of the following is the correct way to receive telemetry data from a drone object named drone?
?Solution
Step 1: Identify method call syntax
To call a method on an object, use dot notation with parentheses: object.method()Step 2: Match method name exactly
The correct method isget_telemetry(), sodrone.get_telemetry()is correct.Final Answer:
telemetry = drone.get_telemetry() -> Option BQuick Check:
Method call syntax = drone.get_telemetry() [OK]
- Missing parentheses when calling method
- Using wrong method name or syntax
- Trying to call method without object
What will be the output of this code snippet?
drone = Drone()
telemetry = drone.get_telemetry()
print(telemetry['battery'])Assume get_telemetry() returns {'position': (10, 20), 'battery': 85}.
Solution
Step 1: Understand returned telemetry dictionary
The telemetry dictionary has keys 'position' and 'battery' with values (10, 20) and 85 respectively.Step 2: Access the 'battery' key value
Printing telemetry['battery'] outputs 85, the battery percentage.Final Answer:
85 -> Option DQuick Check:
telemetry['battery'] = 85 [OK]
- Confusing 'position' with 'battery' key
- Trying to print telemetry without key
- Assuming output is a tuple instead of number
Find the error in this code that tries to print the drone's position from telemetry data:
telemetry = drone.get_telemetry()
print(telemetry.position)Solution
Step 1: Check how telemetry data is accessed
Telemetry is a dictionary, so keys must be accessed with square brackets, not dot notation.Step 2: Identify the error cause
Usingtelemetry.positioncauses an AttributeError because dictionaries don't support dot notation.Final Answer:
Accessing dictionary key with dot notation causes error -> Option AQuick Check:
Dictionary keys need brackets, not dots [OK]
- Using dot notation on dictionary keys
- Forgetting parentheses on method call
- Assuming telemetry is an object with attributes
You want to check if the drone's battery is below 20% and print a warning. Which code correctly does this using telemetry data?
telemetry = drone.get_telemetry()
?Solution
Step 1: Access battery level correctly from telemetry
Telemetry is a dictionary, so use square brackets: telemetry['battery'].Step 2: Write condition to check if battery is below 20
The condition should be< 20to detect low battery and print warning.Final Answer:
if telemetry['battery'] < 20: print('Warning: Low battery!') -> Option CQuick Check:
Check battery < 20 with brackets [OK]
- Using dot notation to access battery
- Checking battery > 20 instead of < 20
- Accessing battery directly from drone object
Ready to prove it?
Pass the test and this pattern moves unknown
