How to Install Ubuntu 20.04 and VirtualBox on Your Computer

In this tutorial, we will install Ubuntu and Virtual Box on our personal computer. My machine is running Windows 10. Let’s walk through this whole process, step-by-step, so you understand how to do it no matter what operating system you have.

Ubuntu is a popular distribution (i.e. flavor) of the Linux operating system and is fully supported by ROS, the most popular framework for writing robotics software.

The process for installing Ubuntu has a lot of steps, so be patient and don’t give up if something isn’t working. Let’s get started!

You Will Need

Directions

Download the Ubuntu Image

Check Ubuntu Releases to find the latest version of Ubuntu that has long term support (LTS). As of the date of this writing, the latest version is Ubuntu 20.04 LTS (Focal Fossa), so click on that one. 

1-ubuntu-releasesJPG

Download the 64-bit PC (AMD64) desktop image (.iso file). It is a large file (about 2.5GB) and will take quite a while to download. Just go do something else and come back to it when it is finished.

Before you install the Ubuntu you just downloaded, you need to install Virtual Box. Virtual Box extends the capabilities of your host computer (i.e. your laptop or desktop PC) by enabling you to install and run an operating system in a new environment on top of your current operating system (Windows 10 in my case). The environment the new operating system will run in is known as a virtual machine (or guest).

Install VirtualBox

Go to the VirtualBox downloads page and select the version that is compatible with your computer. Install it. Once you’re done, your screen should look like this:

2-install-virtual-boxJPG

Detailed installation instructions for all operating systems (Windows, Mac OS, Linux, and Solaris) can be found in the instruction manual.

You can now delete the original executable file for VirtualBox (the one with the .exe extension). You don’t need it anymore.

Create a Virtual Machine

Now that VirtualBox is installed on your computer, we need to create a new virtual machine.

Open Virtual Box and click the New button in the toolbar.

10-start-virtual-boxJPG

Type in a descriptive name for your operating system. You can stick with the default machine folder. The machine folder is where your virtual machines will be stored. I prefer to install it on the D drive where I have more space.

3-name-and-operating-systemJPG

Also, select the operating system that you want to later install (Linux and Ubuntu_64 in the Type and Version fields).

Click Next to proceed.

The default memory size for me is 1024 MB. That is not sufficient for our purposes, so let’s raise it to 6470 MB, and then click Next to proceed.

4-raise-to-6470JPG

Make sure “Create a virtual hard disk now” is selected, and click Create.

5-create-virtual-machineJPG

Select “VirtualBox Disk Image (VDI)”, and click Next.

6-select-virtual-box-disk-imageJPG

Choose a Fixed size virtual hard disk so that you have better performance, and click Next.

7-fixed-sizeJPG

Go with something like 50 GB for the hard disk space. Then click Create.

8-go-with-50gbJPG

It will take several minutes to create the virtual hard disk, so be patient.

9-creating-hard-driveJPG

Install Ubuntu

Double-click on the left panel where you see the name of the virtual machine you just created.

10-double-click-left-panelJPG

A startup window will appear.

Click the Folder icon next to Empty. A popup box will appear that is titled “Optical Disk Selector.”

Click Add.

11-optical-disk-selectorJPG

Find the Ubuntu image you downloaded earlier in this tutorial. It is a .iso file. Select it.

Click Choose.

Click Start to proceed with that Ubuntu image.

Ubuntu should start launching.

12-ubuntu-launchingJPG

Click on “Install Ubuntu” to install Ubuntu. You should see a window that looks something like this.

13-install-ubuntuJPG

Click “Continue” to save the keyboard layout. The default English one is fine.

Select “Normal installation” and “Download updates while installing Ubuntu.” Then click Continue.

14-updates-and-other-softwareJPG

Select “Erase disk and install Ubuntu”. Then click “Install Now”.

15-install-nowJPG

Click Continue when it asks “Write the changes to the disks?”.

You will get to a point where you will need to set your time zone. It will be a big map of the world that should automatically detect your location. Click Continue.

Type in a computer name and pick a username and password. I select the “Log in automatically” option.

When installation is complete, click “Restart Now.”

16-restart-nowJPG

A message will say “Please remove the installation medium, then press ENTER:”. Just ignore it.

Go to File -> Close in the upper left part of the window.

