|
2 | 2 |
|
3 | 3 | import asyncio
|
4 | 4 | from mavsdk import System
|
5 |
| -from mavsdk.geofence import Point, Polygon |
| 5 | +from mavsdk.geofence import Point, Polygon, FenceType, GeofenceData, Circle |
6 | 6 |
|
7 | 7 | """
|
8 | 8 | This example shows how to use the geofence plugin.
|
9 | 9 |
|
10 | 10 | Note: The behavior when your vehicle hits the geofence is NOT configured
|
11 | 11 | in this example.
|
12 | 12 |
|
| 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 | +
|
13 | 17 | """
|
14 | 18 |
|
15 | 19 |
|
@@ -43,11 +47,19 @@ async def run():
|
43 | 47 | p4 = Point(latitude - 0.0001, longitude + 0.0001)
|
44 | 48 |
|
45 | 49 | # 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]) |
47 | 59 |
|
48 | 60 | # Upload the geofence to your vehicle
|
49 | 61 | print("Uploading geofence...")
|
50 |
| - await drone.geofence.upload_geofence([polygon]) |
| 62 | + await drone.geofence.upload_geofence(geofenceData) |
51 | 63 |
|
52 | 64 | print("Geofence uploaded!")
|
53 | 65 |
|
|
0 commit comments