Bird
Raised Fist0
Drone Programmingprogramming~20 mins

Range finder for terrain following in Drone Programming - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Terrain Following Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
Output of range finder distance calculation
What is the output of this code that calculates the distance from the drone to the ground using a range finder reading and drone altitude?
Drone Programming
altitude = 120.5  # meters
range_finder_reading = 15.3  # meters

distance_to_ground = altitude - range_finder_reading
print(f"Distance to ground: {distance_to_ground} meters")
ADistance to ground: 105.2 meters
BDistance to ground: 135.8 meters
CDistance to ground: 120.5 meters
DDistance to ground: 15.3 meters
Attempts:
2 left
💡 Hint
Subtract the range finder reading from the drone's altitude to get the distance to the ground.
🧠 Conceptual
intermediate
1:00remaining
Understanding range finder data for terrain following
Which statement best describes how a range finder helps a drone follow terrain?
AIt measures the distance to the ground so the drone can adjust altitude to maintain a set height.
BIt detects obstacles in front of the drone to avoid collisions.
CIt measures wind speed to stabilize the drone.
DIt records GPS coordinates for navigation.
Attempts:
2 left
💡 Hint
Think about what the range finder measures directly below the drone.
🔧 Debug
advanced
2:00remaining
Identify the error in terrain following altitude adjustment code
What error will this code cause when trying to adjust drone altitude based on range finder data?
Drone Programming
desired_height = 50
range_finder_distance = 45

# Adjust altitude to maintain desired height above ground
new_altitude = desired_height + range_finder_distance
print(f"New altitude: {new_altitude}")
AThe altitude will be set too low because it subtracts instead of adding.
BThe code will cause a syntax error due to missing colon.
CThe code will raise a TypeError because of incompatible types.
DThe altitude will be set too high because it adds desired height and distance instead of subtracting.
Attempts:
2 left
💡 Hint
Think about how altitude relates to desired height and range finder distance.
📝 Syntax
advanced
1:30remaining
Identify the syntax error in range finder data processing
Which option contains the syntax error when trying to create a dictionary of sensor readings?
Drone Programming
sensor_data = {"range_finder": 12.5, "altitude": 100.0, "speed": 5.2}
Asensor_data = {range_finder: 12.5, altitude: 100.0, speed: 5.2}
Bsensor_data = {"range_finder" 12.5, "altitude" 100.0, "speed" 5.2}
Csensor_data = ["range_finder": 12.5, "altitude": 100.0, "speed": 5.2]
Dsensor_data = {"range_finder": 12.5, "altitude": 100.0, "speed": 5.2}
Attempts:
2 left
💡 Hint
Check the punctuation between keys and values in the dictionary.
🚀 Application
expert
2:30remaining
Calculate drone altitude for terrain following with variable terrain
Given a drone flying over terrain where the range finder reading changes as follows: [10, 12, 8, 15, 9] meters, and the drone wants to maintain a constant height of 20 meters above ground, what is the list of altitudes the drone should set to maintain this height?
Drone Programming
range_readings = [10, 12, 8, 15, 9]
desired_height = 20

# Calculate altitudes
altitudes = [reading + desired_height for reading in range_readings]
print(altitudes)
A[20, 20, 20, 20, 20]
B[10, 12, 8, 15, 9]
C[30, 32, 28, 35, 29]
D[-10, -8, -12, -5, -11]
Attempts:
2 left
💡 Hint
Add the desired height to each range finder reading to get the altitude.

Practice

(1/5)
1.

What is the main purpose of a range finder in drone terrain following?

easy
A. To measure the distance between the drone and the ground
B. To control the drone's speed horizontally
C. To detect obstacles in the air above the drone
D. To measure the drone's battery level

Solution

  1. Step 1: Understand the role of a range finder

    A range finder is a sensor that measures how far the drone is from the ground below it.
  2. Step 2: Connect measurement to terrain following

    This distance helps the drone adjust its height to follow the shape of the terrain safely.
  3. Final Answer:

    To measure the distance between the drone and the ground -> Option A
  4. Quick Check:

    Range finder = distance measurement [OK]
