def get_GPS_Pos(self, microsoft_relative_GPS_pos: GPSCoordinate):
        '''AirSim calculates GPS position in relation to microsoft headquarters, 
        this method gives the GPS position relative to the home coordinate set by the constructor.'''
        #calculate lat, long distance from current position to microsoft home coordinate
        if not isinstance(microsoft_relative_GPS_pos, GPSCoordinate):
            raise Exception("Please provide a valid WGS84 GPS coordinate")
        #metres_lat = microsoft_relative_GPS_pos.get_lat_metres_to_other(GPSToUnreal.ORIGIN_GPS)
        #metres_lng = microsoft_relative_GPS_pos.get_long_metres_to_other(GPSToUnreal.ORIGIN_GPS)

        #if microsoft_relative_GPS_pos.lat < GPSToUnreal.ORIGIN_GPS.lat:
        #    metres_lat =- lat_dist
        #if microsoft_relative_GPS_pos.long < GPSToUnreal.ORIGIN_GPS.long:
        #    metres_lat =- lng_dist
        #if microsoft_relative_GPS_pos.alt:
        #    metres_alt = microsoft_relative_GPS_pos.alt

        #then add this distance to home coordinate
        #first calculate azimuth (will probably be ok to do this as dealing with small(ish) angles
        bearing = GPSToUnreal.ORIGIN_GPS.get_initial_bearing(
            microsoft_relative_GPS_pos)
        distance = microsoft_relative_GPS_pos.get_metres_to_other(
            GPSToUnreal.ORIGIN_GPS)
        destination = GPSCoordinate._vincentyGeodesicDirect(
            self.home_position_GPS, distance, bearing)
        return destination
    def testGetMoveToPosXYZFromGPSCoord(self):
        mapper1 = GPSToUnreal(self.NUIGCoordinate)
        UECoord1 = mapper1.getMoveToPosXYZFromGPSCoord(
            self.EyreSquareCoordinate)
        #nuig coordinate to eyre square coordinate
        self.assertAlmostEqual(UECoord1[0], -731.3, delta=10)
        self.assertAlmostEqual(UECoord1[1], 1183, delta=20)

        #check that signs change
        mapper2 = GPSToUnreal(self.EyreSquareCoordinate)
        UECoord2 = mapper2.getMoveToPosXYZFromGPSCoord(self.NUIGCoordinate)
        self.assertAlmostEqual(UECoord2[0], 730, delta=20)
        self.assertAlmostEqual(UECoord2[1], -1183, delta=20)

        nuigRectCoord1 = GPSCoordinate(53.2787637762, -9.0634679794)
        nuigRectCoord2 = GPSCoordinate(53.2787637762, -9.0601420403)
        nuigRectCoord3 = GPSCoordinate(53.2810987761, -9.0601420403)
        nuigRectCoord4 = GPSCoordinate(53.2810987761, -9.0634679794)

        mapper3 = GPSToUnreal(GPSCoordinate(53.280, -9.062, 0))
        rect_coords = [
            nuigRectCoord1, nuigRectCoord2, nuigRectCoord3, nuigRectCoord4
        ]
        for coord in rect_coords:
            print(mapper1.getMoveToPosXYZFromGPSCoord(coord))
 def testGetMetresBetweenPoints(self):
     self.assertAlmostEqual(GPSCoordinate.getMetresBetweenPoints(
         self.OConnellStreetCoordinate, self.EyreSquareCoordinate),
                            185629,
                            delta=5000)
     self.assertAlmostEqual(GPSCoordinate.getMetresBetweenPoints(
         self.EyreSquareCoordinate, self.NUIGCoordinate),
                            1394,
                            delta=50)
