0
0
Drone Programmingprogramming~30 mins

Setting geofence boundaries in Drone Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Setting Geofence Boundaries
📖 Scenario: You are programming a drone to fly safely within a specific area. To keep the drone from flying too far, you need to set up geofence boundaries. These boundaries tell the drone where it can and cannot go.
🎯 Goal: Build a program that defines a geofence area using coordinates, sets a maximum allowed distance from the center, checks if a given drone position is inside the geofence, and prints the result.
📋 What You'll Learn
Create a dictionary called geofence_center with keys 'latitude' and 'longitude' and exact values 37.7749 and -122.4194
Create a variable called max_distance_km and set it to 5
Write a function called is_inside_geofence that takes lat and lon and returns true if the distance from geofence_center is less than or equal to max_distance_km, otherwise false
Print the result of is_inside_geofence(37.7790, -122.4183)
💡 Why This Matters
🌍 Real World
Drones need geofence boundaries to avoid flying into restricted or dangerous areas, ensuring safety and compliance with regulations.
💼 Career
Understanding how to set and check geofence boundaries is important for drone software developers, UAV operators, and anyone working with autonomous flying devices.
Progress0 / 4 steps
1
Create the geofence center coordinates
Create a dictionary called geofence_center with the keys 'latitude' set to 37.7749 and 'longitude' set to -122.4194.
Drone Programming
Need a hint?

Use curly braces {} to create a dictionary with the exact keys and values.

2
Set the maximum allowed distance
Create a variable called max_distance_km and set it to the number 5.
Drone Programming
Need a hint?

Just assign the number 5 to the variable max_distance_km.

3
Write the function to check if inside geofence
Write a function called is_inside_geofence that takes two parameters: lat and lon. Inside the function, calculate the distance from geofence_center using the formula for distance between two points on Earth (use a simple approximation: 1 degree latitude or longitude equals 111 km). Return true if the distance is less than or equal to max_distance_km, otherwise return false.
Drone Programming
Need a hint?

Calculate the difference in latitude and longitude, convert to kilometers by multiplying by 111, then use the Pythagorean theorem to find the distance.

4
Print the geofence check result
Print the result of calling is_inside_geofence(37.7790, -122.4183).
Drone Programming
Need a hint?

Use print() to show the result of the function call.