How to Install ROS Melodic on the NVIDIA Jetson Nano

In this tutorial, I will show you everything you need to know to install ROS Melodic on the NVIDIA Jetson Nano. The official tutorial is here and my quick tutorial is here, but I will run through all the steps below.

Prerequisites

You have set up your NVIDIA Jetson Nano Developer Kit.

Directions

In the Start Menu, go to Preferences -> Software & Updates. Then click on it.

Make sure main, universe, restricted, and multiverse are all checked. Then close the window.

2021-04-02-140620

Now open up a new terminal window, and type (or copy and paste) the following command:

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

The command above sets your computer up to accept software from packages.ros.org. 

Now we need to set up the secure keys so that our system accepts what we are going to download. 

For the next step, update the package list on your system.

sudo apt update

Now type:

sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

Now do a full desktop install of ROS. The command below installs all the software, tools, algorithms, and robot simulators for ROS. After you type the command and press Enter, press Y and hit Enter when asked if you want to continue. It will take a while to download all this stuff, so feel free to take a break while ROS downloads to your system.

sudo apt-get update
sudo apt install ros-melodic-desktop-full

Type Y and press Enter to complete the installation.

Set up the environment variables.

echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc

Note that anytime you want to see what environment variables ROS is using, you can type the following command:

export | grep ROS

This command will show you the ROS distribution you are using, the version of Python ROS is using, and a bunch of other stuff.

The two key variables are as follows:

ROS_MASTER_URI: Shows the URL where the roscore is in execution. This is often your own local computer.

ROS_PACKAGE_PATH: Shows the path on your computer where the ROS packages are.

Install some other tools that you will work with in ROS. After you type the command below, press Y and Enter to complete the download process.

sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential

Press Y and hit Enter.

Now initialize rosdep. This is a tool that is required before you can use ROS.

sudo apt install python-rosdep
sudo rosdep init
rosdep update

Here is the last step of the installation process. Check which version of ROS you have installed. If you see your ROS version as the output, congratulations you have successfully installed ROS!

rosversion -d
2021-04-02-144436

How to Install and Demo the Webots Robot Simulator for ROS 2

In this tutorial, I will show you how to install, build, and demo the ROS 2 package for Webots, the free open-source 3D robot simulator created by Cyberbotics Ltd. Installing Webots was a bit difficult, so it is important you follow the steps below click-by-click, command-by-command so that everything installs properly. Here is what the demo looks like:

Prerequisites

ROS 2 Foxy Fitzroy installed on Ubuntu Linux 20.04 (if you are using another distribution, you will need to replace ‘foxy’ with the name of your distribution).

Install

Below are the exact steps I took to install, build, and demo Webots successfully.

First, open a new terminal window, and create a new workspace. You can call it any name, but we will call it “webots”. Inside the workspace, we will create a source (i.e. src) directory. This is where your packages will go.

mkdir -p ~/webots/src

Navigate to the workspace.

cd ~/webots/src

To install the Webots software, open a new terminal window, and type the following commands:

sudo apt-get install ros-$ROS_DISTRO-webots-ros2

Type Y and then Enter to continue.

Next, we need to clone the repository into our workspace.

git clone https://github.com/cyberbotics/webots_ros2.git

Let’s see if the package is in the source folder of our workspace.

ls
1-in-our-workspaceJPG

Open a new terminal window, and try to run the demo.

ros2 launch webots_ros2_demos armed_robots.launch.py

You will be asked if you want to install the latest version of Webots.

Type Y and press Enter.

It will take some time to install.

2-install-webotsJPG

You will see this demo pop up.

3-demo-armJPG

Press CTRL+C in all terminal windows to shutdown the demo.

Go to the following directory:

cd webots/src/webots_ros2/webots_ros2_importer/webots_ros2_importer
git clone https://github.com/cyberbotics/urdf2webots.git
cd urdf2webots
pip3 install -r requirements.txt

At this stage, I was having install errors when I tried to build the package. So here is what I did next.

Remove the webots package. Either go to the file explorer in Linux and delete the webots_ros2 folder manually, or you can run the following commands to delete the folder.

cd ~/webots/src
rmdir webots_ros2

Now, download the package again.

cd ~/webots/src
git clone --recurse-submodules -b $ROS_DISTRO https://github.com/cyberbotics/webots_ros2.git webots_ros2

Build

Go to the root of the workspace.

cd ~/webots/

Check the dependencies.

rosdep update
rosdep install --from-paths src --ignore-src --rosdistro $ROS_DISTRO
colcon build

Add the sourcing of the workspace to the bashrc file.

gedit ~/.bashrc

At the bottom of the bash file, add the following line:

source ~/webots/install/setup.bash

Demo

How to Run the Robotic Arm Demo

Open a new terminal window, and type the following command.

ros2 launch webots_ros2_demos armed_robots.launch.py

