-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathsurvey.py
91 lines (76 loc) · 3.37 KB
/
survey.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import setup_path
import airsim
import sys
import time
import argparse
class SurveyNavigator:
def __init__(self, args):
self.boxsize = args.size
self.stripewidth = args.stripewidth
self.altitude = args.altitude
self.velocity = args.speed
self.client = airsim.MultirotorClient()
self.client.confirmConnection()
self.client.enableApiControl(True)
def start(self):
print("arming the drone...")
self.client.armDisarm(True)
landed = self.client.getMultirotorState().landed_state
if landed == airsim.LandedState.Landed:
print("taking off...")
self.client.takeoffAsync().join()
# AirSim uses NED coordinates so negative axis is up.
x = -self.boxsize
z = -self.altitude
print("climbing to altitude: " + str(self.altitude))
self.client.moveToPositionAsync(0, 0, z, self.velocity).join()
print("flying to first corner of survey box")
self.client.moveToPositionAsync(x, -self.boxsize, z, self.velocity).join()
# let it settle there a bit.
self.client.hoverAsync().join()
time.sleep(2)
# now compute the survey path required to fill the box
path = []
distance = 0
while x < self.boxsize:
distance += self.boxsize
path.append(airsim.Vector3r(x, self.boxsize, z))
x += self.stripewidth
distance += self.stripewidth
path.append(airsim.Vector3r(x, self.boxsize, z))
distance += self.boxsize
path.append(airsim.Vector3r(x, -self.boxsize, z))
x += self.stripewidth
distance += self.stripewidth
path.append(airsim.Vector3r(x, -self.boxsize, z))
distance += self.boxsize
print("starting survey, estimated distance is " + str(distance))
trip_time = distance / self.velocity
print("estimated survey time is " + str(trip_time))
try:
result = self.client.moveOnPathAsync(path, self.velocity, trip_time, airsim.DrivetrainType.ForwardOnly,
airsim.YawMode(True,0), self.velocity + (self.velocity/2), 1).join()
except:
errorType, value, traceback = sys.exc_info()
print("moveOnPath threw exception: " + str(value))
pass
print("flying back home")
self.client.moveToPositionAsync(0, 0, z, self.velocity).join()
if z < -5:
print("descending")
self.client.moveToPositionAsync(0, 0, -5, 2).join()
print("landing...")
self.client.landAsync().join()
print("disarming.")
self.client.armDisarm(False)
if __name__ == "__main__":
args = sys.argv
args.pop(0)
arg_parser = argparse.ArgumentParser("Usage: survey boxsize stripewidth altitude")
arg_parser.add_argument("--size", type=float, help="size of the box to survey", default=50)
arg_parser.add_argument("--stripewidth", type=float, help="stripe width of survey (in meters)", default=10)
arg_parser.add_argument("--altitude", type=float, help="altitude of survey (in positive meters)", default=30)
arg_parser.add_argument("--speed", type=float, help="speed of survey (in meters/second)", default=5)
args = arg_parser.parse_args(args)
nav = SurveyNavigator(args)
nav.start()