When you place a robot in a known environment, the robot should be able to localize itself, meaning it could compute the approximate position of itself using sensors and algorithms. Localization is crucial to self-driving vehicles, which requires incredible precision. GPS (Global Positioning System) is one of the first steps to localization. However, the system is inherently flawed, in that error margin can be up to 10 meters. In this post, I will talk about how to use GPS to localize the robot, using ROS, rviz and OSM (Open Street Map). I hope to post something later about localization beyond GPS.

If you are unfamiliar with ROS or rviz, I strongly recommend you to read of their documentation, or read some of my previous posts.

Global Positioning System

I am sure that most of you are familiar with GPS. We use it on our phones, cars, airplanes… GPS is a global navigation satellite system that provides geolocation and time information to a GPS receiver anywhere on or near the Earth where there is an unobstructed line of sight to four or more GPS satellites. The United States government created the system, maintains it, and makes it freely accessible to anyone with a GPS receiver. There is a GPS receiver mounted on the golf cart that receives this data. 

Why use GPS when it’s so unreliable? Well, GPS allows us to simplify the localization problem greatly. The golf cart is meant to navigate within a 300 acres area, and finding itself in this vast space is time-consuming and difficult. GPS narrows down the “search” region to a 5-meter radius. Then, when we apply particle filters and find our precise location down to the centimeters. 

A good localization system requires both GPS and other sensors, such as lidar and radar. 

RVIZ

In the previous post, I talked about how to use rviz to visualize OSM (Open Street Map) data. However, the vehicle in rviz was unable to change its location based on the GPS sensor reading. Now, in this post, let’s update the position of the vehicle based on the GPS fixes (in real-time!).

This section might not be as straightforward as you think. It’s not as simple as showing the GPS coordinate directly in RVIZ. It requires some post-processing, which includes transformation with the ROS tf package. Please email me if you have any questions, comments or concerns.

First of all, I created a GPS node that publishes GPS fix under the topic: /sensor/gps/fix. Then, the localization node subscribes (listens) to that topic. Based on the latitude and longitude received, the localization node transforms lat/long to UTM coordinates. (It took me forever to figure out this transformation). Thanks to the built-in geodesy packages in ROS, I was able to use that library for this transformation. Once we have the UTM coordinates, we are ready to set the position of the golf cart.

Here is where tf becomes a part of the equation. tf is a package that lets the user keep track of multiple coordinate frames over time. tf maintains the relationship between coordinate frames in a tree structure buffered in time and lets the user transform points, vectors, etc between any two coordinate frames at any desired point in time. The map in rviz is a coordinate frame, while the base of the golf cart is also a frame. tf manages the relationship between the golf cart and the map. Lastly, with the UTM coordinates and some knowledge of tf, we can broadcast the location of the robot, so that its location in rviz correspond to its actual location in the real world.

gps-loc
The vehicle located itself using the GPS unit. ROS and RVIZ visualize the vehicle’s location in realtime.

Conclusion

When I first started to solve this problem, it looked very daunting. While ROS is very well documented, there is very little documentation about this specific topic. I hope this post helped those who are wondering just as I did. Frankly, localizing a robot can be difficult, integrating ROS and rviz can be even more challenging. I can’t wait to continue to develop the localization module with the help of other sensors, such as lidar & radar.

Last but not least, if you have any questions about ROS, GPS, localization, please don’t hesitate to contact me at contact@neilnie.com. Thanks a lot for stopping by. If you enjoyed this post, please give it a like. Here are several other posts that you might like.

As always, you can find the source code for all of my blog post and projects here on Github.

9 thoughts on “GPS Localization with ROS, rviz and OSM

    1. Thanks for the comment. I simply used a WordPress template. Many of them are great! I customized the template just slightly. I don’t run ads on my blog. I also try not to have cluttered information.

      Like

  1. Hi,

    Thank you for this great post. I am using a high precision GPS sensor on a car (accuracy cm level). I have recorded a bag file with the sensor data (velodyne, images etc) along with the gps/data (NavSatFix format). This gives me latitude, longitude and altitude data from the gps. I wish to use this data in ROS and not able to understand how to convert the lat long data to UTM coordinates and read it. The geodesy node does not contain any brief manual as to how to use the node. Can you help me with this? Thanks.

    Like

Leave a Reply to NeilNie Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s