def camera_callback(self, msg): if msg.action & 0b001: # take picture self.drone( camera.take_photo(cam_id=0) ) # https://developer.parrot.com/docs/olympe/arsdkng_camera.html#olympe.messages.camera.take_photo if msg.action & 0b010: # start recording self.drone(camera.start_recording(cam_id=0)).wait( ) # https://developer.parrot.com/docs/olympe/arsdkng_camera.html#olympe.messages.camera.start_recording if msg.action & 0b100: # stop recording self.drone(camera.stop_recording(cam_id=0)).wait( ) # https://developer.parrot.com/docs/olympe/arsdkng_camera.html#olympe.messages.camera.stop_recording self.drone( gimbal. set_target( # https://developer.parrot.com/docs/olympe/arsdkng_gimbal.html#olympe.messages.gimbal.set_target gimbal_id=0, control_mode='position', # {'position', 'velocity'} yaw_frame_of_reference='none', yaw=0.0, pitch_frame_of_reference=self. gimbal_frame, # {'absolute', 'relative', 'none'} pitch=msg.pitch, roll_frame_of_reference=self. gimbal_frame, # {'absolute', 'relative', 'none'} roll=msg.roll)) self.drone( camera. set_zoom_target( # https://developer.parrot.com/docs/olympe/arsdkng_camera.html#olympe.messages.camera.set_zoom_target cam_id=0, control_mode='level', # {'level', 'velocity'} target=msg.zoom)) # [1, 3]
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 function_10(): drone( start_recording(cam_id=0, _timeout=10, _no_expect=False, _float_tol=(1e-07, 1e-09)) >> f.write("drone(") >> f.write("\n") >> f.write(" start_recording(cam_id=0, _timeout=10, _no_expect=False, _float_tol=(1e-07, 1e-09))") >> f.write("\n") >> f.write(")") >> f.write("\n") )
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"))
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)
def test_asyncaction(): with olympe.Drone(DRONE_IP) as drone: drone.connect() # Start a flying action asynchronously flyingAction = drone( TakeOff() >> FlyingStateChanged(state="hovering", _timeout=5) >> moveBy(10, 0, 0, 0) >> FlyingStateChanged(state="hovering", _timeout=5) >> Landing()) # Start video recording while the drone is flying if not drone(start_recording(cam_id=0)).wait().success(): assert False, "Cannot start video recording" # Send a gimbal pitch velocity target while the drone is flying cameraAction = drone( gimbal.set_target( gimbal_id=0, control_mode="velocity", yaw_frame_of_reference="none", yaw=0.0, pitch_frame_of_reference="none", pitch=0.1, roll_frame_of_reference="none", roll=0.0, )).wait() if not cameraAction.success(): assert False, "Cannot set gimbal velocity target" # Wait for the end of the flying action if not flyingAction.wait().success(): assert False, "Cannot complete the flying action" # Stop video recording while the drone is flying if not drone(stop_recording(cam_id=0)).wait().success(): assert False, "Cannot stop video recording" # Leaving the with statement scope: implicit drone.disconnect() but that # is still a good idea to perform the drone disconnection explicitly drone.disconnect()
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"))
from olympe.messages.camera import start_recording, stop_recording from olympe.messages import gimbal with olympe.Drone("10.202.0.1") as drone: drone.connection() # Start a flying action asynchronously flyingAction = drone( TakeOff() >> FlyingStateChanged(state="hovering", _timeout=5) >> moveBy(3, 0, 0, 0) # >> FlyingStateChanged(state="hovering", _timeout=5) # there is currently a bug in firmware. Just rely on moveBy expection for now >> Landing() ) # Start video recording while the drone is flying if not drone(start_recording(cam_id=0)).wait().success(): raise RuntimeError("Cannot start video recording") # Send a gimbal pitch velocity target while the drone is flying cameraAction = drone(gimbal.set_target( gimbal_id=0, control_mode="velocity", yaw_frame_of_reference="none", yaw=0.0, pitch_frame_of_reference="none", pitch=0.1, roll_frame_of_reference="none", roll=0.0, )).wait() if not cameraAction.success():
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"))
>>>>>>> 1d491c6b6b0ad141dc94e80d05adbb491ba5e36e 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/rnallapu/code/Results") media_info_response = requests.get(ANAFI_MEDIA_API_URL + media_id)