NA of Moles

How to setup ROS Noetic in WSL through Ubuntu 20.04 Focal

Guide for Matteo Matteucci’s Robotics class at PoliMi

Scope: to install the environment needed for the labs without having to deal with Docker or dual booting in Ubuntu.

Target: PCs running Windows 10 or up supporting virtualization.

Basic Installation

First you need to set-up WSL in your machine. From a Windows command line run:

powershell
1
2
wsl --update
wsl --install Ubuntu-20.04

And fill the username and password as you please.

Now you should get a linux shell, in other case you can launch it from the start menu (simply search Ubuntu, it should also apper in the recently installed section) or from the dropdown menu of the terminal (my suggested method).

Let’s update some packages as a precaution and then continue.

bash
1
2
sudo apt update
sudo apt upgrade -y

n.b: If you’re using the internal PoliMi Wifi you may get some errors, simply switching the Wifi from “Public Network” to “Private Network” should fix it. You may have to change it back once you’re done with this tutorial.

Now we start dealing with the core ROS installation. These commands are taken from the Docker repository

bash
1
2
3
4
5
6
7
8
sudo apt-get install -q -y --no-install-recommends dirmngr gnupg2
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
sudo  sh -c 'echo "deb http://packages.ros.org/ros/ubuntu focal main" >> /etc/apt/sources.list.d/ros1-latest.list'
sudo apt-get update 
sudo apt-get install -y --no-install-recommends ros-noetic-ros-core=1.5.0-1*
source "/opt/ros/noetic/setup.bash"
echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
source ~/.bashrc

These are the commands for the “base” ROS installation taken from here

bash
1
2
3
4
5
sudo apt-get install --no-install-recommends -y  build-essential  python3-rosdep  python3-rosinstall   python3-vcstools 
sudo rosdep init 
rosdep update --rosdistro noetic
sudo apt-get update 
sudo apt-get install -y --no-install-recommends ros-noetic-ros-base=1.5.0-1*

Now finally for the “perception” ROS package

bash
1
sudo apt-get install -y --no-install-recommends   ros-noetic-perception=1.5.0-1* 

ℹ️ Note

Basically in the Dockerfile shared in class what we just did was simply the first section.

(This is not a command!)

dockerfile
1
2
# Start from the ROS Noetic perception image
FROM ros:noetic-perception

Now we continue with the other installation commands:

bash
1
sudo apt-get install -y --no-install-recommends nano vim tmux gedit ros-noetic-rqt* net-tools iproute2 ros-noetic-plotjuggler* ros-noetic-foxglove-bridge ros-noetic-turtlesim ros-noetic-tf*

Update for lesson 7

bash
1
sudo apt-get install -y --no-install-recommends  ros-noetic-stage* ros-noetic-gmapping ros-noetic-slam-toolbox* ros-noetic-move-base* ros-noetic-amcl ros-noetic-global-planner ros-noetic-dwa-local-planner ros-noetic-navfn ros-noetic-turtlebot3-* ros-noetic-teleop-twist-keyboard ros-noetic-pointcloud-to-laserscan 

You should already be in the home directory but just in case:

bash
1
2
3
4
5
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/
ln -s /opt/ros/noetic/share/catkin/cmake/toplevel.cmake src/CMakeLists.txt
catkin_make
echo "source ~/catkin_ws/devel/setup.bash"  >> ~/.bashrc

To test it:

In three different tabs execute these commands in this order:

bash
1
2
3
roscore
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key

In case you wanted to run everything in one shot:

After opening the Linux shell:

