Bird
Raised Fist0
Drone Programmingprogramming~10 mins

Formation flying basics in Drone Programming - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Formation flying basics
Initialize leader drone position
↓
Initialize follower drones positions
↓
Calculate relative positions
↓
Send position commands to followers
↓
Followers adjust positions
↓
Check formation accuracy
↓
Maintain formation
The leader drone sets its position, followers calculate where to be relative to leader, adjust, and maintain formation.
Execution Sample
Drone Programming
leader_pos = (0, 0)
follower_offsets = [(1, 0), (0, 1), (-1, 0)]
followers_pos = []
for offset in follower_offsets:
    pos = (leader_pos[0] + offset[0], leader_pos[1] + offset[1])
    followers_pos.append(pos)
print(followers_pos)
Calculate follower drones' positions relative to the leader and print them.
Execution Table
Stepoffsetpos calculationfollowers_pos after appendOutput
1(1, 0)(0+1, 0+0) = (1, 0)[(1, 0)]
2(0, 1)(0+0, 0+1) = (0, 1)[(1, 0), (0, 1)]
3(-1, 0)(0-1, 0+0) = (-1, 0)[(1, 0), (0, 1), (-1, 0)]
4N/AN/AN/A[(1, 0), (0, 1), (-1, 0)]
💡 All follower positions calculated and stored, loop ends.
Variable Tracker
VariableStartAfter 1After 2After 3Final
leader_pos(0, 0)(0, 0)(0, 0)(0, 0)(0, 0)
offsetN/A(1, 0)(0, 1)(-1, 0)N/A
posN/A(1, 0)(0, 1)(-1, 0)N/A
followers_pos[][(1, 0)][(1, 0), (0, 1)][(1, 0), (0, 1), (-1, 0)][(1, 0), (0, 1), (-1, 0)]
Key Moments - 3 Insights
Why do we add the offset to the leader's position?
Because each follower drone's position is relative to the leader's position, adding the offset places followers correctly around the leader as shown in execution_table steps 1-3.
What happens if we forget to append the calculated position to followers_pos?
The followers_pos list would remain empty, so no follower positions would be stored or used, which means no formation can be maintained (see execution_table where followers_pos updates).
Why does the loop stop after processing all offsets?
Because the loop iterates over each offset once, and after the last offset is processed (step 3), there are no more offsets, so the loop ends (exit_note).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 2, what is the value of pos?
A(0, 1)
B(1, 0)
C(-1, 0)
D(0, 0)
💡 Hint
Check the 'pos calculation' column at step 2 in execution_table.
At which step does followers_pos contain [(1, 0), (0, 1)]?
AAfter step 3
BAfter step 1
CAfter step 2
DAt the start
💡 Hint
Look at the 'followers_pos after append' column in execution_table.
If leader_pos changed to (2, 2), what would pos be at step 1?
A(2, 3)
B(3, 2)
C(1, 0)
D(2, 2)
💡 Hint
Add offset (1, 0) to new leader_pos (2, 2) as shown in execution_table pos calculation.
Concept Snapshot
Formation flying basics:
- Leader drone sets position.
- Followers use offsets to calculate their positions.
- Positions = leader_pos + offset.
- Followers adjust to maintain formation.
- Loop through offsets to update all followers.
Full Transcript
This visual trace shows how formation flying works in drone programming. First, the leader drone's position is set at (0, 0). Then, follower drones have offsets that define their positions relative to the leader. The program loops through each offset, adds it to the leader's position to find each follower's position, and stores these positions in a list. The execution table shows each step's calculation and how the followers_pos list grows. Key moments clarify why offsets are added and why appending positions is important. The quiz tests understanding of position calculations and list updates. This step-by-step helps beginners see how drones maintain formation by calculating relative positions.

Practice

(1/5)
1. What is the main purpose of formation flying in drone programming?
easy
A. To make drones move together in set positions
B. To make drones fly randomly
C. To make drones land immediately
D. To make drones avoid flying

Solution

  1. Step 1: Understand formation flying concept

    Formation flying means drones keep specific positions relative to each other.
  2. Step 2: Identify the main goal

    The goal is to move drones together in a planned pattern, not randomly or to stop flying.
  3. Final Answer:

    To make drones move together in set positions -> Option A
  4. Quick Check:

    Formation flying = moving together [OK]
Hint: Formation flying means drones move together [OK]
Common Mistakes:
  • Thinking drones fly randomly
  • Confusing formation flying with landing
  • Assuming drones avoid flying
