coordinates module

Functions for coordinate conversions required by GPS.

Based on code from https://github.com/commaai/laika whose license is copied below:

MIT License

Copyright (c) 2018 comma.ai

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

class coordinates.LocalCoord(init_geodetic, init_ecef)[source]

Bases: object

Class for conversions to NED (North-East-Down).

init_ecef

ECEF of origin of NED.

Type:

np.ndarray

ned_to_ecef_matrix

Rotation matrix to convert from NED to ECEF.

Type:

np.ndarray

ecef_to_ned_matrix

Rotation matrix to convert from ECEF to NED.

Type:

np.ndarray

Notes

Based on code from https://github.com/commaai/laika.

ecef_to_ned(ecef)[source]

Convert ECEF position vectors to NED position vectors.

Parameters:

ecef (np.ndarray) – Float with ECEF position vectors.

Returns:

ned – Converted NED position vectors.

Return type:

np.ndarray

Notes

Based on code from https://github.com/commaai/laika.

ecef_to_nedv(ecef)[source]

Convert ECEF free vectors to NED free vectors.

Parameters:

ecef (np.ndarray) – Float with free vectors in the ECEF frame of reference.

Returns:

ned – Converted free vectors in the NED frame of reference.

Return type:

np.ndarray

Notes

Based on code from https://github.com/commaai/laika.

classmethod from_ecef(init_ecef)[source]

Instantiate class using the NED origin in ECEF coordinates.

Parameters:

init_ecef (np.ndarray) – Float with ECEF coordinates of the NED origin.

Returns:

local_coord – Instance of LocalCoord object with corresponding NED origin.

Return type:

LocalCoord

Notes

Based on code from https://github.com/commaai/laika.

classmethod from_geodetic(init_geodetic)[source]

Instantiate class using NED origin in geodetic coordinates.

Parameters:

init_geodetic (np.ndarray) – Float with WGS-84 LLA coordinates of the NED origin

Returns:

local_coord – Instance of LocalCoord object with corresponding NED origin.

Return type:

LocalCoord

Notes

Based on code from https://github.com/commaai/laika.

geodetic_to_ned(geodetic)[source]

Convert geodetic position vectors to NED position vectors.

Parameters:

geodetic (np.ndarray) – Float with geodetic position vectors.

Returns:

ned – Converted NED position vectors.

Return type:

np.ndarray

Notes

Based on code from https://github.com/commaai/laika.

ned_to_ecef(ned)[source]

Convert NED position vectors to ECEF position vectors.

Parameters:

ned (np.ndarray) – Float with position vectors in the NED frame of reference.

Returns:

ecef – Converted position vectors in the ECEF frame of reference.

Return type:

np.ndarray

Notes

Based on code from https://github.com/commaai/laika.

ned_to_ecefv(ned)[source]

Convert NED free vectors to ECEF free vectors.

Parameters:

ned (np.ndarray) – Float with free vectors in the NED frame of reference.

Returns:

ecef – Converted free vectors in the ECEF frame of reference.

Return type:

np.ndarray

Notes

Based on code from https://github.com/commaai/laika.

ned_to_geodetic(ned)[source]

Convert geodetic position vectors to NED position vectors.

Parameters:

ned (np.ndarray) – Float with NED position vectors.

Returns:

geodetic – Converted geodetic position vectors.

Return type:

np.ndarray

Notes

Based on code from https://github.com/commaai/laika.

coordinates.add_el_az(navdata, receiver_state, inplace=False)[source]

Adds elevation and azimuth to NavData object.

Parameters:
  • navdata (gnss_lib_py.navdata.navdata.NavData) – Instance of the NavData class. Must include gps_millis as well as satellite ECEF positions as x_sv_m, y_sv_m, z_sv_m, gnss_id and sv_id.

  • receiver_state (gnss_lib_py.navdata.navdata.NavData) – Either estimated or ground truth receiver position in ECEF frame in meters as an instance of the NavData class with the following rows: x_rx*_m, y_rx*_m, z_rx*_m, gps_millis.

  • inplace (bool) – If false (default) will add elevation and azimuth to a new NavData instance. If true, will add elevation and azimuth to the existing NavData instance.

Returns:

data_el_az – If inplace is True, adds el_sv_deg and az_sv_deg to the input navdata and returns the same object. If inplace is False, returns el_sv_deg and az_sv_deg in a new NavData instance along with gps_millis and the corresponding satellite and receiver rows.

Return type:

gnss_lib_py.navdata.navdata.NavData

coordinates.ecef_to_el_az(rx_pos, sv_pos)[source]

Calculate the elevation and azimuth from receiver to satellites.

Vectorized to be able to be able to output the elevation and azimuth for multiple satellites at the same time.

Parameters:
  • rx_pos (np.ndarray) – 1x3 vector containing ECEF [X, Y, Z] coordinate of receiver

  • sv_pos (np.ndarray) – 3xN array containing ECEF [X, Y, Z] coordinates of satellites

Returns:

el_az – 2XN array containing the elevation and azimuth from the receiver to the requested satellites. Elevation and azimuth are given in decimal degrees.

Return type:

np.ndarray

Notes

Code based on method by J. Makela. AE 456, Global Navigation Sat Systems, University of Illinois Urbana-Champaign. Fall 2017

coordinates.ecef_to_geodetic(ecef, radians=False)[source]

ECEF to LLA conversion using Ferrari’s method.

Parameters:
  • ecef (np.ndarray) – array where ECEF x, ECEF y, and ECEF z are either independent rows or independent columns, values should be floats

  • radians (bool) – If False (default), output of lat/lon is returned in degrees. If True, output of lat/lon is returned in radians.

Returns:

geodetic – Float with WGS-84 LLA coordinates corresponding to input ECEF. Order is returned as (lat, lon, h) and is returned in the same shape as the input. Height is in meters above the the WGS-84 ellipsoid.

Return type:

np.ndarray

Notes

Based on code from https://github.com/commaai/laika.

coordinates.el_az_to_enu_unit_vector(el_deg, az_deg)[source]

Convert elevation and azimuth to ENU unit vectors.

Parameters:
  • el_deg (np.ndarray) – Elevation angle in degrees.

  • az_deg (np.ndarray) – Azimuth angle in degrees.

Returns:

unit_dir_mat – ENU unit vectors.

Return type:

np.ndarray

coordinates.geodetic_to_ecef(geodetic, radians=False)[source]

LLA to ECEF conversion.

Parameters:
  • geodetic (np.ndarray) – Float with WGS-84 LLA coordinates.

  • radians (bool) – Flag of whether input [rad].

Returns:

ecef – ECEF coordinates corresponding to input LLA.

Return type:

np.ndarray

Notes

Based on code from https://github.com/commaai/laika.

coordinates.wrap_0_to_2pi(angles)[source]

Wraps an arbitrary radian between [0, 2pi).

Angles must be in radians.

Parameters:

angles (np.ndarray) – Array of angles in radians to wrap between 0 and 2pi.

Returns:

angles – Angles wrapped between 0 and 2pi in radians.

Return type:

np.ndarray