bash
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
sudo apt update
sudo apt upgrade -y
sudo apt-get install -q -y --no-install-recommends dirmngr gnupg2
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
sudo  sh -c 'echo "deb http://packages.ros.org/ros/ubuntu focal main" >> /etc/apt/sources.list.d/ros1-latest.list'
sudo apt-get update 
sudo apt-get install -y --no-install-recommends ros-noetic-ros-core=1.5.0-1*
source "/opt/ros/noetic/setup.bash"
echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
sudo apt-get install --no-install-recommends -y  build-essential  python3-rosdep  python3-rosinstall   python3-vcstools 
sudo rosdep init 
rosdep update --rosdistro noetic
sudo apt-get update 
sudo apt-get install -y --no-install-recommends ros-noetic-ros-base=1.5.0-1*
sudo apt-get install -y --no-install-recommends   ros-noetic-perception=1.5.0-1* 
sudo apt-get install -y --no-install-recommends nano vim tmux gedit ros-noetic-rqt* net-tools iproute2 ros-noetic-plotjuggler* ros-noetic-foxglove-bridge ros-noetic-turtlesim ros-noetic-tf*
sudo apt-get install -y --no-install-recommends  ros-noetic-stage* ros-noetic-gmapping ros-noetic-slam-toolbox* ros-noetic-move-base* ros-noetic-amcl ros-noetic-global-planner ros-noetic-dwa-local-planner ros-noetic-navfn ros-noetic-turtlebot3-* ros-noetic-teleop-twist-keyboard ros-noetic-pointcloud-to-laserscan 
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/
ln -s /opt/ros/noetic/share/catkin/cmake/toplevel.cmake src/CMakeLists.txt
catkin_make
echo "source ~/catkin_ws/devel/setup.bash"  >> ~/.bashrc

Quality of life improvements (you can skip this)

If you want an easier tmux experience with mouse support (like scrolling for output history, click to change pane, etc) and color:

bash
1
2
3
4
cd $HOME
touch ~/.tmux.conf
echo "setw -g mouse on" >> ~/.tmux.conf
echo "setw -g default-terminal "tmux-256color"" >> ~/.tmux.conf

Cloning

Now your ROS developement environment is fully functioning, so we can just “clone” the distro to be able to interact in a multihost configuration. Write down your Ubuntu username, it’s just the name of the account that we setup in the first step. It also appears before the @ in your shell.

bash
1
sudo nano /etc/wsl.conf

Now we have to modify the text file into this:

conf
[boot]
systemd=true
[user]
default=UsernameThatIJustToldYouToWriteDOwn

And now just CTRL + O to save, same name,CTRL + X to exit.

Now create an empty folder in a place of your liking (possibly in a disk with at least 20Gb)

Open a Powershell terminal in that folder and type:

powershell
1
2
wsl --shutdown
wsl.exe --export Ubuntu-20.04 UbuntuRosBck.tar

Just wait….

If everything went correctly then you can type in the same terminal:

powershell
1
wsl.exe --import UbuntuRosSecondary ./filesystemsecondary UbuntuRosBck.tar

Wait, again. As soon as the process is complete we can just launch the instance with

powershell
1
wsl.exe --distribution UbuntuRosSecondary 

Now we have two identical WSL instances that we can launch from the start menu or from the terminal drop down.

How your Terminal dropdown should look like
How your Terminal dropdown should look like

Now, going back to the directory where we exported the backup at the start of this step we have two big files: UbuntuRosBck.tar and filesystem\ext4.vhdx

⚠️ Warning

Precaution when moving the generated files pt. 1

For filesystem\ext4.vhdx: DON’T TOUCH, MOVE OR DELETE IT. It contains all your data.

💡 Tip

Precaution when moving the generated files pt. 2

For UbuntuRosBck.tar instead you can either delete it or you can also share it with your friends.

Testing

With this configuration you don’t have to fiddle with Master IPs and such like for Docker. To test it just run like this:

bash
1
2
3
roscore
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key

Turtlesim running on multiple machines
Turtlesim running on multiple machines

Sharing is Caring

UbuntuRosBck.tar basically contain a full linux distro with all the ROS packages already installed. You can transfer it on their PC and then in an empty folder just run:

powershell
1
2
wsl.exe --import UbuntuRosPrimary ./filesystemprimary UbuntuRosBck.tar
wsl.exe --import UbuntuRosSecondary ./filesystemsecondary UbuntuRosBck.tar

Ideally this should just run™

Be mindful to not put anything personal or harmful inside and to give them the password you used in the first step. It’s technically a local VM so it shouldn’t bee too much of a risk from that point of view.

❗ Caution

Just in case it’s not clear:

Your WSL password, not your Windows password!

Also, like for the previous section: please never delete the filesystemprimary\ext4.vhdx and filesystemsecondary\ext4.vhdxfiles but you can delete UbuntuRosBck.tar file without causing problems.


Tags: