Created
April 7, 2016 21:02
-
-
Save mrpollo/c750d6c13b45562c6b1073557d275001 to your computer and use it in GitHub Desktop.
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 __future__ import print_function | |
from flask import Flask, request | |
from dronekit import connect, LocationGlobal, VehicleMode | |
import sys, time | |
class Drone(object): | |
def __init__(self): | |
self.vehicle = connect('tcp:127.0.0.1:5760', wait_ready=True) | |
self.vehicle.add_attribute_listener('armed', self._armed_callback) | |
while not self.vehicle.is_armable: | |
self._log("<<< Waiting for vehicle to initialise...") | |
time.sleep(1) | |
self._log("<<< arming") | |
self.vehicle.armed = True # Lets arm the copter! | |
self.vehicle.mode = VehicleMode("GUIDED") | |
def goto(self, point): | |
self._log("<<< sent to point: ", point) | |
self.vehicle.simple_goto(point) | |
def _armed_callback(self, vehicle, name, message): | |
self._log("<<< we are armed lets go!") | |
if self.vehicle.location.global_relative_frame.alt < 100: | |
self.vehicle.simple_takeoff(100) # takeoff at 100 meters | |
def _log(self, *args): | |
print(*args, file=sys.stderr) | |
sys.stderr.flush() | |
app = Flask(__name__) | |
d = Drone() | |
@app.route("/") | |
def hello(): | |
return str(d.vehicle.mode.name) | |
@app.route("/track") | |
def track(): | |
return str(d.vehicle.location.global_frame) | |
@app.route("/goto", methods=['POST']) | |
def goto(): | |
lat = float(request.form['lat']) | |
lon = float(request.form['lon']) | |
alt = float(request.form['alt']) | |
point = LocationGlobal(lat, lon, alt) | |
d.goto(point) | |
return str(point) | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment