Created
August 5, 2016 21:46
-
-
Save dbaldwin/9185b702091148580fa836c1911f8735 to your computer and use it in GitHub Desktop.
Basic takeoff to 20m and land with DroneKit, Raspberry Pi and Pixhawk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dronekit import connect, VehicleMode, LocationGlobalRelative | |
from pymavlink import mavutil | |
import time | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--connect', default='127.0.0.1:14550') | |
args = parser.parse_args() | |
# Connect to the Vehicle | |
print 'Connecting to vehicle on: %s' % args.connect | |
vehicle = connect(args.connect, baud=57600, wait_ready=True) | |
# Function to arm and then takeoff to a user specified altitude | |
def arm_and_takeoff(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) | |
print "Arming motors" | |
# Copter should arm in GUIDED mode | |
vehicle.mode = VehicleMode("GUIDED") | |
vehicle.armed = True | |
while not vehicle.armed: | |
print " Waiting for arming..." | |
time.sleep(1) | |
print "Taking off!" | |
vehicle.simple_takeoff(aTargetAltitude) # Take off to target altitude | |
# Check that vehicle has reached takeoff altitude | |
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) | |
# Initialize the takeoff sequence to 20m | |
arm_and_takeoff(20) | |
print("Take off complete") | |
# Hover for 10 seconds | |
time.sleep(10) | |
print("Now let's land") | |
vehicle.mode = VehicleMode("LAND") | |
# Close vehicle object | |
vehicle.close() |
Hello, I used this code but my quadcopter don`t enter in hover mode, only take off and after reached the altitude land Can somone help me with this problem?
have u tried increasing the time.sleep part of the code after the take off is completed?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
even if you delete that part of the code, i think you won't get through vehicle.armed=True because gps lock is still a requirement.