/
telemetry.py
executable file
·44 lines (29 loc) · 1 KB
/
telemetry.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
import asyncio
from mavsdk import System
async def run():
# Init the drone
drone = System()
await drone.connect(system_address="udp://:14540")
# Start the tasks
asyncio.ensure_future(print_battery(drone))
asyncio.ensure_future(print_gps_info(drone))
asyncio.ensure_future(print_in_air(drone))
asyncio.ensure_future(print_position(drone))
while True:
await asyncio.sleep(1)
async def print_battery(drone):
async for battery in drone.telemetry.battery():
print(f"Battery: {battery.remaining_percent}")
async def print_gps_info(drone):
async for gps_info in drone.telemetry.gps_info():
print(f"GPS info: {gps_info}")
async def print_in_air(drone):
async for in_air in drone.telemetry.in_air():
print(f"In air: {in_air}")
async def print_position(drone):
async for position in drone.telemetry.position():
print(position)
if __name__ == "__main__":
# Start the main function
asyncio.run(run())