示例#1
0
def Record_Transmit(Dr_Obj):

    Mr_IP               = '192.168.8.240'  # Master IP
    
    
    drone(stop_recording(cam_id=0))
    
    ANAFI_MEDIA_API_URL = Dr_Obj.ANAFI_MEDIA_API_URL
    ANAFI_URL           = Dr_Obj.ANAFI_URL
    photo_saved         = drone(recording_progress(result="stopped", _policy="wait"))
    
    drone(start_recording(cam_id=0))
    print(colored( ("Recording Started"), "blue"))

    time.sleep(2)
    drone(stop_recording(cam_id=0))
    photo_saved.wait()

    print(colored( ("Recording Completed"), "blue"))

    print(colored( ("Starting transfer to Drone Computer"), "green"))
    media_id = photo_saved.received_events().last().args["media_id"]
    os.chdir("/home/spacetrex/code/Results")

    media_info_response = requests.get(ANAFI_MEDIA_API_URL + media_id)
    media_info_response.raise_for_status()
    download_dir        = tempfile.mkdtemp()
    Res_dir             = filecreation()

    for resource in media_info_response.json()["resources"]:
        image_response = requests.get(ANAFI_URL + resource["url"], stream=True)
        download_path = os.path.join(download_dir, resource["resource_id"])

        print(colored( ("File transfer to Drone Computer in progress"), "green"))

        image_response.raise_for_status()

        with open(download_path, "wb") as image_file:
            shutil.copyfileobj(image_response.raw, image_file)
        shutil.copy2(download_path, Res_dir)
        print(colored( ("File transfer to Drone computer completed !!"), "green"))


    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

    ssh.connect(hostname= Mr_IP, username = '******',password ='******',port= 22)
    sftp_client = ssh.open_sftp()

    #rem_path = '/home/spacetrex/Results/'+ media_id+'.MP4'
    rem_path = '/home/spacetrex/Results/ANAFI_2.MP4'
    loc_path = download_path


    print(colored( ("Starting transfer to Master Computer"), "cyan"))
    sftp_client.put(loc_path, rem_path)
   
    sftp_client.close()
    ssh.close()
    print(colored( ("File transfer to Master computer completed !!"), "cyan"))
def record_and_fetch(Dr_Obj, X_Tar, ran_V, rec_Vid):
    Pose_Topic = "/vicon/anafi_2/odom"
    pose_subscriber = rospy.Subscriber(Pose_Topic, Odometry, poseCallback)

    global x, y, z, vx, vy, vz, wx, wy, wz, roll, pitch, yaw
    rec_Vid = 0
    ANAFI_MEDIA_API_URL = Dr_Obj.ANAFI_MEDIA_API_URL
    ANAFI_URL = Dr_Obj.ANAFI_URL

    X_St = [x, y, z, vx, vy, vz, roll, pitch, yaw]
    DT = np.array(X_Tar) - np.array(X_St[0:3])
    r_tar = vec_mag(DT)

    if r_tar <= 1.001 * ran_V and rec_Vid == 0:
        print(colored(("Recording Started"), "blue"))
        drone(start_recording(cam_id=0))

    elif r_tar <= 1.001 * ran_V and rec_Vid == 1:
        print(colored(("Recording In Progress"), "blue"))

    elif r_tar > .001 * ran_V and rec_Vid == 2:
        print(colored(("Recording Completed"), "blue"))
        drone(stop_recording(cam_id=0))

        photo_saved = drone(
            recording_progress(result="stopped", _policy="wait"))
        photo_saved.wait()

        media_id = photo_saved.received_events().last().args["media_id"]
        print(media_id)
        os.chdir("/home/spacetrex/code/Results")
        media_info_response = requests.get(ANAFI_MEDIA_API_URL + media_id)
        media_info_response.raise_for_status()
        download_dir = tempfile.mkdtemp()
        Res_dir = filecreation()
        #tempfile.gettempdir()
        for resource in media_info_response.json()["resources"]:
            image_response = requests.get(ANAFI_URL + resource["url"],
                                          stream=True)
            download_path = os.path.join(download_dir, resource["resource_id"])
            print(colored(("File Transfer in progress"), "blue"))

            image_response.raise_for_status()

            with open(download_path, "wb") as image_file:
                shutil.copyfileobj(image_response.raw, image_file)
            shutil.copy2(download_path, Res_dir)
            print(colored(("File Transfer Completed !!!!!!!!!!"), "green"))
        rec_Vid = 2
