0
0
Drone Programmingprogramming~30 mins

Collision avoidance in swarms in Drone Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Collision avoidance in swarms
📖 Scenario: You are programming a group of drones flying together in a swarm. To keep them safe, each drone must avoid getting too close to others. You will write a simple program to check the distances between drones and mark which ones need to move away to avoid collisions.
🎯 Goal: Build a program that stores drone positions, sets a safe distance threshold, checks which drones are too close to each other, and prints a list of drones that must move to avoid collisions.
📋 What You'll Learn
Create a dictionary with drone names as keys and their (x, y) positions as values
Create a variable for the safe distance threshold
Use a loop to compare each drone's position with others to find pairs too close
Print the list of drones that need to move to avoid collisions
💡 Why This Matters
🌍 Real World
Collision avoidance is critical for drone swarms used in delivery, search and rescue, and aerial photography to prevent crashes and ensure smooth operation.
💼 Career
Understanding how to program collision avoidance helps in roles like drone software developer, robotics engineer, and autonomous systems programmer.
Progress0 / 4 steps
1
DATA SETUP: Create drone positions dictionary
Create a dictionary called drones with these exact entries: 'DroneA': (0, 0), 'DroneB': (3, 4), 'DroneC': (5, 1), 'DroneD': (8, 8)
Drone Programming
Need a hint?

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

2
CONFIGURATION: Set safe distance threshold
Create a variable called safe_distance and set it to 5
Drone Programming
Need a hint?

Use a simple number variable for the safe distance.

3
CORE LOGIC: Find drones too close to each other
Create a list called to_move. Use a nested for loop with variables drone1, pos1 and drone2, pos2 to compare each drone's position with others. Calculate the distance using the formula distance = ((pos1[0] - pos2[0])**2 + (pos1[1] - pos2[1])**2)**0.5. If the distance is less than safe_distance and the drones are different, add drone1 to to_move if not already in it.
Drone Programming
Need a hint?

Use two loops to compare each drone with every other drone. Calculate distance with the Pythagorean formula.

4
OUTPUT: Print drones that need to move
Write a print statement to display the list to_move
Drone Programming
Need a hint?

Use print(to_move) to show the drones that must move.