Bird
Raised Fist0
Drone Programmingprogramming~20 mins

ESC (Electronic Speed Controller) role in Drone Programming - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
ESC Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of ESC signal processing code
What is the output of this code simulating ESC signal processing for motor speed control?
Drone Programming
def esc_signal(pwm_value):
    # PWM value from 1000 to 2000 microseconds
    if pwm_value < 1100:
        return 0  # motor off
    elif pwm_value > 1900:
        return 100  # max speed
    else:
        # linear scale between 0 and 100
        return (pwm_value - 1100) / 8

print(int(esc_signal(1050)))
print(int(esc_signal(1500)))
print(int(esc_signal(1950)))
A0\n48\n100
B5\n50\n100
C0\n50\n95
D0\n50\n100
Attempts:
2 left
💡 Hint
Think about how the PWM value maps to motor speed in the code.
🧠 Conceptual
intermediate
1:30remaining
Primary role of an ESC in a drone
Which option best describes the primary role of an ESC (Electronic Speed Controller) in a drone?
AConvert battery voltage to a stable 5V supply for sensors
BTransmit flight commands wirelessly to the drone
CControl motor speed by adjusting power based on input signals
DMeasure altitude using barometric pressure sensors
Attempts:
2 left
💡 Hint
Think about what controls the motor speed in response to commands.
🔧 Debug
advanced
2:00remaining
Identify the error in ESC signal scaling code
What error will this ESC signal scaling code cause when run?
Drone Programming
def esc_speed(pwm):
    if pwm < 1100:
        return 0
    elif pwm > 1900:
        return 100
    else:
        return (pwm - 1100) / 0

print(esc_speed(1500))
ATypeError
BZeroDivisionError
CValueError
DNo error, outputs 50
Attempts:
2 left
💡 Hint
Look carefully at the division operation in the else block.
📝 Syntax
advanced
1:30remaining
Syntax error in ESC control function
Which option contains the correct syntax for this ESC control function?
Drone Programming
def esc_control(pwm):
    if pwm < 1100
        return 0
    elif pwm > 1900:
        return 100
    else:
        return (pwm - 1100) / 8
Adef esc_control(pwm):\n if pwm < 1100:\n return 0\n elif pwm > 1900:\n return 100\n else:\n return (pwm - 1100) / 8
Bdef esc_control(pwm):\n if pwm < 1100\n return 0\n elif pwm > 1900\n return 100\n else\n return (pwm - 1100) / 8
Cdef esc_control(pwm):\n if pwm < 1100:\n return 0\n elif pwm > 1900\n return 100\n else:\n return (pwm - 1100) / 8
Ddef esc_control(pwm):\n if pwm < 1100:\n return 0\n elif pwm > 1900:\n return 100\n else\n return (pwm - 1100) / 8
Attempts:
2 left
💡 Hint
Check where colons are missing after if and else statements.
🚀 Application
expert
2:00remaining
Calculate motor speed from ESC PWM input
Given an ESC that maps PWM input from 1100 to 1900 microseconds linearly to motor speed 0 to 100%, what is the motor speed for PWM input 1700?
A75%
B80%
C50%
D62.5%
Attempts:
2 left
💡 Hint
Calculate the fraction of the way 1700 is between 1100 and 1900, then multiply by 100.

Practice

(1/5)
1. What is the main role of an ESC (Electronic Speed Controller) in drone programming?
easy
A. To control the speed and direction of the drone's motors
B. To capture images during flight
C. To provide GPS location data
D. To manage the drone's battery charging

Solution

  1. Step 1: Understand ESC function

    An ESC controls how fast and in which direction a motor spins.
  2. Step 2: Compare options to ESC role

    Only controlling motor speed and direction matches ESC's purpose.
  3. Final Answer:

    To control the speed and direction of the drone's motors -> Option A
  4. Quick Check:

    ESC = motor speed and direction control [OK]
Hint: ESC always controls motor speed and direction [OK]
Common Mistakes:
  • Confusing ESC with camera or GPS functions
  • Thinking ESC manages battery charging
  • Assuming ESC controls drone navigation
2. Which of the following is the correct way to set motor speed using an ESC command in drone programming?
easy
A. esc.speed = 'fast'
B. setSpeed(esc, 'high')
C. esc.setSpeed(100)
D. esc.set_speed(100%)

Solution

  1. Step 1: Identify correct syntax for setting speed

    The method esc.setSpeed(100) uses a numeric value and proper method call.
  2. Step 2: Check other options for syntax errors

    The other options use wrong syntax: strings instead of numbers, incorrect function calls, or invalid parameters like percentages.
  3. Final Answer:

    esc.setSpeed(100) -> Option C
  4. Quick Check:

    Correct method call with numeric speed [OK]
Hint: Use method calls with numeric speed values [OK]
Common Mistakes:
  • Using strings instead of numbers for speed
  • Wrong method names or syntax
  • Including percentage signs in parameters
3. Given this code snippet controlling an ESC:
esc.setSpeed(50)
esc.setDirection('reverse')
print(esc.getSpeed())
What will be the output?
medium
A. 'reverse'
B. 50
C. Error: Invalid method
D. 0

Solution

  1. Step 1: Analyze speed setting

    The speed is set to 50 with esc.setSpeed(50).
  2. Step 2: Understand getSpeed output

    esc.getSpeed() returns the current speed, which is 50.
  3. Final Answer:

    50 -> Option B
  4. Quick Check:

    Speed set to 50, getSpeed returns 50 [OK]
Hint: getSpeed returns last set speed value [OK]
Common Mistakes:
  • Confusing direction with speed output
  • Assuming getSpeed returns direction
  • Expecting error due to direction command
4. Identify the error in this ESC control code:
esc.setSpeed = 75
esc.setDirection('forward')
medium
A. Missing semicolon after setSpeed
B. Wrong direction value 'forward'
C. esc object not defined
D. Using assignment instead of method call for setSpeed

Solution

  1. Step 1: Check setSpeed usage

    esc.setSpeed = 75 assigns a value instead of calling a method.
  2. Step 2: Correct method call syntax

    It should be esc.setSpeed(75) to set speed properly.
  3. Final Answer:

    Using assignment instead of method call for setSpeed -> Option D
  4. Quick Check:

    Method call needed, not assignment [OK]
Hint: Use parentheses () to call methods, not = [OK]
Common Mistakes:
  • Assigning value instead of calling method
  • Assuming direction value 'forward' is invalid
  • Forgetting parentheses in method calls
5. You want to program an ESC to smoothly stop the drone's motor. Which sequence of commands is best?
hard
A. esc.setSpeed(50) esc.setSpeed(0)
B. esc.setSpeed(100) esc.setSpeed(0)
C. esc.setDirection('reverse') esc.setSpeed(0)
D. esc.setSpeed(0) esc.setDirection('stop')

Solution

  1. Step 1: Understand smooth stopping

    Gradually reducing speed from a moderate value to zero helps smooth stop.
  2. Step 2: Analyze options for smoothness

    esc.setSpeed(50) esc.setSpeed(0) reduces speed from 50 to 0, which is smooth. Others either jump or use invalid direction.
  3. Final Answer:

    esc.setSpeed(50) followed by esc.setSpeed(0) for smooth stop -> Option A
  4. Quick Check:

    Smooth stop = gradual speed decrease [OK]
Hint: Reduce speed gradually to zero for smooth stop [OK]
Common Mistakes:
  • Setting speed directly to 0 from max
  • Using 'stop' as a direction value
  • Reversing direction to stop motor
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard