Skip to content

Commit

Permalink
Merge pull request #673 from MuhammadBilal1/patch-2
Browse files Browse the repository at this point in the history
Geofence mechanism is updated according to V2.1.0.
  • Loading branch information
julianoes authored Mar 24, 2024
2 parents 69576ac + 9e0f947 commit 8ebfdec
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 8ebfdec

Please sign in to comment.