-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
64 lines (51 loc) · 1.96 KB
/
main.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import asyncio
from pathlib import Path
import cv2
import pandas
from lib.comm.integrations import IntegrationCommander
from lib.comp.cam import Camera
from lib.comp.drones import Drone
from lib.models.groundingdino import GroundingDINO
from lib.util.config import config
from lib.util.images import cv_to_pil, add_box_mask, pil_to_cv
class Main:
def __init__(self):
self.drone = Drone()
self.camera = Camera()
self.model = GroundingDINO()
self.waypoints = pandas.read_csv(config.waypoints, header=None).to_numpy()
self.perspectives = [
pandas.read_csv(Path(config.perspectives).joinpath(f'{i}.csv'), header=None).to_numpy().tolist() for i in
range(len(self.waypoints))]
self.commander = IntegrationCommander(self.drone, self.camera, self.model, self.waypoints, self.perspectives)
self.window = False
def window_thread(self):
self.window = True
while self.window:
frame = self.camera.get_frame()
if frame is not None:
if self.commander.box is not None:
frame = cv_to_pil(frame)
frame = add_box_mask(frame, self.commander.box)
frame = pil_to_cv(frame)
cv2.imshow('Mission-Center', frame)
if cv2.waitKey(0) & 0xFF == ord('0'):
self.window = False
cv2.destroyAllWindows()
async def moni_battery(self):
async for b in self.drone.drone.telemetry.battery():
print(b.remaining_percent)
await asyncio.sleep(1)
async def __call__(self):
await self.drone.connect()
try:
await self.drone.takeoff()
await self.commander.start_control()
except Exception as e:
print(e)
finally:
await self.drone.return_to_launch()
if __name__ == '__main__':
config.load('configurations/base.yaml')
main = Main()
asyncio.run(main())