def Record_Transmit(Dr_Obj):

    Mr_IP = '192.168.8.240'  # Master IP

    drone(stop_recording(cam_id=0))
    Setup_Video_mode(drone)

    ANAFI_MEDIA_API_URL = Dr_Obj.ANAFI_MEDIA_API_URL
    ANAFI_URL = Dr_Obj.ANAFI_URL
    photo_saved = drone(recording_progress(result="stopped", _policy="wait"))

    drone(start_recording(cam_id=0))
    print(colored(("Recording Started"), "blue"))

    time.sleep(2)
    drone(stop_recording(cam_id=0))
    photo_saved.wait()

    print(colored(("Recording Completed"), "blue"))

    print(colored(("Starting transfer to Drone Computer"), "green"))
    media_id = photo_saved.received_events().last().args["media_id"]
    os.chdir("/home/spacetrex/code/Results")

    media_info_response = requests.get(ANAFI_MEDIA_API_URL + media_id)
    media_info_response.raise_for_status()
    download_dir = tempfile.mkdtemp()
    Res_dir = filecreation()

    for resource in media_info_response.json()["resources"]:
        image_response = requests.get(ANAFI_URL + resource["url"], stream=True)
        download_path = os.path.join(download_dir, resource["resource_id"])

        print(colored(("File transfer to Drone Computer in progress"),
                      "green"))

        image_response.raise_for_status()

        with open(download_path, "wb") as image_file:
            shutil.copyfileobj(image_response.raw, image_file)
        shutil.copy2(download_path, Res_dir)
        print(
            colored(("File transfer to Drone computer completed !!"), "green"))
示例#4
0
def take_Map_Video_Move(drone, th_mov, th_R0, dxm):
    # take a photo burst and get the associated media_id

    xc, yc, zc =  R3_Mat_Cords(th_R0, dxm)
    photo_saved = drone(recording_progress(result="stopped", _policy="wait"))
    # drone(
    #     MaxRotationSpeed(1)
    #     >> MaxRotationSpeedChanged(current=1, _policy='wait')
    # ).wait()
    #drone(setAutonomousFlightMaxRotationSpeed(1e-7)).wait()
    drone(start_recording(cam_id=0) & moveBy(xc, yc, zc, th_mov)).wait()
    drone(stop_recording(cam_id=0)).wait()

    print('Action Completed')
    photo_saved.wait()
    media_id = photo_saved.received_events().last().args["media_id"]
    print(media_id)

    # download the photos associated with this media id
    os.chdir("/home/rnallapu/code/Results")
    media_info_response = requests.get(ANAFI_MEDIA_API_URL + media_id)
    media_info_response.raise_for_status()
    

    download_dir = tempfile.mkdtemp()
    Res_dir = filecreation()
    

    #tempfile.gettempdir()
    for resource in media_info_response.json()["resources"]:
        image_response = requests.get(ANAFI_URL + resource["url"], stream=True)
        download_path = os.path.join(download_dir, resource["resource_id"])

        print('Hello')
        print(download_path)
        image_response.raise_for_status()

        with open(download_path, "wb") as image_file:
            shutil.copyfileobj(image_response.raw, image_file)

        #shutil.copy2(download_path, "/home/rnallapu/code/Photos/")
        shutil.copy2(download_path, Res_dir)
示例#5
0
def Drone_Map_Opn2(Dr_Obj, X_Ref, X_Tar, ran_V, Tp, vyT, X_End):

    Mr_IP = '192.168.8.240'  # Master IP

    drone(stop_recording(cam_id=0))

    thr_vec = Dr_Obj.thr_vec
    X_tol = Dr_Obj.X_tol
    yw_tol = Dr_Obj.yw_tol

    ANAFI_MEDIA_API_URL = Dr_Obj.ANAFI_MEDIA_API_URL
    ANAFI_URL = Dr_Obj.ANAFI_URL

    Drone_Move_Orient(Dr_Obj, X_Ref)
    print(colored(("Moved home, executing map command!"), "green"))
    time.sleep(0.5)

    X_Ref2 = X_Ref
    y0 = X_Ref[1]

    global x, y, z, vx, vy, vz, wx, wy, wz, roll, pitch, yaw
    Pose_Topic = "/vicon/anafi_5/odom"

    lr = 20

    print(colored(("Loop Rate: ", lr, " Hz"), "magenta"))
    print(colored(("Travel Time: ", Tp, " s"), "magenta"))
    print(colored(("Velocity: ", vyT, " m/s"), "magenta"))

    looprate = rospy.Rate(lr)
    dt = 1.0 / lr
    X_tol = 0.1

    gn_mat = [5.5, 18, 4.3, 2, 12, 1.3]  # Controller Gains
    rec_Vid = 0

    photo_saved = drone(recording_progress(result="stopped", _policy="wait"))

    for t in np.arange(0, Tp + dt, dt):

        pose_subscriber = rospy.Subscriber(Pose_Topic, Odometry, poseCallback)
        X_St = [x, y, z, vx, vy, vz, roll, pitch, yaw]

        X_Ref[1] = y0 + vyT * t
        X_Ref[4] = vyT
        X_Ref[8] = wrapTo2Pi(atan2(-y, -x))

        DT = np.array(X_Tar) - np.array(X_St[0:3])
        r_tar = vec_mag(DT)
        th0 = asin(DT[2] / r_tar) * 180 / pi

        gimbal_target(drone, th0)
        drone_center(drone, X_St, X_Ref, gn_mat, thr_vec, X_tol, yw_tol)
        print(colored(("Distance to target: ", r_tar), "red"))
        print(colored(("Record Status: ", rec_Vid), "red"))
        print(colored(("Distance threshhold: ", 1.01 * ran_V), "blue"))
        # print(colored(("Gimbal angle computed: ", th0),"blue"))

        if r_tar <= 1.01 * ran_V and rec_Vid == 0:
            rec_Vid = 1
            drone(start_recording(cam_id=0))
            print(colored(("Recording Started"), "blue"))

        elif r_tar > 1.01 * ran_V and rec_Vid == 1:
            rec_Vid = 2
            print(colored(("Recording Completed"), "blue"))
            drone(stop_recording(cam_id=0))
            photo_saved.wait()

        looprate.sleep()

    print(colored(("Current Time: ", t, "sec"), "cyan"))
    print(colored(("Targetted End Y: ", X_Ref[1], "m/s"), "cyan"))
    print(colored(("Achieved End Y: ", X_St[1], "m/s"), "cyan"))

    drone_center(drone, X_St, X_End, gn_mat, thr_vec, X_tol, yw_tol)
    drone(Landing()).wait()

    if rec_Vid == 2:
        print(colored(("Starting transfer to drone computer!"), "green"))
        media_id = photo_saved.received_events().last().args["media_id"]
        print(colored((media_id), "green"))
        os.chdir("/home/spacetrex/code/Results")

        media_info_response = requests.get(ANAFI_MEDIA_API_URL + media_id)
        media_info_response.raise_for_status()
        download_dir = tempfile.mkdtemp()
        Res_dir = filecreation()
        #tempfile.gettempdir()
        for resource in media_info_response.json()["resources"]:
            image_response = requests.get(ANAFI_URL + resource["url"],
                                          stream=True)
            download_path = os.path.join(download_dir, resource["resource_id"])
            print(
                colored(("File transfer to drone computer in progress"),
                        "green"))

            image_response.raise_for_status()

            with open(download_path, "wb") as image_file:
                shutil.copyfileobj(image_response.raw, image_file)
            shutil.copy2(download_path, Res_dir)
            print(colored(("File transfer to drone computer !!"), "green"))

        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(hostname=Mr_IP,
                    username='******',
                    password='******',
                    port=22)
        sftp_client = ssh.open_sftp()
        loc_path = download_path
        rem_path = '/home/spacetrex/Results/ANAFI_5.MP4'

        print(colored(("Starting transfer to Master Computer"), "cyan"))
        sftp_client.put(loc_path, rem_path)

        sftp_client.close()
        ssh.close()

        print(
            colored(("File transfer to Master computer completed !!"), "cyan"))

    else:
        print(colored(("No Recording obtained!!"), "red"))
    print(
        colored(("Mapping done!! Holding drone at Final Desitination!"),
                "green"))
def Drone_Map_Opn2(Dr_Obj, X_Ref, X_Tar, ran_V):

    drone(stop_recording(cam_id=0))

    thr_vec = Dr_Obj.thr_vec
    X_tol = Dr_Obj.X_tol
    yw_tol = Dr_Obj.yw_tol

    ANAFI_MEDIA_API_URL = Dr_Obj.ANAFI_MEDIA_API_URL
    ANAFI_URL = Dr_Obj.ANAFI_URL

    Drone_Move_Orient(Dr_Obj, X_Ref)
    print(colored(("Moved home, executing map command!"), "green"))
    time.sleep(0.5)

    X_Ref2 = X_Ref
    y0 = X_Ref[1]

    global x, y, z, vx, vy, vz, wx, wy, wz, roll, pitch, yaw
    # Pose_Topic = "/vicon/anafi_2/odom"

    vyT = -0.15
    Tp = 30

    lr = 35
    looprate = rospy.Rate(lr)
    dt = 1.0 / lr
    X_tol = 0.1

    gn_mat = [5, 15, 4, 4, 12, 1.8]  # Controller Gains
    rec_Vid = 0

    photo_saved = drone(recording_progress(result="stopped", _policy="wait"))

    for t in np.arange(0, Tp + dt, dt):

        pose_subscriber = rospy.Subscriber(Pose_Topic, Odometry, poseCallback)
        X_St = [x, y, z, vx, vy, vz, roll, pitch, yaw]

        X_Ref[1] = y0 + vyT * t
        X_Ref[4] = vyT
        X_Ref[8] = wrapTo2Pi(atan2(-y, -x))
        Yaw_Ref_D = X_Ref[8] * 180 / pi

        DT = np.array(X_Tar) - np.array(X_St[0:3])
        r_tar = vec_mag(DT)

        Er = np.array(X_Ref[0:3]) - np.array(X_St[0:3])
        er = vec_mag(Er)

        th0 = asin(DT[2] / r_tar) * 180 / pi
        Yaw_D = yaw * 180 / pi
        yw_er = abs(Yaw_Ref_D - Yaw_D)

        gimbal_target(drone, th0)
        drone_center(drone, X_St, X_Ref, gn_mat, thr_vec, X_tol, yw_tol)

        print(" ")
        print(colored(("Reference tracking error: ", er), "yellow"))
        print(colored(("Yaw tracking Error: ", yw_er), "yellow"))

        print(colored(("Z desired: ", X_Ref[2]), "green"))
        print(colored(("Z achieved: ", z), "green"))

        print(colored(("Distance to target: ", r_tar), "red"))
        print(colored(("Record Status: ", rec_Vid), "red"))

        print(colored(("Distance threshhold: ", 1.01 * ran_V), "blue"))
        print(colored(("Gimbal angle computed: ", th0), "blue"))

        if r_tar <= 1.01 * ran_V and rec_Vid == 0:
            rec_Vid = 1
            drone(start_recording(cam_id=0))
            print(colored(("Recording Started"), "blue"))

        elif r_tar > 1.01 * ran_V and rec_Vid == 1:
            rec_Vid = 2
            print(colored(("Recording Completed"), "blue"))
            drone(stop_recording(cam_id=0))
            photo_saved.wait()

        looprate.sleep()
    time.sleep(0.5)

    # X_Ref2[1] = -2.0
    # Drone_Move_Orient(Dr_Obj, X_Ref2)
    drone(Landing()).wait()
    print(colored(("Starting Transfer"), "green"))

    # photo_saved = drone(recording_progress(result="stopped", _policy="wait"))
    # photo_saved.wait()
    media_id = photo_saved.received_events().last().args["media_id"]
    print(colored((media_id), "green"))

    os.chdir("/home/spacetrex/code/Results")
    media_info_response = requests.get(ANAFI_MEDIA_API_URL + media_id)
    media_info_response.raise_for_status()
    download_dir = tempfile.mkdtemp()
    Res_dir = filecreation()
    #tempfile.gettempdir()
    for resource in media_info_response.json()["resources"]:
        image_response = requests.get(ANAFI_URL + resource["url"], stream=True)
        download_path = os.path.join(download_dir, resource["resource_id"])
        print(colored(("File Transfer in progress"), "blue"))

        image_response.raise_for_status()

        with open(download_path, "wb") as image_file:
            shutil.copyfileobj(image_response.raw, image_file)
        shutil.copy2(download_path, Res_dir)
        print(colored(("File Transfer Completed !!!!!!!!!!"), "green"))
    print(
        colored(("Mapping done !! Holding drone at Final Desitination!"),
                "green"))
    X_St = [x, y, z, vx, vy, vz, roll, pitch, yaw]
    DT = np.array(X_Tar) - np.array(X_St[0:3])
    r_tar = vec_mag(DT)

    if r_tar<=1.001*ran_V and rec_Vid==0:
        print(colored( ("Recording Started"), "blue"))
        drone(start_recording(cam_id=0))

    elif r_tar<=1.001*ran_V and rec_Vid==1:
        print(colored( ("Recording In Progress"), "blue"))

    elif r_tar>.001*ran_V and rec_Vid==2:
        print(colored( ("Recording Completed"), "blue"))
        drone(stop_recording(cam_id=0))

        photo_saved = drone(recording_progress(result="stopped", _policy="wait"))
        photo_saved.wait()

        media_id = photo_saved.received_events().last().args["media_id"]
        print(media_id)
        os.chdir("/home/rnallapu/code/Results")
        media_info_response = requests.get(ANAFI_MEDIA_API_URL + media_id)
        media_info_response.raise_for_status()
        download_dir = tempfile.mkdtemp()
        Res_dir = filecreation()
            #tempfile.gettempdir()
        for resource in media_info_response.json()["resources"]:
            image_response = requests.get(ANAFI_URL + resource["url"], stream=True)
            download_path = os.path.join(download_dir, resource["resource_id"])
            print(colored( ("File Transfer in progress"), "blue"))