2. Which of the following is the correct way to represent a drone's position in a formation list in Python?
easy
A. drone_positions = 0, 0, 1, 1, 2, 2
B. drone_positions = {0, 0, 1, 1, 2, 2}
C. drone_positions = [(0, 0), (1, 1), (2, 2)]
D. drone_positions = '0,0;1,1;2,2'

Solution

  1. Step 1: Identify correct data structure for positions

    Positions are pairs of coordinates, best stored as tuples inside a list.
  2. Step 2: Check each option

    drone_positions = [(0, 0), (1, 1), (2, 2)] uses a list of tuples, which is correct. Others use sets, strings, or invalid formats.
  3. Final Answer:

    drone_positions = [(0, 0), (1, 1), (2, 2)] -> Option C
  4. Quick Check:

    Positions as list of tuples = drone_positions = [(0, 0), (1, 1), (2, 2)] [OK]
Hint: Use list of tuples for positions [OK]
Common Mistakes:
  • Using sets instead of lists
  • Using strings instead of coordinate pairs
  • Not grouping coordinates as tuples
3. What will be the output of this code snippet?
positions = [(0,0), (1,1), (2,2)]
for i, pos in enumerate(positions):
    print(f"Drone {i} flies to {pos}")
medium
A. Drone 1 flies to (0, 0) Drone 2 flies to (1, 1) Drone 3 flies to (2, 2)
B. Drone 0 flies to (0, 0) Drone 1 flies to (1, 1) Drone 2 flies to (2, 2)
C. Drone 0 flies to 0 Drone 1 flies to 1 Drone 2 flies to 2
D. Error: enumerate() not defined

Solution

  1. Step 1: Understand enumerate usage

    enumerate gives index and value from the list; here index is drone number, value is position tuple.
  2. Step 2: Trace the loop output

    For i=0, pos=(0,0); i=1, pos=(1,1); i=2, pos=(2,2). The print statement formats these correctly.
  3. Final Answer:

    Drone 0 flies to (0, 0) Drone 1 flies to (1, 1) Drone 2 flies to (2, 2) -> Option B
  4. Quick Check:

    enumerate index + position tuple = Drone 0 flies to (0, 0) Drone 1 flies to (1, 1) Drone 2 flies to (2, 2) [OK]
Hint: enumerate gives index and item together [OK]
Common Mistakes:
  • Starting drone count at 1 instead of 0
  • Printing only numbers, not tuples
  • Assuming enumerate is undefined
4. Identify the error in this code for sending commands to drones:
drones = ['D1', 'D2', 'D3']
positions = [(0,0), (1,1), (2,2)]
for i in range(len(drones)):
    print(f"Send {drones[i]} to position {positions}")
medium
A. print statement missing parentheses
B. drones list is empty
C. range(len(drones)) is invalid syntax
D. positions should be positions[i] to get each drone's position

Solution

  1. Step 1: Check loop and indexing

    Loop correctly iterates over drone indices, but positions is printed as whole list, not single position.
  2. Step 2: Fix position indexing

    Use positions[i] to get the matching position for each drone.
  3. Final Answer:

    positions should be positions[i] to get each drone's position -> Option D
  4. Quick Check:

    Match drone with single position = positions should be positions[i] to get each drone's position [OK]
Hint: Index positions with i to match drones [OK]
Common Mistakes:
  • Printing whole positions list each time
  • Assuming range(len(drones)) is wrong
  • Forgetting to index positions
5. You want to program a formation where drones fly in a V shape. Which code snippet correctly assigns positions for 5 drones in this formation?
hard
A. positions = [(-2,2), (-1,1), (0,0), (1,1), (2,2)]
B. positions = [(0,0), (0,1), (0,2), (0,3), (0,4)]
C. positions = [(1,1), (2,2), (3,3), (4,4), (5,5)]
D. positions = [(0,0), (-1,-1), (-2,-2), (-3,-3), (-4,-4)]

Solution

  1. Step 1: Understand V shape coordinates

    A V shape has drones spread left and right diagonally from center (0,0).
  2. Step 2: Check each option's pattern

    positions = [(-2,2), (-1,1), (0,0), (1,1), (2,2)] has symmetric positions left and right diagonally, forming a V. Others are straight lines or one-sided.
  3. Final Answer:

    positions = [(-2,2), (-1,1), (0,0), (1,1), (2,2)] -> Option A
  4. Quick Check:

    V shape = symmetric diagonal positions [OK]
Hint: V shape means symmetric diagonal positions [OK]
Common Mistakes:
  • Choosing straight line positions
  • Not centering the formation
  • Using only positive or negative coordinates
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