-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtakeoff_test.py
58 lines (45 loc) · 1.75 KB
/
takeoff_test.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
# USAGE
# python takeoff_test.py
# Connect to the Vehicle.
print("Connecting to vehicle on: serial0")
vehicle = connect('/dev/serial0', wait_ready=True, baud=921600)
def arm_and_takeoff(aTargetAltitude):
"""
Arms vehicle and fly to aTargetAltitude.
"""
print ("Basic pre-arm checks")
# don't let the user try to arm until autopilot is ready
while not vehicle.is_armable:
print(" Waiting for vehicle to initialise...")
time.sleep(1)
while not vehicle.mode.name == 'GUIDED': # wait until mode has changed
print(" Waiting for mode change ...")
time.sleep(1)
print ("\nSet Vehicle.armed=True (currently: %s)" % vehicle.armed)
vehicle.armed = True
while not vehicle.armed: # wait until copter is armed
print (" Waiting for arming...")
time.sleep(1)
print (" Vehicle is armed: %s" % vehicle.armed)
print ("Taking off!")
vehicle.simple_takeoff(aTargetAltitude) # take off to target altitude
# 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 ("Global Location (relative altitude): %s" % vehicle.location.global_relative_frame)
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)
# take off to 10m
arm_and_takeoff(10)
print("Take off complete")
# hover for 10 seconds
time.sleep(10)
# land
print("Now let's land")
vehicle.mode = VehicleMode("LAND")
# close vehicle object
vehicle.close()