Bird
Raised Fist0
Drone Programmingprogramming~10 mins

Speed control during mission in Drone Programming - Step-by-Step Execution

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
Concept Flow - Speed control during mission
Start Mission
Set Initial Speed
Check Mission Progress
Adjust Speed?
NoContinue at Current Speed
Yes
Update Speed
Check if Mission Complete
No
End Mission
Back to Check Mission Progress
The drone starts the mission with an initial speed, then continuously checks progress to decide if speed needs adjustment, repeating until the mission ends.
Execution Sample
Drone Programming
speed = 5  # initial speed in m/s
while not mission_complete():
    progress = get_progress()
    if progress > 50:
        speed = 3  # slow down after halfway
    move_drone(speed)
This code sets an initial speed, then slows the drone down after it passes halfway through the mission.
Execution Table
Stepprogress (%)Condition (progress > 50)Speed (m/s)Action
110False5Move drone at speed 5
230False5Move drone at speed 5
355True3Slow down to speed 3
470True3Move drone at speed 3
590True3Move drone at speed 3
6100True3Mission complete, stop
💡 Mission progress reached 100%, loop ends
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5Final
speed5553333
progress01030557090100
Key Moments - 2 Insights
Why does the speed change only after progress passes 50%?
Because the condition 'progress > 50' becomes True at step 3 (progress 55), triggering the speed update as shown in the execution_table.
Does the speed ever increase again after slowing down?
No, once speed is set to 3 at step 3, it stays at 3 until mission ends, as no condition changes it back.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the speed at step 2?
A3 m/s
B5 m/s
C0 m/s
DCannot tell
💡 Hint
Check the 'Speed (m/s)' column at step 2 in the execution_table.
At which step does the condition 'progress > 50' become true?
AStep 5
BStep 1
CStep 3
DStep 6
💡 Hint
Look at the 'Condition (progress > 50)' column in the execution_table.
If the initial speed was 6 instead of 5, what would be the speed at step 1?
A6 m/s
B5 m/s
C3 m/s
D0 m/s
💡 Hint
Refer to variable_tracker for 'speed' initial value and how it changes.
Concept Snapshot
Speed control during mission:
- Start mission with initial speed
- Continuously check mission progress
- If progress passes threshold (e.g., 50%), adjust speed
- Continue until mission completes
- Use conditions inside loop to update speed dynamically
Full Transcript
This visual trace shows how a drone controls its speed during a mission. It starts with an initial speed of 5 meters per second. As the mission progresses, the program checks the progress percentage. When progress exceeds 50%, the speed is reduced to 3 meters per second to slow down the drone. This change happens at step 3 in the execution table. The speed remains at 3 until the mission completes at 100% progress. The variable tracker shows how 'speed' and 'progress' change at each step. Key moments clarify why speed changes only after halfway and why it does not increase again. The quiz questions help reinforce understanding by asking about speed values and condition checks at specific steps.

Practice

(1/5)
1. What is the main reason to adjust the drone's speed during a mission?
easy
A. To save battery by flying as fast as possible
B. To change the drone's color
C. To make the drone hover in place
D. To fly slower near obstacles for safety

Solution

  1. Step 1: Understand speed control purpose

    Speed control helps adjust how fast the drone flies to match mission needs.
  2. Step 2: Identify safety reason

    Flying slower near obstacles reduces crash risk and improves control.
  3. Final Answer:

    To fly slower near obstacles for safety -> Option D
  4. Quick Check:

    Safety needs slower speed near obstacles = B [OK]
Hint: Slower speed near obstacles means safer flight [OK]
Common Mistakes:
  • Thinking faster speed always saves battery
  • Confusing speed control with hovering
  • Believing speed changes drone color
2. Which of the following is the correct way to set the drone speed to 5 meters per second in code?
easy
A. setSpeed(drone, 5)
B. drone.speed = '5mps'
C. drone.setSpeed(5)
D. drone.speed(5)

Solution

  1. Step 1: Identify correct method syntax

    The method to set speed is called on the drone object with a number argument.
  2. Step 2: Check each option

    drone.setSpeed(5) uses drone.setSpeed(5) which is correct syntax for setting speed to 5.
  3. Final Answer:

    drone.setSpeed(5) -> Option C
  4. Quick Check:

    Method call with number argument = A [OK]
Hint: Use object.method(value) to set speed [OK]
Common Mistakes:
  • Using string instead of number for speed
  • Calling speed as a function instead of method
  • Passing drone as argument instead of calling method on it
3. What will be the output of this code snippet?
drone.setSpeed(3)
print(drone.speed)
medium
A. None
B. 3
C. Error: speed attribute not found
D. drone.setSpeed(3)

Solution

  1. Step 1: Understand setSpeed effect

    Calling drone.setSpeed(3) sets the drone's speed attribute to 3.
  2. Step 2: Print drone.speed value

    Printing drone.speed outputs the current speed value, which is 3.
  3. Final Answer:

    3 -> Option B
  4. Quick Check:

    Set speed to 3, print speed = 3 [OK]
Hint: setSpeed changes speed attribute; print shows it [OK]
Common Mistakes:
  • Expecting method call to print
  • Assuming speed attribute is missing
  • Confusing method name with attribute
4. The following code is intended to set the drone speed to 10 m/s but causes an error. What is the problem?
drone.setspeed(10)
medium
A. Method name is case-sensitive; should be setSpeed
B. Speed value 10 is too high and causes error
C. Missing parentheses after method name
D. drone object is not defined

Solution

  1. Step 1: Check method name spelling

    Method names are case-sensitive; 'setspeed' is incorrect, correct is 'setSpeed'.
  2. Step 2: Confirm other options

    Speed 10 is valid, parentheses are present, and drone object assumed defined.
  3. Final Answer:

    Method name is case-sensitive; should be setSpeed -> Option A
  4. Quick Check:

    Case-sensitive method names cause errors = A [OK]
Hint: Check exact method name spelling and case [OK]
Common Mistakes:
  • Ignoring case sensitivity in method names
  • Assuming value too high causes error
  • Forgetting parentheses after method
5. You want the drone to fly slower near obstacles and faster in open areas during a mission. Which code snippet correctly changes speed based on distance to obstacle?
distance = drone.getDistance()
if distance < 5:
    drone.setSpeed(2)
else:
    drone.setSpeed(8)
hard
A. Correctly sets speed slower near obstacles and faster otherwise
B. Sets speed faster near obstacles, which is unsafe
C. Uses wrong comparison operator; should be distance > 5
D. Does not change speed at all

Solution

  1. Step 1: Understand distance check

    Code checks if distance to obstacle is less than 5 meters.
  2. Step 2: Analyze speed settings

    If close (distance < 5), speed is set to 2 (slow). Else speed is 8 (fast). This matches safe speed control.
  3. Final Answer:

    Correctly sets speed slower near obstacles and faster otherwise -> Option A
  4. Quick Check:

    Distance check controls speed safely = C [OK]
Hint: Use if distance < threshold for slower speed [OK]
Common Mistakes:
  • Reversing comparison operator
  • Setting faster speed near obstacles
  • Not calling setSpeed inside condition