0
0
Drone Programmingprogramming~30 mins

Formation flying basics in Drone Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Formation flying basics
📖 Scenario: You are programming a group of drones to fly together in a simple formation. Each drone has a unique ID and a starting position represented by coordinates (x, y).To keep the formation tight, you want to calculate the relative positions of each drone compared to the leader drone.
🎯 Goal: Build a program that stores the drones' starting positions, sets the leader drone, calculates the relative positions of all drones to the leader, and then prints these relative positions.
📋 What You'll Learn
Create a dictionary with drone IDs as keys and their (x, y) positions as values
Create a variable to store the leader drone's ID
Calculate the relative positions of each drone compared to the leader drone using a dictionary comprehension
Print the dictionary of relative positions
💡 Why This Matters
🌍 Real World
Drone teams often fly in formations for tasks like filming, surveying, or search and rescue. Calculating relative positions helps keep them coordinated.
💼 Career
Understanding how to manage multiple drones and their positions is important for drone operators, robotics programmers, and engineers working on autonomous systems.
Progress0 / 4 steps
1
Create the drones' starting positions
Create a dictionary called drones with these exact entries: 'drone1': (10, 20), 'drone2': (15, 25), 'drone3': (12, 22), 'drone4': (18, 30)
Drone Programming
Need a hint?

Use a dictionary with drone IDs as keys and tuples for positions.

2
Set the leader drone
Create a variable called leader and set it to the string 'drone1' to mark the leader drone
Drone Programming
Need a hint?

Just assign the string 'drone1' to the variable leader.

3
Calculate relative positions
Use a dictionary comprehension to create a new dictionary called relative_positions where each drone's position is adjusted by subtracting the leader drone's x and y coordinates from its own coordinates. Use for drone, (x, y) in drones.items() to iterate.
Drone Programming
Need a hint?

Subtract the leader's x and y from each drone's x and y inside the dictionary comprehension.

4
Print the relative positions
Write a print statement to display the relative_positions dictionary
Drone Programming
Need a hint?

Use print(relative_positions) to show the result.