Skip to content

Instantly share code, notes, and snippets.

@Dhulkarnayn
Last active August 19, 2021 16:24
Show Gist options
  • Save Dhulkarnayn/84ce90be190978698b55f5bc0c3bd084 to your computer and use it in GitHub Desktop.
Save Dhulkarnayn/84ce90be190978698b55f5bc0c3bd084 to your computer and use it in GitHub Desktop.
# Import Necessary Packages
from dronekit import connect, VehicleMode,LocationGlobalRelative
import time
def basicTakeOff(altitude):
"""
Simple function which returns the distance and bearing between two geographic location
Inputs:
1. altitude - TakeOff Altitude
"""
vehicle.mode = VehicleMode("GUIDED")
vehicle.armed = True
time.sleep(2)
vehicle.simple_takeoff(altitude)
while True:
print("Reached Height = ", vehicle.location.global_relative_frame.alt)
if vehicle.location.global_relative_frame.alt >= (altitude - 1.5):
break
time.sleep(1)
# Connecting the Vehicle
vehicle = connect('udpin:127.0.0.1:14551', baud=115200)
# Takeoff the Vehicle
takeOffAltitude = 10
basicTakeOff(takeOffAltitude)
print("Reached:", takeOffAltitude, " m")
# Landing the Vehicle
vehicle.mode=VehicleMode('LAND')
print("Landing the Vehicle!!!")
time.sleep(1)
print("Exiting the Code!!!")
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment