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.
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