📖 Scenario: You are setting up a drone's remote control (RC) transmitter. The transmitter sends signals for different controls like throttle, yaw, pitch, and roll. Each control channel has a specific range of values that the drone understands.To make sure the drone flies correctly, you need to configure the transmitter channels with their correct minimum and maximum values.
🎯 Goal: Build a program that stores the RC transmitter channel ranges, sets a safety threshold, filters channels that exceed this threshold, and then prints the filtered channels.
📋 What You'll Learn
Create a dictionary called channels with exact keys and values for throttle, yaw, pitch, and roll.
Create a variable called safety_threshold with the exact value 1500.
Use a dictionary comprehension to create a new dictionary called active_channels that includes only channels with values greater than safety_threshold.
Print the active_channels dictionary.
💡 Why This Matters
🌍 Real World
This project simulates configuring an RC transmitter for a drone, which is essential for safe and precise drone control.
💼 Career
Understanding how to manage and filter control signals is important for drone programming, robotics, and embedded systems development.
Progress0 / 4 steps
1
Create the RC transmitter channels dictionary
Create a dictionary called channels with these exact entries: 'throttle': 1200, 'yaw': 1600, 'pitch': 1400, 'roll': 1700.
Drone Programming
Hint
Use curly braces {} to create a dictionary. Separate keys and values with a colon :. Separate items with commas.
2
Set the safety threshold value
Create a variable called safety_threshold and set it to the integer value 1500.
Drone Programming
Hint
Use the assignment operator = to set the variable.
3
Filter channels above the safety threshold
Use a dictionary comprehension to create a new dictionary called active_channels that includes only the channels from channels where the value is greater than safety_threshold. Use for channel, value in channels.items() in your comprehension.
Drone Programming
Hint
Dictionary comprehension syntax: {key: value for key, value in dict.items() if condition}.
4
Print the active channels
Write a print statement to display the active_channels dictionary.
Drone Programming
Hint
Use print(active_channels) to show the filtered dictionary.
Practice
(1/5)
1. What is the main purpose of configuring an RC transmitter for a drone?
easy
A. To update the drone's firmware automatically
B. To charge the drone's battery
C. To connect the remote control to the drone and assign control channels
D. To change the drone's camera settings remotely
Solution
Step 1: Understand RC transmitter role
The RC transmitter sends signals to the drone to control its movements.
Step 2: Identify configuration purpose
Configuring the transmitter means connecting it to the drone and setting channels for controls like throttle and yaw.
Final Answer:
To connect the remote control to the drone and assign control channels -> Option C
Quick Check:
RC transmitter configuration = connect and assign channels [OK]
Hint: RC transmitter setup links remote to drone controls [OK]
Common Mistakes:
Confusing transmitter setup with battery charging
Thinking it updates drone software automatically
Assuming it controls camera settings
2. Which of the following is the correct syntax to assign channel 3 to throttle in a drone's RC transmitter configuration code snippet?
easy
A. transmitter.setChannel(3, 'throttle')
B. transmitter.assign('throttle', 3)
C. setChannel(throttle, 3)
D. channel3 = throttle
Solution
Step 1: Recognize correct method call format
The method to assign a channel usually follows the pattern object.method(channelNumber, controlName).
Step 2: Match syntax to options
transmitter.setChannel(3, 'throttle') matches this pattern: transmitter.setChannel(3, 'throttle'). Others have incorrect order or syntax.
B. Channel 3 is already assigned, causing a duplicate key error
C. transmitter.channels is not a valid attribute
D. The control name 'throttle' is missing quotes, causing a NameError
Solution
Step 1: Identify error cause in code
The third setChannel call uses throttle without quotes, so Python treats it as a variable, causing NameError.
Step 2: Confirm correct syntax
Control names must be strings in quotes, like 'throttle'.
Final Answer:
The control name 'throttle' is missing quotes, causing a NameError -> Option D
Quick Check:
String literals need quotes around control names [OK]
Hint: Always quote control names as strings in setChannel calls [OK]
Common Mistakes:
Forgetting quotes around control names
Assuming duplicate keys cause error here
Thinking setChannel needs more arguments
5. You want to configure an RC transmitter to control a drone with these channels: 1 for roll, 2 for pitch, 3 for throttle, and 4 for yaw. You also want to save this configuration for future use. Which code snippet correctly sets and saves these channels?
hard
A. transmitter.setChannel(1, 'roll')
transmitter.setChannel(2, 'pitch')
transmitter.setChannel(3, 'throttle')
transmitter.setChannel(4, 'yaw')
transmitter.saveConfig()
B. transmitter.assignChannel('roll', 1)
transmitter.assignChannel('pitch', 2)
transmitter.assignChannel('throttle', 3)
transmitter.assignChannel('yaw', 4)
transmitter.save()
C. setChannel(1, 'roll')
setChannel(2, 'pitch')
setChannel(3, 'throttle')
setChannel(4, 'yaw')
saveConfig()
D. transmitter.channels = {1:'roll', 2:'pitch', 3:'throttle', 4:'yaw'}
transmitter.saveConfig()
Solution
Step 1: Check channel assignment syntax
Correct method is transmitter.setChannel(channelNumber, controlName) repeated for each channel.
Step 2: Verify saving method
transmitter.saveConfig() is the correct method to save the configuration. Direct assignment to transmitter.channels may miss internal setup. Incorrect approaches use wrong method names or missing object prefix.