def read_GPS_coords(gps_coords_file_path) -> "A list of gps coords":
	'''Reads in a list of gps coordinates'''
	try:
		#read file but skip header
		gps_coords = open(gps_coords_file_path, 'r').readlines()[1:]
	except FileNotFoundError as e:
		#don't handle this for now...
		raise e
	
	try:
		gps_coords = [GPSCoordinate(coord.replace('\n','').split(',')[0], coord.replace('\n','').split(',')[1], coord.replace('\n','').split(',')[2])for coord in filter(lambda gps_coord: gps_coord != '\n', gps_coords)]
	except IndexError as e:
		#don't handle for now
		gps_coords = [GPSCoordinate(coord.replace('\n','').split(',')[0], coord.replace('\n','').split(',')[1]) for coord in filter(lambda gps_coord: gps_coord != '\n', gps_coords)]
	print('gps_coords: ',gps_coords)
	return gps_coords
Beispiel #5
0
def main(
    GPS_CSV: 'file path to csv containing gps coordinates',
    desination_UE4_coord_file='file to save converted UE4 coordinates',
    GPS_home_pos:
    "GPSCoordinate which records where the RAV home position is located" = GPSCoordinate(
        53.2793, -9.0638)):
    gps_coords = read_GPS_coords(GPS_CSV)
    converter = GenerateUECoordsFromGPS(GPS_home_pos)
    UE4_coords = converter.convert_GPS_list_to_UE4(gps_coords)
    write_UE4_coords(desination_UE4_coord_file, UE4_coords)
    def testGet_GPS_Pos(self):
        mapper1 = GPSToUnreal(self.NUIGCoordinate)
        #pos = mapper1.get_GPS_Pos()
        redmond_campus_coord = GPSCoordinate(47.6477308, -122.1321476)
        #should be 696 m lat, 600 long
        #close enough
        print(mapper1.get_GPS_Pos(redmond_campus_coord))


#		self.assertAlmostEqual(OConnellStreetCoordinate.getMetresBetweenPoints(EyreSquareCoordinate),186270 delta = 5000)
#		self.assertAlmostEqual(NUIGCoordinate.getMetresBetweenPoints(EyreSquareCoordinate),836 delta = 50)
 def testGetInitialBearing(self):
     #taken from https://www.movable-type.co.uk/scripts/latlong.html
     osaka = GPSCoordinate(35, 135)
     baghdad = GPSCoordinate(35, 45)
     self.assertAlmostEqual(osaka.get_initial_bearing(baghdad), 60, delta=5)
     self.assertAlmostEqual(baghdad.get_initial_bearing(osaka),
                            360 - 60,
                            delta=5)
 def setUp(self):
     self.OConnellStreetCoordinate = GPSCoordinate(53.3512416, -6.2629676,
                                                   0)
     self.EyreSquareCoordinate = GPSCoordinate(53.2743394, -9.0514163)
     self.NUIGCoordinate = GPSCoordinate(53.2809159, -9.0692133, 20)
	def __init__(self, home_position_GPS: GPSCoordinate = GPSCoordinate(53.2793, -9.0638), home_position_UE4 = UE4Coord(0,0,0)):
		#set home gps position
		self.home_position_GPS = home_position_GPS
		self.home_position_UE4 = home_position_UE4
		self.GPS_to_unreal_converter = GPSToUnreal(home_position_GPS)
