-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflying_test.py
More file actions
93 lines (76 loc) · 3 KB
/
flying_test.py
File metadata and controls
93 lines (76 loc) · 3 KB
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
92
93
# Import DroneKit-Python
from dronekit import connect, VehicleMode, time
#Setup option parsing to get connection string
import argparse
parser = argparse.ArgumentParser(description='Print out vehicle state information')
parser.add_argument('--connect',help="vehicle connection target string.")
args=parser.parse_args()
connection_string = args.connect
# Connect to the Vehicle.
print "\nConnecting to vehicle on: %s" % connection_string
vehicle = connect(connection_string, wait_ready=False)
vehicle.wait_ready(timeout=120)
#Get some vehicle attributes (state)
print "Get some vehicle attribute values:"
print "GPS: %s" % vehicle.gps_0
print "Battery: %s" % vehicle.battery
print "Last Heartbeat: %s" % vehicle.last_heartbeat
print "Is Armable?: %s" % vehicle.system_status.state
print "Mode: %s" % vehicle.mode.name # settable
def arm_and_takeoff(aTargetAltitude):
"""
Arms vehicle and fly to aTargetAltitude.
"""
print("Basic pre-arm checks")
print("Arming motors")
vehicle.mode = VehicleMode("GUIDED")
vehicle.armed = True
print("Vehicle armed!")
#Takeoff
print("Taking off!")
vehicle.simple_takeoff(aTargetAltitude) # Take off to target altitude
lat = vehicle.location.global_relative_frame.lat
lon = vehicle.location.global_relative_frame.lon
alt = vehicle.location.global_relative_frame.alt
print('Current location after takeoff is: {0},{1},{2}'.format(lat,lon,alt))
# Wait until the vehicle reaches a safe height before processing the goto
# (otherwise the command after Vehicle.simple_takeoff will execute immediately).
while True:
print(" Altitude: ", vehicle.location.global_relative_frame.alt)
# Break and return from function just below target altitude.
if vehicle.location.global_relative_frame.alt >= aTargetAltitude * 0.95:
print("Reached target altitude")
break
time.sleep(1)
arm_and_takeoff(10)
####################################
# YOUR CODE GOES HERE
####################################
# Check that you are using proper GOTO commands that are
# executed in a loop with the following logic:
#def my_goto_function(target):
# print the target coordinates so we know what is happening
# simple goto command
# while loop must include while vehicle.mode="GUIDED"
# check distance to target
# if close to target
# break
#
# You can call your function for each waypoint
# SANITY CHECK that you don't go farther than 20 meters from your starting waypoint.
# I'm somehow against anyone trying to fly to Australia during our flight tests!
####################################
# Add this at the end
####################################
print("Returning to Launch")
vehicle.mode = VehicleMode("LAND") # Note we replace RTL with LAND
# Close vehicle object before exiting script
print("Close vehicle object")
vehicle.close()
# Shut down simulator if it was started.
if sitl:
sitl.stop()
# Close vehicle object before exiting script
vehicle.close()
time.sleep(5)
print("Completed")