Lab 3.2: Localization of indoor and outdoor


The goal of this lab is to implement the indoor and outdoor localization system. For outdoor localization system we will use GPS which is the most popular outdoor localization system and provides acceptable localization error. For indoor localization system, we will use open loop speed integration to infer the location of the wifibot. Although open loop system can result in error accumulation when wifibot moves for a long time, it is very easy to implement.

Outdoor localization-Global Positioning System (GPS)

By previous lab, we know that the data format from GPS module is NMEA protocol which provides longitude and latitude of the module. The coordinate system for longitude and latitude of the earth is called World Geodetic System (the newest one is called WGS84). However, in robot worlds we usually use Cartesian coordinate system which use SI unit (meters), we have to transform the coordinate from WGS to Cartesian coordinate.

To be more specific we want to know how much distance wifibot move given the difference of the longitudes and latitudes:


The transformation is composed of mathematic equation combining the parameters of the earth, we can use the transformations that have been derived to transform WGS coordinate to Cartesian coordinate. The detail can be found here.

Indoor Localization- Velocity integration using open loop speed control

From equation of motion, we know that we can get the total moving distance by integrating the velocity over time. In previous lab we have learned how to control the wifibot and set the desirable speed for the wifibot, in this section we can use integration of velocity to infer the distance wifibot has driven. To calculate the position over two dimensional space, the IMU data which provides the orientation of the wifibot can be utilized.

First, in order to visualize the movement of the wifibot we need to have running the following three components: a ROS node that continuously queries the data from IMU module (i.e. the script written in Lab 2.3), Hokuyo node, the keyboard teleoperation package for controlling the movement of the wifibot and, finally,  a script containing wifibot protocol and serial communication code that receives, analyzes and transforms  the data from the aforementioned scripts.

Firstly, create a new ROS package using the following command:

Let create a node containing wifibot protocol and serial communication code that receives, analyzes and transforms  the data published by Hokuyo node, IMU and  teleoperation package. First create .cpp files in the package folder named Localisation_Sub.cpp using following commands:

Use following code in Localisation_Sub.cpp file:


Then save the file and nd open the CMakeLists.txt in the package folder using following commands:

Add following line to the last line of the CMakeLists.txt file:

Make sure to add the following line to the manifest.xml file in the package folder:

Type following command in the terminal to compile the package and create the node in bin folder:


In order to simplify the implementation process let create a launch file. Go to the bin folder of your package and create the OpenOdoTF.launch file with the following command:

Paste following script in the file:

When the aforementioned .launch file would be executed it will run all the necessary nodes for visualizing the movement and surrounding of the wifibot. However, before proceeding make sure to activate the Hokuyo node and grant it the corresponding permissions on ttyACM1 port with the following commands:

If you succeed a message similar to the one after would be prompted:

In a new terminal run the .launch file with the following command:

Check the list of the published topics with the following command to make sure that you have all the necessary data:

Note that you should send the teleoperation commands through the same terminal where the .launch file has been launched.

Now, we are ready to plot visualize the movement and surrounding of the wifibot. In a new terminal launch rviz. Firstly, add a TF visualization and set the Fixed Frame option to map in the global options. Secondly add a Laserscan topic and set its topic to /scan. You should be able to an image similar to the one after.