Select “Power off the machine.” Click OK.

In the “Oracle VM Virtual Box Manager” window, highlight your virtual machine and click the green arrow up top that says “Start”.

You should now see your Ubuntu Linux desktop.

18-homepageJPG

Click the small white arrow in the upper-right portion of the screen. “Power Off” the machine.

19-power-off-machineJPG

Alternatively, you can open up a terminal window and type the following command:

sudo shutdown -h now

Highlight your virtual machine and go to Settings → Display and change your Video Memory to 128 MB. This will give you ample video memory. Click OK.

20-ample-video-memoryJPG

Also go to Settings → System → Processor, and adjust the number of CPUs to 4. Then Click OK.

21-4-cpusJPG

To make your screen larger, log back into Linux and go to your Settings. Then go to Display, and select your desired resolution.

resolution

If you have issues where your screen flips to portrait mode and gets stuck there, press CTRL + Alt + F1 to return to the login screen to fix the resolution.

You can follow this tutorial to enable clipboard sharing.

Congrats! You’re done!

How to Use GPS With the Robot Localization Package – ROS 2

In this tutorial, we will integrate GPS data into a mobile robot in order to localize in an environment.

3b-launch-the-robot

The official instructions for doing this are on this page, but we will walk through the entire process below.

You can get the entire code for this project here.

Let’s get started!

Prerequisites 

You have completed the Ultimate Guide to the ROS 2 Navigation Stack (also known as Nav2). We will not be using the Navigation Stack, but that Ultimate Guide helps you set up all the packages that you will use in this tutorial.

If you know ROS 2 and understand how to read Launch files, you should be able to follow along with this tutorial quite well without having to go through the Ultimate Guide.

Calculate the Magnetic Declination of Your Location

First, we need to calculate the magnetic declination in radians.

Go to this page.

Enter your latitude and longitude, and click “Calculate”. If you don’t know your latitude and longitude, you can look it up by zip code.

My magnetic declination is 5° 20′ W. 

1-magnetic-declination

Convert that value to decimal format. Since the units above are 5 degrees and 20 minutes, this value is the following in decimal format:

5.333333 degrees

Now we need to convert that value to radians.

5.333333 degrees = 0.093084220955 radians.

Set the Latitude, Longitude, and Elevation in the World File

We need to set the latitude, longitude, and elevation of the origin in Gazebo.

Go to your world file. Open a terminal window, and type:

colcon_cd basic_mobile_robot
cd worlds/basic_mobile_bot_world
gedit smalltown.world

Inside the <spherical_coordinates> tag at the bottom of the file, modify the latitude, longitude, and elevation to wherever you are. Here is my smalltown.world file.

I am in Atlanta, Georgia. My latitude is 33.83, and my longitude is -84.42. The elevation at this location is 836.6 feet, which is 254.99568 meters.

Save the file and close it.

When we load Gazebo:

  • x = East
  • y = North
  • z = Up

So, for example, if the robot is in Atlanta and heading in the positive x-direction in the world coordinate frame, the robot is moving eastward, and we should expect the longitude to get less negative (i.e. move towards 0).

If the robot is heading in the positive y-direction in the world coordinate frame, the robot is moving northward, and we should expect the latitude to increase (i.e. move towards 90 degrees).

Set the Configuration Parameters

We now need to specify the configuration parameters of the ekf_node by creating a YAML file.

Open a new terminal window, and type the following command to move to the basic_mobile_robot package:

colcon_cd basic_mobile_robot
cd config
gedit ekf_with_gps.yaml

Copy and paste this code inside the YAML file.

Save and close the file.

You can get a complete description of all the parameters on this page

Create a Launch File

Open a new terminal window, and move to your launch folder.

colcon_cd basic_mobile_robot
cd launch
gedit basic_mobile_bot_v6.launch.py

Copy and paste this code into the file.

Save the file, and close it.

Build the Package

Now build the package by opening a terminal window, and typing the following command:

cd ~/dev_ws
colcon build --packages-select basic_mobile_robot

Launch the Robot

Open a new terminal, and launch the robot.

cd ~/dev_ws/
ros2 launch basic_mobile_robot basic_mobile_bot_v6.launch.py
3-launch-the-robot

Call a ROS service to set the GPS’s origin for the navsat_transform node.

ros2 service call /datum robot_localization/srv/SetDatum '{geo_pose: {position: {latitude: 33.83, longitude: -84.42, altitude: 254.99568}, orientation: {x: 0.0, y: 0.0, z: 0.0, w: 1.0}}}'
3c-service-call

Now let’s check out the coordinate frames. Open a new terminal window, and type:

ros2 run tf2_tools view_frames.py

In newer versions of ROS 2, you might have to type:

ros2 run tf2_tools view_frames

In the current working directory, you will have a file called frames.pdf. Open that file.

evince frames.pdf

Here is what my coordinate transform (i.e. tf) tree looks like:

2-transform_tree

Check out the topics.

ros2 topic list

We can see the raw GPS data.

ros2 topic echo /gps/fix
4-gps-fix

We can see the GPS data after we have processed the raw GPS data through an Extended Kalman Filter.

ros2 topic echo /gps/filtered
5-gps-filtered

The pose of the robot in the map frame before data processing through an Extended Kalman Filter.

ros2 topic echo /odometry/gps
7-odometry-gps

The pose of the robot in the map frame after data processing through an Extended Kalman Filter. This value below is a combination of wheel encoder information, IMU data, and GPS data.

ros2 topic echo /odometry/global
6-odometry-global

The pose of the robot with respect to the starting point of the robot (i.e. with respect to the odom frame). This value below is a combination of wheel encoder information and IMU data.

ros2 topic echo /odometry/local
8-odometry-local

To steer the robot, open a new terminal window, and type the following command:

rqt_robot_steering

If you go straight down the positive x-axis, you will notice that the latitude value is getting less negative. This trend makes sense given the robot’s eastward trajectory.

That’s it! Keep building!

The Ultimate Guide to the ROS 2 Navigation Stack – Foxy

In the tutorials below, we will cover the ROS 2 Navigation Stack (also known as Nav2) in detail, step-by-step. The ROS 2 Navigation Stack is a collection of software packages that you can use to help your mobile robot move from a starting location to a goal location safely. Here will be our final output:

Navigation in a known environment with a map
Navigation in an unknown environment without a map

Credit to Ramkumar Gandhinathan and Lentin Joseph’s awesome book ROS Robotics Projects Second Edition (Disclosure: As an Amazon Associate I earn from qualifying purchases) for the world file, which comes from their book’s public GitHub page.

Real-World Applications

The ROS 2 Navigation Stack can be used in a number of real-world robotic applications: 

  • Ground Delivery
  • Hospitals and Medical Centers
  • Hotels (Room Service)
  • Offices
  • Restaurants
  • Warehouses
  • And more…

In this project, we will work with a simulated robot in a simulated world. Roboticists like to simulate robots before building them in order to test out different algorithms. You can imagine the cost of making mistakes with a physical robot can be high (e.g. crashing a mobile robot into a wall at high speed means lost money).

Let’s get started!

Prerequisites

  • ROS 2 Foxy Fitzroy installed on Ubuntu Linux 20.04
    • If you are using another ROS 2 distribution, you will need to replace ‘foxy’ with the name of your distribution everywhere I mention ‘foxy’ in this tutorial. 
    • I highly recommend you get the newest version of ROS 2. If you are using a newer version of ROS 2, you can still follow most of the steps in this tutorial. I will point out the areas where you will need to do things differently.
  • You have already created a ROS 2 workspace. The name of our workspace is “dev_ws”, which stands for “development workspace.” 

For future reference, here is a complete package (named ‘two_wheeled_robot‘) I developed that uses both URDF and SDF robot model files with the ROS 2 Navigation Stack. You can use this as a template after you have gone through the tutorials below.

Directions

Complete the following five tutorials in order, step by step. When you are done, you will have a deep understanding of the ROS 2 Navigation Stack and will be ready to confidently use this package in your own robotics projects.

  1. How to Create a Simulated Mobile Robot in ROS 2 Using URDF
  2. Set Up the Odometry for a Simulated Mobile Robot in ROS 2
  3. Sensor Fusion Using the Robot Localization Package – ROS 2
  4. Set Up LIDAR for a Simulated Mobile Robot in ROS 2
  5. Navigation and SLAM Using the ROS 2 Navigation Stack

Enjoy!