curr_lon = 0 curr_lat_temp = curr_lat curr_lon_temp = curr_lon if prev_lat == curr_lat and prev_lon == curr_lon: curr_lat_temp = 0 curr_lon_temp = 0 else: prev_lat = curr_lat prev_lon = curr_lon logged_data += str(curr_lat_temp) + ',' + str( curr_lon_temp) + ',' + str(data_stream.TPV['time'] + ',') break else: continue if hf.if_in_depot(float(curr_lat), float(curr_lon)) or sp_count < 5: if DEPOT_BEGIN: os.system("./final_upload.sh") print('In depot (hopefully), gonna exit soon') time.sleep(0.1) STARTED_FROM_DEPOT = True if RETURN_TO_DEPOT: if file_open: outfile.close() file_open = False os.system("./final_upload.sh") print('Returned to depot') # remove last logged file as not on route if file_open: outfile_name = open('current_file.txt', 'r') filename = outfile_name.readline()
logged_data_can += '{0:d},'.format( int(throttle)) + '{0:d},'.format(int(rpm)) + '{0:d},'.format( int(speed)) + acceleration + ',' + jerk + ',' logged_data_can += logged_data_gps if distance_half_sec != 'n/a': logged_data_can += ',{0:f},{1:f},{2:f},{3:f}'.format( distance_total, distance_interval, distance_half_sec, distance) else: logged_data_can += ',{0:f},{1:f},'.format( distance_total, distance_interval ) + distance_half_sec + ',{0:f}'.format(distance) if file_open: print(logged_data_can, file=outfile_can) # geofence logic begins if hf.if_in_depot(float(curr_lat), float(curr_lon), distance_total, RETURN_TO_DEPOT, vspeed2): if DEPOT_BEGIN: #os.system("./final_upload.sh") #print('D') if not file_open: file_name_can = 'Documents/logs/log_DOJ_' + datetime.now( ).strftime('%Y_%m_%d_%H_%M_%S') + '.csv' # save file name outfile_name = open('current_file.txt', 'w+') print(file_name_can, file=outfile_name) outfile_name.close() # write to a new file outfile_can = open(file_name_can, 'w+') print('Logging to first file') file_open = True STARTED_FROM_DEPOT = True
if curr_lon == 'n/a': curr_lon = 0; curr_lat_temp = curr_lat curr_lon_temp = curr_lon if prev_lat == curr_lat and prev_lon == curr_lon: curr_lat_temp = 0 curr_lon_temp = 0 else: prev_lat = curr_lat prev_lon = curr_lon logged_data += str(curr_lat_temp) + ',' + str(curr_lon_temp) + ',' + str(data_stream.TPV['time'] + ',') break else: continue if hf.if_in_depot(float(curr_lat),float(curr_lon),distance_total) or sp_count < 5: if DEPOT_BEGIN: #os.system("./final_upload.sh") print('D') time.sleep(0.1) if not file_open: file_name = 'Documents/logs/log_DOJ_' + str(datetime.now()) + '.csv' # save file name outfile_name = open('current_file.txt','w+') print(file_name,file = outfile_name) outfile_name.close() # write to a new file outfile = open(file_name,'w+') print('Logging to first file') file_open = True STARTED_FROM_DEPOT = True