Created
April 15, 2019 06:31
-
-
Save pteacher/52d086dcd542b42bcf443d0c1e37be3a to your computer and use it in GitHub Desktop.
dronekit_arm_test
This file contains 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 | |
import time | |
import argparse | |
parser = argparse.ArgumentParser(description='commands') | |
parser.add_argument('--connect') | |
args = parser.parse_args() | |
connection_string = args.connect | |
print("Connection to drone on %s" %connection_string) | |
vehicle = connect(connection_string, wait_ready=True) | |
def arm_and_take_off(tgt_altitude): | |
print("arming motors") | |
# while not vehicle.is_armable: | |
# print("trying to arm...") | |
# time.sleep(1) | |
vehicle.mode = VehicleMode("STABILIZE") | |
vehicle.armed = True | |
''' | |
while not vehicle.armed: | |
print " Waiting for arming..." | |
time.sleep(1) | |
''' | |
''' | |
while vehicle.gps_0.fix_type < 2: | |
print "Waiting for GPS...:", vehicle.gps_0.fix_type | |
time.sleep(1) | |
''' | |
# Get Vehicle Home location - will be `None` until first set by autopilot | |
'''while not vehicle.home_location: | |
cmds = vehicle.commands | |
cmds.download() | |
cmds.wait_ready() | |
if not vehicle.home_location: | |
print " Waiting for home location ..." | |
# We have a home location, so print it! | |
print "\n Home location: %s" % vehicle.home_location | |
# Set vehicle home_location, mode, and armed attributes (the only settable attributes) | |
print "\nSet new home location" | |
# Home location must be within 50km of EKF home location (or setting will fail silently) | |
# In this case, just set value to current location with an easily recognisable altitude (222) | |
my_location_alt = vehicle.location.global_frame | |
my_location_alt.alt = 222.0 | |
vehicle.home_location = my_location_alt | |
print " New Home Location (from attribute - altitude should be 222): %s" % vehicle.home_location | |
''' | |
print("Takeoff") | |
vehicle.simple_takeoff(tgt_altitude) | |
time.sleep(10) | |
''' | |
while not vehicle.mode.name=='GUIDED' and not vehicle.armed and not api.exit: | |
print " Getting ready to take off ..." | |
time.sleep(1) | |
''' | |
while True: | |
altitude = vehicle.location.global_relative_frame.alt | |
print altitude | |
if altitude >= tgt_altitude - 1: | |
print("alt reached") | |
break | |
time.sleep(1) | |
arm_and_take_off(20) | |
''' | |
vehicle.airspeed = 15 | |
print("go to WPL") | |
wpl = LocationGlobalRelative(56.413436, 40.981330, 20) | |
vehicle.simple_goto(wpl) | |
time.sleep(10) | |
wpl = LocationGlobalRelative(56.410008, 40.988211, 20) | |
vehicle.simple_goto(wpl) | |
time.sleep(50) | |
wpl = LocationGlobalRelative(56.408690, 40.981062, 20) | |
vehicle.simple_goto(wpl) | |
time.sleep(50) | |
print("coming back") | |
vehicle.mode = VehicleMode("RTL") | |
time.sleep(60) | |
''' | |
# mavproxy --master tcp:127.0.0.1:5760 --out udp:127.0.0.1:14551 --out udp:100.126.45.198:14550 | |
# python.exe C:\Users\user\Documents\drone_test.py --connect udp:127.0.0.1:14551 | |
# dronekit-sitl copter --home=56.413436,40.981330,30,30 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment