def main(): target_file = open("target_positions_gps.txt") # Recieve GPS target position line = target_file.readline() if line != "": t, lat, long = line.split(",") target_loc = GPSCoord.from_nmea(lat.strip(), long.strip()) while True: time.sleep(1) # Recieve GPS target position line = target_file.readline() if line != "": t, lat, long = line.split(",") else: target_file.close break prev_target_loc = target_loc target_loc = GPSCoord.from_nmea(lat.strip(), long.strip()) dest = swarming_checks(drones, target_loc, prev_target_loc) if dest != None: print("target lat:{} long:{} dest lat:{} long:{}".format( target_loc.lat, target_loc.long, dest.lat, dest.long))
def read_coordinate(self): """ Reads the coordinates from the next line of the given file, and returns it as a GPSCoord. Each line of the file contains time, latitude and longitude in NMEA format. """ time, latitude, longitude = self.target_pos_file.readline().split(",") return GPSCoord.from_nmea(latitude.strip(), longitude.strip())
def main(): target_file = open("target_positions_gps.txt") while True: time.sleep(1) # Recieve GPS target position line = target_file.readline() if line != "": t, lat, long = line.split(",") else: target_file.close break # Output desired position target_loc = GPSCoord.from_nmea(lat.strip(), long.strip()) desired_loc = swarming_logic.update_loc(target_loc, drone_num) print("Target Loc: {} Desired Loc: {}".format(target_loc, desired_loc))
def main(): # Socket to send readings to the client. socket = init_socket() ser = serial.Serial('../../../../../../../dev/tty.usbserial', 4800, timeout=5) line = ser.readline( ) # Read remaining junk line so that next line is clean while True: # Change this to readings from the GPS module. # time_sample = "Sat Aug 3 14:21:15 2019" # latitude = "4331.23049S" # longitude = "17234.98533E" line = ser.readline().decode('utf-8') splitline = line.split(",") if splitline[0] == GPGGA: date = time.localtime(time.time()) gps_time = "{}:{}:{}".format(splitline[1][:2], splitline[1][2:4], splitline[1][4:-4]) time_sample = "{} {} {} {} {}".format(WEEKDAYS[date.tm_wday], MONTHS[date.tm_mon - 1], date.tm_mday, gps_time, date.tm_year) latitude_nmea = splitline[2] + splitline[3] longitude_nmea = splitline[4] + splitline[5] coord = GPSCoord.from_nmea(latitude_nmea, longitude_nmea) print_message = "{},{:.5f},{:.5f}".format(time_sample, coord.lat, coord.long) message = "{},{:.5f},{:.5f}".format(time_sample, coord.lat, coord.long) storage = open("gps_storage.txt", "w") storage.write(message + '\n') print("Sending: {}".format(print_message)) # Send new gps data to NUC socket.send(message.encode('utf-8'))