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 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 Setup_Photo_mode(drone): drone(stop_recording(cam_id=0)).wait() drone(set_autorecord(cam_id=0, state="inactive")).wait() drone(set_camera_mode(cam_id=0, value="photo")).wait() # For the file_format: jpeg is the only available option # dng is not supported in burst mode drone( set_exposure_settings( cam_id=0, mode="automatic_prefer_iso_sensitivity", shutter_speed="shutter_1_over_10000", iso_sensitivity="iso_1200", max_iso_sensitivity="iso_1200", ) ).wait() drone( set_photo_mode( cam_id=0, mode="single", format="rectilinear", file_format="jpeg", burst="burst_14_over_4s", bracketing="preset_1ev", capture_interval=0.0, ) ).wait()
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 function_11(): drone( stop_recording(cam_id=0, _timeout=10, _no_expect=False, _float_tol=(1e-07, 1e-09)) >> f.write("drone(") >> f.write("\n") >> f.write(" stop_recording(cam_id=0, _timeout=10, _no_expect=False, _float_tol=(1e-07, 1e-09))") >> f.write("\n") >> f.write(")") >> f.write("\n") )
def __init__(self, D_IP, nm, lr): self.name = nm loc = "/home/spacetrex/code/Logs/" tck = str(round(time.time())) lf_nm = loc + nm + tck self.D_IP = D_IP #self.drone = olympe.Drone(self.D_IP, loglevel=7, logfile=open(lf_nm, "a+")) self.drone = olympe.Drone(self.D_IP, loglevel=0) self.drone.connection() self.drone(stop_recording(cam_id=0)).wait() self.drone(set_camera_mode(cam_id=0, value="recording")).wait() self.loop_rate = lr # Set loop rate (Hz) self.X_tol = 0.5 # Position tolerance (m) self.V_tol = 0.1 # Velocity tolerance(m/s) self.yw_tol = 2.0 * pi / 180.0 # Yaw rate tolerance (rads) self.Tt_MX = 10 # Max tilt setting for yaw and pitch (deg) self.Tl_Mx = 4 # Max vertical speed (m/s) self.YR_MX = 22 # Max yaw rate (deg/s) self.GB_MX = 50 # Max gimbal rate (deg/s) self.thr_vec = [self.Tt_MX, self.Tt_MX, self.Tl_Mx, self.YR_MX] # Drone settings self.gn_mat = [3.6, 18.0, 3.6, 18.0, 5.0, 9.0, 2.0] # Controller Gains #self.gn_mat = [6, 18, 4, 5, 11, 2] self.ANAFI_IP = D_IP # Real Drone # Drone web server URL self.ANAFI_URL = "http://{}/".format(self.ANAFI_IP) self.ANAFI_MEDIA_API_URL = self.ANAFI_URL + "api/v1/media/medias/" # Set Rotation Speed maxYawRate = self.drone(MaxRotationSpeed(self.YR_MX)).wait() if maxYawRate.success(): print(colored(("Max Yaw rate set to: ", self.YR_MX), "green")) elif maxYawRate.timedout(): print(colored(("Yaw rate action failed"), "green")) else: print(colored(("Yaw rate action in progress"), "green")) # Set Gimbal Speed max_GMB_Rate = self.drone( set_max_speed(gimbal_id=0, yaw=self.GB_MX / 5, pitch=self.GB_MX, roll=self.GB_MX / 5)).wait() if max_GMB_Rate.success(): print( colored(("Max gimbal pitch rate set to: ", self.GB_MX), "green")) elif max_GMB_Rate.timedout(): print(colored(("gimbal rate action failed"), "green")) else: print(colored(("gimbal rate action in progress"), "green"))
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 Setup_Video_mode(drone): drone(stop_recording(cam_id=0)).wait() drone(set_camera_mode(cam_id=0, value="recording")).wait() drone(set_autorecord(cam_id=0, state="inactive")).wait() drone( set_recording_mode( cam_id=0, mode="standard", resolution="res_uhd_4k", framerate="fps_30", hyperlapse="ratio_15", ) ).wait(_timeout=2.).success()
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"))
colored(('Invalid action selected, please select again! \n'), "red")) def listener(): rospy.init_node('anafi_5_listener', anonymous=True) #this topic needs to be changed for each computer rospy.Subscriber("anafi_5/master", Int16, callback) rospy.spin() if __name__ == '__main__': try: signal(SIGINT, Drone_land) global Dr_cl Dr_IP = "192.168.42.1" # Real Drone Dr_cl = Anafi_drone(Dr_IP) drone = Dr_cl.drone drone(stop_recording(cam_id=0)) x0 = 5 print('\x1bc') X_Ref = Drone_Actns_5(x0, drone) listener() except rospy.ROSInterruptException: rospy.loginfo("node terminated")
# 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(): raise RuntimeError("Cannot set gimbal velocity target") # Wait for the end of the flying action if not flyingAction.wait().success(): print(drone.get_state(FlyingStateChanged)['state']) raise RuntimeError("Cannot complete the flying action") # Stop video recording while the drone is flying if not drone(stop_recording(cam_id=0)).wait().success(): raise RuntimeError("Cannot stop video recording") # Leaving the with statement scope: implicit drone.disconnection()
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"))