def appendWaypoint(request): waypoint = request['body']['waypoint'] vehicle = request['vehicle'] cmds = vehicle.commands cmds.download() cmds.wait_ready() if waypoint['action'] == 'takeoff': commands.takeoff(vehicle, waypoint['alt'], cmds) elif waypoint['action'] == 'goto': commands.goto(waypoint['lat'], waypoint['lng'], waypoint['alt'], cmds) elif waypoint['action'] == 'land': commands.land(waypoint['lat'], waypoint['lng'], cmds) elif waypoint['action'] == 'landv': commands.landVertical(cmds) elif waypoint['action'] == 'rtl': commands.rtl(cmds) cmds.upload() commands.startmission( vehicle) #comando necessario caso o veiculo esteja no solo #if cmds.next == 0: #estes comandos estao sendo testados para tratar o problema 2. # print 'next = 0' # cmds.next = cmds.count #if cmds.next == cmds.count - 1: # print 'next = count -1' # cmds.next = cmds.count return {'status-append-waypoint': 'ok'}
def setMission(request): mission = request['body']['mission'] vehicle = request['vehicle'] cmds = vehicle.commands cmds.clear() for item in mission: if item['action'] == 'takeoff': commands.takeoff(vehicle, item['alt'], cmds) elif item['action'] == 'waypoint': commands.goto(item['lat'], item['lng'], item['alt'], cmds) elif item['action'] == 'land': commands.land(item['lat'], item['lng'], item['alt'], cmds) elif item['action'] == 'rtl': commands.rtl(cmds) cmds.upload() commands.startmission(vehicle) return {'status-set-mission': 'ok'}
def setWaypoint(request): waypoint = request['body']['waypoint'] vehicle = request['vehicle'] cmds = vehicle.commands cmds.clear() cmds.next = 0 if waypoint['action'] == 'takeoff': commands.takeoff(vehicle, waypoint['alt'], cmds) elif waypoint['action'] == 'goto': commands.goto(waypoint['lat'], waypoint['lng'], waypoint['alt'], cmds) elif waypoint['action'] == 'land': commands.land(waypoint['lat'], waypoint['lng'], cmds) elif waypoint['action'] == 'landv': commands.landVertical(cmds) elif waypoint['action'] == 'rtl': commands.rtl(cmds) cmds.upload() commands.startmission( vehicle) #comando necessario caso o veiculo esteja no solo return {'status-set-waypoint': 'ok'}
def setWaypoint(request): point = request['body']['waypoint'] vehicle = request['vehicle'] cmds = vehicle.commands cmds.download() cmds.wait_ready() finished = True if cmds.next == cmds.count else False print "finished status:" print finished if point['action'] == 'takeoff': commands.takeoff(vehicle, point['alt'], cmds) elif point['action'] == 'waypoint': commands.goto(point['lat'], point['lng'], point['alt'], cmds) elif point['action'] == 'land': commands.land(point['lat'], point['lng'], point['alt'], cmds) elif point['action'] == 'rtl': commands.rtl(cmds) cmds.upload() if finished: commands.startmission(vehicle) return {'status-set-waypoint': 'ok'}
def appendMission(request): mission = request['body']['mission'] vehicle = request['vehicle'] cmds = vehicle.commands cmds.download() cmds.wait_ready() for item in mission: if item['action'] == 'takeoff': commands.takeoff(vehicle, item['alt'], cmds) elif item['action'] == 'goto': commands.goto(item['lat'], item['lng'], item['alt'], cmds) elif item['action'] == 'land': commands.land(item['lat'], item['lng'], cmds) elif item['action'] == 'landv': commands.landVertical(cmds) elif item['action'] == 'rtl': commands.rtl(cmds) cmds.upload() commands.startmission( vehicle) #comando necessario caso o veiculo esteja no solo return {'status-append-mission': 'ok'}
# get width and height of camera width = camera.get(cv2.CAP_PROP_FRAME_WIDTH) height = camera.get(cv2.CAP_PROP_FRAME_HEIGHT) # find center of camera width / 2, height / 2 dX = cX - width / 2 dY = cY - height / 2 # find distance dist = math.sqrt((dX * dX) + (dY * dY)) return (dX, dY, dist) if __name__ == "__main__": format = "%(asctime)s: %(message)s" logging.basicConfig(format=format, level=logging.INFO, datefmt="%H:%M:%S") found = False rv = False exitProgram = False camera = cv2.VideoCapture('tcp://192.168.1.1:5555') fly.takeoff() while exitProgram == False: print("Flying...") async_detect = pool.apply_async(detectImage, (camera, found)) rv = async_detect.get() print("Found:", rv) dist = calculateDistance(rv[1], rv[2]) async_fly = pool.apply_async(flyDrone, (rv[0], rv[1], rv[2])) found = async_fly.get() exitProgram = preview(camera) fly.land() print("Stopped...")