Study: Robotics(Robot)/Robot: Positioning

[Positioning] ROS GPS(WGS84) to UTM μ’Œν‘œ λ³€ν™˜ν•˜κΈ°

DrawingProcess 2023. 9. 30. 18:40
λ°˜μ‘ν˜•
πŸ’‘ λ³Έ λ¬Έμ„œλŠ” 'ROS GPS(WGS84) to UTM μ’Œν‘œ λ³€ν™˜ν•˜κΈ°'에 λŒ€ν•΄ 정리해놓은 κΈ€μž…λ‹ˆλ‹€.
GPS(WGS84), UTM μ’Œν‘œκ³„ μžμ²΄μ— λŒ€ν•œ 이해뢀터 이λ₯Ό λ³€ν™˜ν•˜λŠ” 라이브러리 μ‚¬μš©λ°©λ²•κΉŒμ§€ μ •λ¦¬ν•˜μ˜€μœΌλ‹ˆ μ°Έκ³ ν•˜μ‹œκΈ° λ°”λžλ‹ˆλ‹€.

1. μ’Œν‘œκ³„ 이해

1) GPS(WGS84)

WGSλŠ” World Gedetic System coordinate의 약어이며, WGS84 μ’Œν‘œκ³„μ—μ„œ 84λŠ” 84년도에 μ œμ •λœ μ’Œν‘œκ³„μž…λ‹ˆλ‹€.

μ΄λŠ” 타원체 λͺ¨μ–‘μ˜ 지ꡬ상 μœ„μΉ˜λ₯Ό ν‘œν˜„ν•˜κΈ° μœ„ν•œ μ’Œν‘œκ³„λ‘œ, μ λ„와 λ³Έμ΄ˆμžμ˜€μ„ μ΄ κ΅μ°¨ν•˜λŠ” 점을 기쀀점(0.0º, 0.0º)으둜 ν•©λ‹ˆλ‹€.

λ”°λΌμ„œ ν‘œν˜„ μžμ²΄λŠ” μ •ν™•ν•˜λ‚˜, 타원체 μžμ²΄μ—μ„œμ˜ μœ„μΉ˜λ₯Ό ν‘œν˜„ν•˜κΈ°μ— 면적 거리λ₯Ό κ³„μ‚°ν•˜λŠ” 데 어렀움을 κ²ͺ을 수 μžˆμŠ΅λ‹ˆλ‹€.

2) UTM

UTM μ’Œν‘œκ³„λŠ” Universal Transverse Mercator Coordinate System의 μ•½μ–΄μž…λ‹ˆλ‹€.

μ΄λŠ” 도면 μœ„μ— 지ꡬλ₯Ό λ„“κ²Œ νŽ΄μ„œ ν‘œμ‹œν•œλ‹€κ³  μƒκ°ν•˜λ©΄ μ΄ν•΄ν•˜κΈ° μ‰¬μš°λ©°, μ •ν™•νžˆλŠ” 3도λ₯Ό κΈ°μ€€μœΌλ‘œ 지ꡬλ₯Ό 60쑰각으둜 λ‚˜λˆˆ ν›„ 각 단면 펼쳐 μ§μ‚¬κ°ν˜• ν˜•νƒœλ‘œ λ§Œλ“ λ‹€κ³  μƒκ°ν•˜λ©΄ λ©λ‹ˆλ‹€.

λ”°λΌμ„œ μ›ν˜•μ„ νŽ΄λŠ” 방식이닀 λ³΄λ‹ˆ μ™œκ³‘μ΄ μ‘΄μž¬ν•©λ‹ˆλ‹€λ§Œ, 면적 거리λ₯Ό κ³„μ‚°ν•˜λŠ” 데 μš©μ΄ν•©λ‹ˆλ‹€.

2. μ’Œν‘œ λ³€ν™˜ν•˜κΈ°(WGS84 <=> UTM)

1) Python (library: utm)