When you’re done watching the demo, press CTRL + C in all terminal windows.

That’s it. Keep building!

How to Install ROS 2 Navigation (Nav2)

In this tutorial, we will explore Navigation2 (Nav2), which is a collection of tools for ROS 2 that enable a robot to go from point A to point B safely. We will also take a look at a SLAM demo with a robot named Turtlebot 3. Here will be our final output:

Real-World Applications

Navigation is one of the most important tasks for a mobile robot. Navigation is about enabling a mobile robot to move from one location to another without running into any obstacles.

In order to navigate properly, a robot needs to have a map (mapping), know where it is located (localization), and have a plan for getting from point A to point B (path planning).

Prerequisites

Install and Build Nav2

***Note: The official instructions for installing Nav2 are here. Please check out that link to get the latest instructions. The steps below are valid as of the date of this blog post and will likely be different by the time you read this.***

Once you’re done with this tutorial, you can head over to my Ultimate Guide to the ROS 2 Navigation Stack.

To install Nav2, open a new terminal window, and type the following commands:

sudo apt install ros-foxy-navigation2

Type Y and then Enter to continue.

sudo apt install ros-foxy-nav2-bringup

Type Y and then Enter to continue.

Install the Turtlebot 3 example.

Open a new terminal window, and type:

sudo apt install ros-foxy-turtlebot3*
sudo apt install ros-foxy-nav2-simple-commander

If you want to build from the source (i.e. get the ROS2 navigation packages directly from GitHub), open a new terminal window, and type the following commands. One right after the other.

mkdir -p ~/nav2_ws/src
cd ~/nav2_ws/src
git clone https://github.com/ros-planning/navigation2.git --branch foxy-devel
cd ~/nav2_ws
rosdep install -y -r -q --from-paths src --ignore-src --rosdistro foxy

Your computer might say something like “executing command [sudo ……”. That is fine. Just wait, and let your system finish doing what it is doing.

colcon build --symlink-install

It took a while to install Nav2 on my machine. Just be patient.

You noticed that if we install Nav2 from the source, we also needed to install it using the Ubuntu package manager first. The reason we had to do both is that the Ubuntu package manager installs some non-ROS dependencies that are necessary for Nav2 to build from the source.

Building Nav2 from the source (using the Github clone command we did above) enables us to customize the packages in Nav2 to our liking (e.g. add new plugins, messages, etc.) that won’t get overwritten during a system upgrade (i.e. sudo apt-get upgrade)

When Nav2 is finished installing, open your bash file.

gedit ~/.bashrc

Add these lines to the bottom of the file. You can get the latest information on what to add on this link.

source ~/nav2_ws/install/setup.bash
export TURTLEBOT3_MODEL=waffle
export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:/opt/ros/foxy/share/turtlebot3_gazebo/models
source /usr/share/gazebo/setup.sh

Save the file, and close it.

cd ~/nav2_ws

Build it again, just to make sure everything is in order

colcon build

Test Your Installation

Now test your installation.

Open a new terminal window.

cd ~/nav2_ws
ros2 launch nav2_bringup tb3_simulation_launch.py

rviz2 will open.

Gazebo will also open, but it may take a while.

1_gazebo_rviz_openJPG

Move the Robot From Point A to Point B

Now go to the rviz2 screen.

Set the initial pose of the robot by clicking the “2D Pose Estimate” on top of the rviz2 screen. Then click on the map in the estimated position where the robot is in Gazebo.

2b-2d-pose-estimateJPG
2-set-poseJPG
3-robot-poseJPG

Set a goal for the robot to move to. Click “Navigation2 Goal” button and choose a destination. The wheeled robot will move to the goal destination.

4-navigation-goalJPG
5-navigate-to-a-goalJPG

In the bottom left of the screen, you can Pause and Reset.

Press CTRL + C on all terminal windows to close down the programs.

Install the SLAM Toolbox

Now that we know how to navigate the robot from point A to point B with a prebuilt map, let’s see how we can navigate the robot while mapping. This process is known as Simultaneous localization and mapping (SLAM).

Open a new terminal window. Type this command:

sudo apt install ros-foxy-slam-toolbox

Launch the SLAM launch file. Open a new terminal window, and type:

cd ~/nav2_ws
ros2 launch nav2_bringup slam_launch.py

Now launch the robot.

ros2 launch nav2_bringup tb3_simulation_launch.py

Click the 2D Pose Estimate button and click on the rviz screen an estimate position where the robot is in Gazebo.

Then click the Navigation2 Goal button and click on an area of rviz where you want the robot to go.

Press CTRL+C in all terminals to shut everything down.

Here is another command you can run. This command launches Turtlebot3 and the SLAM package in a single command.

ros2 launch nav2_bringup tb3_simulation_launch.py slam:=True

That’s it. Keep building!