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.
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.
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 email@example.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.
- Driver by wire system (DBW)
- Robot Operating System
12 replies on “GPS Localization with ROS, rviz and OSM”
I really like your blog.. very nice colors & theme. Did you design this website yourself or did you hire someone to do it for you? Plz answer back as I’m looking to design my own blog and would like to find out where u got this from. kudos
LikeLiked by 1 person
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.
Appreciating the commitment you put into your website and detailed information you provide. It’s good to come across a blog every once in a while that isn’t the same outdated rehashed material. Excellent read! I’ve saved your site and I’m including your RSS feeds to my Google account.
LikeLiked by 1 person
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.
Hi, neilnie, I’m a graduate student from CHINA. I have a idea the same with you, use rviz to show osm and roborcar , and update the position of the robot. I just install the package: osm_cartography ,and sucefully show the .osm in rviz . BUT NOW , i am confused to show the robot and update the position , sorry I download your ROS_GPS but don’t know how to use. I love you if you can write a userguide hhhhhh.