Skip to content

Commit

Permalink
Geofence mechanism is updated according to V2.1.0.
Browse files Browse the repository at this point in the history
The process of setting the geofence in V1 was different than V2, so this change updated the geofence process according to the need of V2.
Geofence class is changed.
  • Loading branch information
MuhammadBilal1 authored Mar 24, 2024
1 parent 69576ac commit fd74c76
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions examples/geofence.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

import asyncio
from mavsdk import System
from mavsdk.geofence import Point, Polygon
from mavsdk.geofence import Point, Polygon, FenceType, GeofenceData, Circle

"""
This example shows how to use the geofence plugin.
Note: The behavior when your vehicle hits the geofence is NOT configured
in this example.
FenceType:
INCLUSION: The vehicle will not go outside the fence area.
EXCLUSION: The vehicle will not come inside the fence area.
"""


Expand Down Expand Up @@ -43,11 +47,19 @@ async def run():
p4 = Point(latitude - 0.0001, longitude + 0.0001)

# Create a polygon object using your points
polygon = Polygon([p1, p2, p3, p4], Polygon.FenceType.INCLUSION)
polygon = Polygon([p1, p2, p3, p4], FenceType.INCLUSION)

# circle = Circle(p1, 10.0, FenceType.INCLUSION)

# Sending the circle object is necessary in the geofence data,
# so if you don't want to set the circular geofence, send it like this.
circle = Circle(Point(0,0), 0, FenceType.INCLUSION)

geofenceData = GeofenceData([polygon], [circle])

# Upload the geofence to your vehicle
print("Uploading geofence...")
await drone.geofence.upload_geofence([polygon])
await drone.geofence.upload_geofence(geofenceData)

print("Geofence uploaded!")

Expand Down

0 comments on commit fd74c76

Please sign in to comment.