class GPSToUnreal:
    # this is taken as origin (0,0)
    # EYRE_SQUARE_COORD = GPSCoordinate(53.2745, -9.049, 0)
    # NUIG
    # EYRE_SQUARE_COORD = GPSCoordinate(53.276, -9.057, 0)
    # not quite eyre square, but close enough!
    #HOME_COORD = GPSCoordinate(53.280, -9.062, 0)
    ORIGIN_GPS = GPSCoordinate(47.641468, -122.140165, 122)

    # transormation that maps a GPS position from the microsoft office origin
    # to the Eyre square coordinate
    #DELTA_TRANSFORM = HOME_COORD - ORIGIN_GPS

    # home_position_GPS is the home gps location of the drone in AirSim
    def __init__(self,
                 home_position_GPS: GPSCoordinate = GPSCoordinate(
                     53.2793, -9.0638)):
        '''Set the home gps coordinate of the rav'''
        self.home_position_GPS = home_position_GPS

    def getMoveToPosXYZFromGPSCoord(self, desired_GPS_position: GPSCoordinate):
        '''Returns the XYZ Unreal Engine NED coordinatee position to move to in order to reach the desired gps position'''

        if not isinstance(desired_GPS_position, GPSCoordinate):
            raise Exception("Please provide a valid WGS84 GPS coordinate")

        metres_lat = self.home_position_GPS.get_lat_metres_to_other(
            desired_GPS_position)
        metres_long = self.home_position_GPS.get_long_metres_to_other(
            desired_GPS_position)
        metres_alt = self.home_position_GPS.get_alt_metres_to_other(
            desired_GPS_position)

        #check whether the lat/long difference is positive or negative (metres to other methods give abs values)
        if desired_GPS_position.lat < self.home_position_GPS.lat:
            metres_lat = -metres_lat
        if desired_GPS_position.long < self.home_position_GPS.long:
            metres_long = -metres_long

        #altitudes in games engine are negative
        return (metres_lat, metres_long, -abs(metres_alt))

    def get_GPS_Pos(self, microsoft_relative_GPS_pos: GPSCoordinate):
        '''AirSim calculates GPS position in relation to microsoft headquarters, 
        this method gives the GPS position relative to the home coordinate set by the constructor.'''
        #calculate lat, long distance from current position to microsoft home coordinate
        if not isinstance(microsoft_relative_GPS_pos, GPSCoordinate):
            raise Exception("Please provide a valid WGS84 GPS coordinate")
        #metres_lat = microsoft_relative_GPS_pos.get_lat_metres_to_other(GPSToUnreal.ORIGIN_GPS)
        #metres_lng = microsoft_relative_GPS_pos.get_long_metres_to_other(GPSToUnreal.ORIGIN_GPS)

        #if microsoft_relative_GPS_pos.lat < GPSToUnreal.ORIGIN_GPS.lat:
        #    metres_lat =- lat_dist
        #if microsoft_relative_GPS_pos.long < GPSToUnreal.ORIGIN_GPS.long:
        #    metres_lat =- lng_dist
        #if microsoft_relative_GPS_pos.alt:
        #    metres_alt = microsoft_relative_GPS_pos.alt

        #then add this distance to home coordinate
        #first calculate azimuth (will probably be ok to do this as dealing with small(ish) angles
        bearing = GPSToUnreal.ORIGIN_GPS.get_initial_bearing(
            microsoft_relative_GPS_pos)
        distance = microsoft_relative_GPS_pos.get_metres_to_other(
            GPSToUnreal.ORIGIN_GPS)
        destination = GPSCoordinate._vincentyGeodesicDirect(
            self.home_position_GPS, distance, bearing)
        return destination
 def __init__(self,
              home_position_GPS: GPSCoordinate = GPSCoordinate(
                  53.2793, -9.0638)):
     '''Set the home gps coordinate of the rav'''
     self.home_position_GPS = home_position_GPS
Beispiel #12
0
    parser.add_argument(
        "GPS_home_pos_lat",
        type=float,
        metavar="GPS_home_pos_lat",
        nargs='?',
        help="latitude which records where the RAV home position is located")
    parser.add_argument(
        "GPS_home_pos_lng",
        type=float,
        metavar="GPS_home_pos_lng",
        nargs='?',
        help="longitude which records where the RAV home position is located")
    parser.add_argument(
        "GPS_home_pos_alt",
        type=float,
        metavar="GPS_home_pos_alt",
        nargs='?',
        help="altitude which records where the RAV home position is located")

    args = vars(parser.parse_args())
    print(args)
    if args["GPS_home_pos_lat"] and args["GPS_home_pos_lng"]:
        args["GPS_home_pos"] = GPSCoordinate(args["GPS_home_pos_lat"],
                                             args["GPS_home_pos_lng"],
                                             args["GPS_home_pos_alt"])

    del args["GPS_home_pos_lat"]
    del args["GPS_home_pos_lng"]
    del args["GPS_home_pos_alt"]

    main(**args)