def init_connexion():
   vehicle = connect('/dev/ttyAMA0', wait_ready=True, baud=57600)
 
   while vehicle.gps_0.fix_type < 2:
       print "Etat du gps :", vehicle.gps_0.fix_type
   	time.sleep(1)
 
   while not vehicle.is_armable:
       print "Attente de la fin du process d'initialisation"
   	time.sleep(1)
 
   vehicle.mode = VehicleMode("GUIDED")

def arm_and_takeoff(altitude):
   vehicle.armed = True
 
   while not vehicle.armed:
       print "Attente de l'armement des moteurs"
   	time.sleep(1)
 
   if vehicle.mode.name == "GUIDED":
   	vehicle.simple_takeoff(altitude)
 
   	while True:
           print " Altitude: ", vehicle.location.global_relative_frame.alt
 
       	if vehicle.location.global_relative_frame.alt >= altitude * 0.95:
               print "Altitude initiale atteinte"
           	break
       	time.sleep(1)
   else:
   	vehicle.armed = False

 
def go_to(lat, long, alt):	
   if vehicle.mode.name == "GUIDED":
   	tempPoint = LocationGlobalRelative(lat, long, alt)
 
   	vehicle.simple_goto(tempPoint, groundspeed=3)

 
print "Initialisation de la connexion"
init_connexion()
 
print "Armement et Décollage avec une aaltitude initiale de 10 m"
arm_and_takeoff(10)
 
print "En route pour le premier point"
go_to(48.630150, -1.491171, 10)
time.sleep(10)
 
print "En route pour le deuxième point"
go_to(48.630007, -1.491560, 10)
time.sleep(10)
 
print "Retour au point de départ puis atterissage"
vehicle.mode = VehicleMode("RTL")
 
vehicle.close()

 
from dronekit import connect, LocationGlobalRelative
from dronekit.lib import VehicleMode
import time
 
vehicle = None

def init_connexion():
   vehicle = connect('/dev/ttyAMA0', wait_ready=True, baud=57600)
 
   while vehicle.gps_0.fix_type < 2:
   	print "Etat du gps :", vehicle.gps_0.fix_type
   	time.sleep(1)
 
   while not vehicle.is_armable:
   	print "Attente de la fin du process d'initialisation"
   	time.sleep(1)
 
   vehicle.mode = VehicleMode("GUIDED")

def arm_and_takeoff(altitude):
   vehicle.armed = True
 
   while not vehicle.armed:
   	print "Attente de l'armement des moteurs"
   	time.sleep(1)
 
   if vehicle.mode.name == "GUIDED":
   	vehicle.simple_takeoff(altitude)
 
   	while True:
       	print " Altitude: ", vehicle.location.global_relative_frame.alt
 
       	if vehicle.location.global_relative_frame.alt >= altitude * 0.95:
           	print "Altitude initiale atteinte"
           	break
       	time.sleep(1)
   else:
   	vehicle.armed = False

def go_to(lat, long, alt):
   if vehicle.mode.name == "GUIDED":
   	tempPoint = LocationGlobalRelative(lat, long, alt)
 
   	vehicle.simple_goto(tempPoint, groundspeed=3)

print "Initialisation de la connexion"
init_connexion()
 
print "Armement et Decollage avec une altitude initiale de 10 m"
arm_and_takeoff(10)
 
print "En route pour le premier point"
go_to(48.630150, -1.491171, 10)
time.sleep(10)
 
print "En route pour le deuxieme point"
go_to(48.630007, -1.491560, 10)
time.sleep(10)
 
print "Retour au point de depart puis atterissage"
vehicle.mode = VehicleMode("RTL")
 
vehicle.close()