Skip to content

Mavros global position plugin

ROS / ros eco / packages / mavros

ECEF Coordinate system

Earth-Centered, Earth-Fixed

  • Origin: Earth center of mass
  • X-axis:
  • Y-axis
  • Z-axis: Point to the north pole
  • latitude (ϕ):
  • longitude (λ) alt text

Topics

Publisher

topic
gp_lp_offset
gp_origin GPS_GLOBAL_ORIGIN
compass_hdg
rel_alt altitude above home position
local GLOBAL_POSITION_INT odometry
global GLOBAL_POSITION_INT NavSetFix
/raw/satellites
/raw/gps_vel GPS_RAW_INT
/raw/fix GPS_RAW_INT

Subscribers

topic
home_position/home
set_gp_origin
mavlink mavros topic(message)
GLOBAL_POSITION_INT (33)
GPS_GLOBAL_ORIGIN (49)
GPS_RAW_INT (24)
LOCAL_POSITION_NED_SYSTEM_GLOBAL_OFFSET (89) gp_lp_offset

1
2
3
4
5
# GLOBAL_POSITION_INT
ros2 service call /mavros/set_message_interval mavros_msgs/srv/MessageInterval "{\"message_id\": 33, \"message_rate\": 2 }"

#GPS_GLOBAL_ORIGIN
ros2 service call /mavros/set_message_interval mavros_msgs/srv/MessageInterval "{\"message_id\": 49, \"message_rate\": 2 }"

Latitude, Longitude and Coordinate system

alt text

Latitude (ϕ) lines run east-west and are parallel to each other but measure north-north. So if you go north, latitude values increase. Finally, latitude values (Y-values) range between -90 and +90 degrees.

Longitude (λ) lines run north-south and measure east-west. They converge at the poles. And its X-coordinates are between -180 and +180 degrees.

alt text


Demo

lat, lon
Tel Aviv → (32.0853° N, 34.7818° E)

bearing_deg

The bearing_deg is the direction of travel, measured in degrees clockwise from North:

0° → North

90° → East

180° → South

270° → West

Calc next point

calc next point using distance and bearing
from math import radians, degrees, sin, cos, atan2, asin

def move_point(lat, lon, distance_m, bearing_deg):
    R = 6371000  # Earth radius in meters

    lat1 = radians(lat)
    lon1 = radians(lon)
    bearing = radians(bearing_deg)

    lat2 = asin(sin(lat1) * cos(distance_m/R) +
                cos(lat1) * sin(distance_m/R) * cos(bearing))

    lon2 = lon1 + atan2(sin(bearing) * sin(distance_m/R) * cos(lat1),
                        cos(distance_m/R) - sin(lat1) * sin(lat2))

    return degrees(lat2), degrees(lon2)

# Example: move 500m east
lat, lon = 32.0853, 34.7818
new_lat, new_lon = move_point(lat, lon, 500, 90)

print(f"Original: {lat:.6f}, {lon:.6f}")
print(f"New point: {new_lat:.6f}, {new_lon:.6f}")
calc distance and bearing between two points
from math import radians, sin, cos, sqrt, atan2, degrees

def haversine(coord1, coord2):
    # Coordinates: (lat, lon)
    R = 6371.0  # Earth radius in kilometers

    lat1, lon1 = map(radians, coord1)
    lat2, lon2 = map(radians, coord2)

    dlat = lat2 - lat1
    dlon = lon2 - lon1

    a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
    c = 2 * atan2(sqrt(a), sqrt(1-a))

    return R * c

def bearing_between_points(lat1, lon1, lat2, lon2):
    # Convert to radians
    lat1, lon1, lat2, lon2 = map(radians, [lat1, lon1, lat2, lon2])

    dlon = lon2 - lon1

    x = sin(dlon) * cos(lat2)
    y = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(dlon)

    initial_bearing = atan2(x, y)

    # Convert from radians to degrees and normalize 0-360
    bearing = (degrees(initial_bearing) + 360) % 360
    return bearing

# Example
origin = (32.0853, 34.7818)   # Tel Aviv
target = (32.085300, 34.787107)   # next point ~500m east

print(f"Distance: {haversine(origin, target):.2f} km")
print(f"Bearing (from north cw): {bearing_between_points(32.0853, 34.7818, 32.085300, 34.787107):.2f}°")

Datum

A datum in geodesy and mapping is a reference framework that defines the shape, size, and position of the coordinate system used to describe locations on Earth.

WGS84 (World Geodetic System 1984) is one of the most important modern datums, is use by GPS navigation system.