utm λΌμ΄λΈŒλŸ¬λ¦¬λŠ” 'Bidirectional UTM-WGS84 converter for python'이라 μ„€λͺ…λ˜μ–΄ 있으며, μ–‘λ°©ν–₯으둜 λ³€ν™˜ν•˜λŠ” 파이썬 λΌμ΄λΈŒλŸ¬λ¦¬μž…λ‹ˆλ‹€. λ‹€μŒκ³Ό 같이 μ„€μΉ˜ν•΄μ„œ μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

$ pip install utm

Usage

>>> import utm
Latitude/Longitude to UTM

Convert a (latitude, longitude) tuple into an UTM coordinate:

>>> utm.from_latlon(51.2, 7.5)
(395201.3103811303, 5673135.241182375, 32, 'U')
  • The syntax is utm.from_latlon(LATITUDE, LONGITUDE).
  • The return has the form (EASTING, NORTHING, ZONE_NUMBER, ZONE_LETTER).

You can also use NumPy arrays for LATITUDE and LONGITUDE. In the result EASTING and NORTHING will have the same shape. ZONE_NUMBER and ZONE_LETTER are scalars and will be calculated for the first point of the input. All other points will be set into the same UTM zone. Therefore it's a good idea to make sure all points are near each other.

>>> utm.from_latlon(np.array([51.2, 49.0]), np.array([7.5, 8.4]))
(array([395201.31038113, 456114.59586214]), array([5673135.24118237, 5427629.20426126]), 32, 'U')

UTM to Latitude/Longitude Convert an UTM coordinate into a (latitude, longitude) tuple:

>>> utm.to_latlon(340000, 5710000, 32, 'U')
(51.51852098408468, 6.693872395145327)
  • The syntax is utm.to_latlon(EASTING, NORTHING, ZONE_NUMBER, ZONE_LETTER).
  • The return has the form (LATITUDE, LONGITUDE).

You can also use NumPy arrays for EASTING and NORTHING. In the result LATITUDE and LONGITUDE will have the same shape. ZONE_NUMBER and ZONE_LETTER are scalars.

>>> utm.to_latlon(np.array([395200, 456100]), np.array([5673100, 5427600]), 32, 'U')
(array([51.19968297, 48.99973627]), array([7.49999141, 8.3998036 ]))

Since the zone letter is not strictly needed for the conversion you may also the northern parameter instead, which is a named parameter and can be set to either True or False. Have a look at the unit tests to see how it can be used.

2) C++ (library: GeographicLib)

1. 라이브러리 μ„€μΉ˜ 및 PATH 등둝

Installation using the autoconfigure tools. The method works on most Unix-like systems including Linux and Mac OS X. Here are the steps to compile and install GeographicLib:

Unpack the source, running

$ tar xfpz GeographicLib-1.44.tar.gz

then enter the directory created, Create a separate build directory and enter it.

cd GeographicLib-1.44
mkdir build
cd build
# Configure the software, specifying the path of the source directory, with
$ ../configure
# By default GeographicLib will be installed under /usr/local. You can change this with, for example
$ ../configure --prefix=/tmp/geographic

Compile and install the software with

make
make install

The headers, library, and utilities are installed in the include/GeographicLib, lib, and bin directories under prefix. For documentation, open share/doc/GeographicLib/html/index.html in a web browser.

2. CMakeLists 파일 μˆ˜μ •

find_package(GeographicLib REQUIRED)
target_link_libraries ${GeographicLib_LIBRARIES}

3. μ½”λ“œ μž‘μ„±

void WGS2UTM(double lat, double lon, double& easting, double& northing){
  int zone;
  bool northp;
  GeographicLib::UTMUPS::Forward(lat, lon, zone, northp, easting, northing);
  std::string zonestr = GeographicLib::UTMUPS::EncodeZone(zone, northp);
}

μ°Έκ³ 

λ°˜μ‘ν˜•