Hint: Range finder always measures distance to ground [OK]
Common Mistakes:
  • Confusing range finder with speed sensor
  • Thinking it measures battery or air obstacles
  • Assuming it controls horizontal movement
2.

Which of the following code snippets correctly reads a range finder sensor value in a drone program?

1. distance = range_finder.read()
2. distance = read.range_finder()
3. distance = rangeFinder.readValue()
4. distance = range_finder.get()
easy
A. 2. distance = read.range_finder()
B. 3. distance = rangeFinder.readValue()
C. 1. distance = range_finder.read()
D. 4. distance = range_finder.get()

Solution

  1. Step 1: Identify correct method call syntax

    In drone programming, sensors are often objects with a method called read() to get current values.
  2. Step 2: Check each option for correct syntax

    Option 1 uses range_finder.read(), which is standard and correct. Others use incorrect method names or syntax.
  3. Final Answer:

    1. distance = range_finder.read() -> Option C
  4. Quick Check:

    Sensor read method = read() [OK]
Hint: Sensor reading usually uses .read() method [OK]
Common Mistakes:
  • Using wrong method names like get() or readValue()
  • Incorrect object.method order
  • Confusing variable names with method calls
3.

What will be the output of this code snippet controlling drone height?

distance = 5
if distance < 3:
    action = "ascend"
elif distance > 7:
    action = "descend"
else:
    action = "hold"
print(action)

medium
A. "ascend"
B. "hold"
C. "descend"
D. Error

Solution

  1. Step 1: Evaluate the distance condition

    The distance is 5. Check if 5 < 3 (false), then if 5 > 7 (false).
  2. Step 2: Determine the else branch

    Since both conditions are false, the else branch runs, setting action to "hold".
  3. Final Answer:

    "hold" -> Option B
  4. Quick Check:

    Distance 5 triggers else = hold [OK]
Hint: Check conditions in order, else runs if none match [OK]
Common Mistakes:
  • Choosing ascend or descend incorrectly
  • Confusing comparison operators
  • Assuming error due to syntax
4.

Find the error in this drone height control code:

distance = range_finder.read()
if distance < 2
    action = "ascend"
else:
    action = "descend"
print(action)

medium
A. range_finder.read() is invalid
B. Wrong comparison operator
C. Incorrect indentation of else
D. Missing colon after if condition

Solution

  1. Step 1: Check syntax of if statement

    The if statement is missing a colon (:) at the end of the condition line, which is required in Python-like syntax.
  2. Step 2: Verify other parts

    Comparison operator and indentation are correct. The method call is valid assuming range_finder object exists.
  3. Final Answer:

    Missing colon after if condition -> Option D
  4. Quick Check:

    if statement needs colon : [OK]
Hint: Always put colon after if condition [OK]
Common Mistakes:
  • Forgetting colon after if
  • Misaligning else indentation
  • Changing comparison operators unnecessarily
5.

You want the drone to maintain a height of 4 meters above ground using the range finder. Which code snippet correctly adjusts the drone's vertical speed based on the measured distance?

distance = range_finder.read()
if distance < 4:
    vertical_speed = 1  # ascend
elif distance > 4:
    vertical_speed = -1 # descend
else:
    vertical_speed = 0  # hold steady
print(vertical_speed)
hard
A. This code correctly sets vertical_speed to keep 4m height
B. The conditions should use <= and >= instead of < and >
C. vertical_speed values should be reversed for ascend and descend
D. The else block is unnecessary and should be removed

Solution

  1. Step 1: Understand the desired behavior

    The drone should ascend if below 4m, descend if above 4m, and hold if exactly 4m.
  2. Step 2: Check code logic

    If distance < 4, vertical_speed = 1 (ascend) is correct. If distance > 4, vertical_speed = -1 (descend) is correct. Else holds steady at 0.
  3. Final Answer:

    This code correctly sets vertical_speed to keep 4m height -> Option A
  4. Quick Check:

    Conditions match desired height control [OK]
Hint: Ascend if below target, descend if above, else hold [OK]
Common Mistakes:
  • Reversing ascend and descend speeds
  • Removing else block causing no hold state
  • Using <= or >= unnecessarily