points = [] target = "DJI_0635.JPG" path = "/home/taylor/Pictures/mapping/cap_dec_2_2020/images/" target_path = os.path.join(path, target) target_coords = get_decimal_coordinates(get_exif(target_path)) target_gps = gps_tools.GpsPoint(target_coords[0], target_coords[1]) for r, d, f in os.walk(path): for file in f: if file.lower().endswith(('.png', '.jpg', '.jpeg')): filepath = os.path.join(r, file) coords = get_decimal_coordinates(get_exif(filepath)) gps_point = gps_tools.GpsPoint(coords[0], coords[1]) distance = gps_tools.get_distance(target_gps, gps_point) if coords is not None and distance < 50: points.append( (coords[0], coords[1], os.path.basename(filepath))) index = 0 # exif = get_exif('/home/taylor/Pictures/mapping/cap_dec_2_2020/images/DJI_0173.JPG') # coords = get_decimal_coordinates(exif) out_path = "/home/taylor/Pictures/mapping/cap_dec_2_2020/gps_test/" # os.mkdir(out_path) import shutil print("name, dec, latitude, longitude, n") for coords in points: name = coords[2]
def rtk_loop_once(tcp_sock1, tcp_sock2, buffers, print_gps=False, last_sample=None, retries=3, logger=None): if not logger: raise RuntimeError("No Logger Specified") errors = 0 # print(buffers) blocking_exception = None while True: try: data0 = tcp_sock1.recv(TCP_BUFFER_SIZE).decode('utf-8') data1 = tcp_sock2.recv(TCP_BUFFER_SIZE).decode('utf-8') buffers[0] += data0 buffers[1] += data1 buffers[0], data1 = digest_data(buffers[0], logger) buffers[1], data2 = digest_data(buffers[1], logger) # print("Read GPS duration {}".format(time.time() - start_time)) break except BlockingIOError as e: blocking_exception = e #print("GPS BlockingIOError") except Exception as e: logger.error("GPS ERROR DURING READ: {}".format(e)) errors += 1 time.sleep(_FAST_POLLING_DELAY_S) if errors > retries: # if blocking_exception is not None: # print("ERROR GPS DATA NOT AVAILABLE") # print("TOO MANY GPS ERRORS") return buffers, None try: if data1 and data2: azimuth_degrees = gps_tools.get_heading( data1, data2) + VEHICLE_AZIMUTH_OFFSET_DEG d = gps_tools.get_distance(data1, data2) lat = (data1.lat + data2.lat) / 2.0 lon = (data1.lon + data2.lon) / 2.0 #print("HEIGHT DIFFERENCE {}".format(data1.height_m - data2.height_m)) height_m = (data1.height_m + data2.height_m) / 2.0 rtk_age = max([data1.rtk_age, data2.rtk_age]) latest_sample = gps_tools.GpsSample(lat, lon, height_m, (data1.status, data2.status), ( data1.num_sats, data2.num_sats), azimuth_degrees, data1.time_stamp, rtk_age) if last_sample: period = latest_sample.time_stamp - last_sample.time_stamp else: period = None #print("GPS DEBUG: FIX reads... : {}".format(latest_sample.status)) if print_gps: fix1 = data1.status == "fix" fix2 = data2.status == "fix" logger.info("Lat: {:.10f}, Lon: {:.10f}, Azimuth: {:.2f}, Distance: {:.4f}, Fixes: ({}, {}), Period: {:.2f}".format( latest_sample.lat, latest_sample.lon, azimuth_degrees, d, fix1, fix2, period)) return buffers, latest_sample else: logger.error("Missing GPS Data") return buffers, None except KeyboardInterrupt as e: raise e except BlockingIOError: return buffers, None except Exception as e: logger.error("GPS ERROR DURING PROCESSING: {}".format(e)) return buffers, None
new_path = new_path[-4320:-2200] print(len(new_path)) # new_path = new_path[:100] # print(new_path) dict_path = [] new = [] for idx in range(0, len(new_path), 4): new.append(new_path[idx]) new_path = new # new_path[0] last_distance = 0 print("%%%%%%%%%%%%%%%%%%") for point in new_path: # print(point._asdict()) try: distance = gps_tools.get_distance(point, new_path[0]) if distance < last_distance: print("EUEHGJKLEHGELJHG") # last_distance = distance print(gps_tools.get_distance(point, new_path[0])) last_distance = distance # dict_path.append(point._asdict()) except Exception as e: print(e) pass r.set('twistedfields:gpspath:aaa_test:key', pickle.dumps(dict_path)) r.set('twistedfields:gpspath:parking_to_upper_field:key', pickle.dumps(dict_path)) sys.exit()
else: last_bad_status_time = time.time() while len(position_list) > 0: if latest_sample.time_stamp - position_list[0].time_stamp > STATIONARY_TIME: position_list.pop(0) else: break if time.time() - last_bad_status_time < 30 and time.time() - bad_tone_time > 30: bad_tone_time = time.time() print("Bad status") subprocess.Popen("aplay /home/pi/error.wav", shell=True) if len(position_list) > 100 and time.time() - last_bad_status_time > STATIONARY_TIME: device_stationary = True max_distance = 0 for position in position_list: distance = gps_tools.get_distance(latest_sample, position) if distance > max_distance: max_distance = distance if distance > 0.05: device_stationary = False if device_stationary: print("Device Stationary") if save_file_okay: # save the file location_string = "Lat Lon: {:.10f}, {:.10f}, Height M: {:.4f}, Fix: {}, Spread: {}, Stamp: {:.4f}".format( latest_sample.lat, latest_sample.lon, latest_sample.height_m, latest_sample.status, max_distance, latest_sample.time_stamp) print(location_string) with open("/home/pi/gps_locations.txt", "a+") as gps_file: gps_file.write(location_string + "\n") save_file_okay = False if time.time() - good_tone_time > 10: