0
0
Drone Programmingprogramming~10 mins

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

Choose your learning style9 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.