Skip to content

Commit 8ebfdec

Browse files
authored
Merge pull request #673 from MuhammadBilal1/patch-2
Geofence mechanism is updated according to V2.1.0.
2 parents 69576ac + 9e0f947 commit 8ebfdec

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

examples/geofence.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22

33
import asyncio
44
from mavsdk import System
5-
from mavsdk.geofence import Point, Polygon
5+
from mavsdk.geofence import Point, Polygon, FenceType, GeofenceData, Circle
66

77
"""
88
This example shows how to use the geofence plugin.
99
1010
Note: The behavior when your vehicle hits the geofence is NOT configured
1111
in this example.
1212
13+
FenceType:
14+
INCLUSION: The vehicle will not go outside the fence area.
15+
EXCLUSION: The vehicle will not come inside the fence area.
16+
1317
"""
1418

1519

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

4549
# Create a polygon object using your points
46-
polygon = Polygon([p1, p2, p3, p4], Polygon.FenceType.INCLUSION)
50+
polygon = Polygon([p1, p2, p3, p4], FenceType.INCLUSION)
51+
52+
# circle = Circle(p1, 10.0, FenceType.INCLUSION)
53+
54+
# Sending the circle object is necessary in the geofence data,
55+
# so if you don't want to set the circular geofence, send it like this.
56+
circle = Circle(Point(0, 0), 0, FenceType.INCLUSION)
57+
58+
geofenceData = GeofenceData([polygon], [circle])
4759

4860
# Upload the geofence to your vehicle
4961
print("Uploading geofence...")
50-
await drone.geofence.upload_geofence([polygon])
62+
await drone.geofence.upload_geofence(geofenceData)
5163

5264
print("Geofence uploaded!")
5365

0 commit comments

Comments
 (0)