forked from aditya2g/Megathon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
execute.py
73 lines (58 loc) · 1.75 KB
/
execute.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
65
66
67
68
69
70
71
72
73
# import setup_path
import airsim
import time
import numpy as np
import os
import pprint
# connect to the AirSim simulator
client = airsim.MultirotorClient()
client.confirmConnection()
client.enableApiControl(True)
client.armDisarm(True)
state = client.getMultirotorState()
s = pprint.pformat(state)
print("state: %s" % s)
print("Taking OFF")
client.takeoffAsync().join()
state = client.getMultirotorState()
print("state: %s" % pprint.pformat(state))
print("Moving to position")
client.moveToPositionAsync(0, 0, -50, 10).join()
# for i in points:
# -42.003983 -28.115284 -50.316597
# -48.902599 52.301170 -50.129326
# 44.438919 20.640558 -51.753590
# x=-42
# y=-28
# z=-50
points = np.array([-42.003983,-28.115284,-50.316597,-1,-48.902599,52.301170,-50.129326,-3,50.438919,21.640558,-51.753590,-2])
points = np.reshape(points,(3,4))
# points = np.array([50.438919,21.640558,-51.753590,-48.902599,52.301170,-50.129326])
# points = np.reshape(points,(2,3))
for i in points:
print(i)
x = int(i[0])
y = int(i[1])
z = int(i[2])
h = int(i[3])
print("Moving to position")
client.moveToPositionAsync(x, y, z, 10).join()
print("Hovering")
client.hoverAsync().join()
print("Killing mosquitoes")
client.moveToPositionAsync(x, y, h, 10).join()
print("Hovering")
client.hoverAsync().join()
time.sleep(2)
state = client.getMultirotorState()
print("state: %s" % pprint.pformat(state))
print("Moving to position")
client.moveToPositionAsync(x, y, z, 10).join()
print("flying back home")
client.moveToPositionAsync(0, 0, z, 10).join()
print("landing...")
client.landAsync().join()
client.armDisarm(False)
client.reset()
# that's enough fun for now. let's quit cleanly
client.enableApiControl(False)