Assignments Setup

We assumed that you have Linux installed already to get the Computer Environment setup as as instructed here.

Install Simulator

Simulators are utilized extensively when working in robotics and autonomous systems. It makes the development faster, safer, and cheaper. There are many simulators that work with ROS 2. Gazebo and Webots are two of the most common. In this course we will be using the Webots simulator Links to an external site.. You can read more about ROS 2 and simulators here Links to an external site..

We will use Webots R2023b. It is important that you use this specific version! You can download it from the Webots GitHub repo Links to an external site..

To download and install it on Ubuntu 20.04 and 22.04:

wget https://github.com/cyberbotics/webots/releases/download/R2023b/webots_2023b_amd64.deb
sudo apt install ./webots_2023b_amd64.deb

Most likely a warning message like N: Download is performed unsandboxed as root as file '/home/patric/Downloads/webots_2023b_amd64.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied) will be printed, which you can ignore just like when installing other software distributed as a .deb-file like for example docker. Links to an external site.

Setup ROS Workspace

When working with ROS you need to have a workspace Links to an external site.. The workspace is where you put the packages Links to an external site. you develop, such that you can build and install them in a way that ROS recognizes.

mkdir -p ~/ros2_ws/src
cd ~/ros2_ws/src
git clone --recurse-submodules https://github.com/KTH-RPL/wasp_autonomous_systems.git -b ht23

Install ROS Course Packages Dependencies

We will use rosdep Links to an external site. to manage and install all the dependencies that the course packages require.

First we install rosdep Links to an external site.:

sudo apt install python3-rosdep python3-pip 

We have to initialize rosdep Links to an external site.:

sudo rosdep init
rosdep update

Make sure that you can execute the newly installed programs by adding your local bin folder to the PATH.

echo "export PATH=\"`python3 -m site --user-base`/bin:\$PATH\"" >> ~/.bashrc
source ~/.bashrc

Next we use it to install the dependencies.

cd ~/ros2_ws
source /opt/ros/humble/setup.bash
rosdep install --from-paths src -y --ignore-src --as-root pip:false

Build and Install Packages

In order for ROS to know about our packages we need to build and install them. For this we will use the colcon Links to an external site. build tool.

First we need to install colcon Links to an external site.:

sudo apt install python3-colcon-common-extensions

Next we should build our workspace Links to an external site. (especially webots_ros2_driver takes a while to build):

cd ~/ros2_ws
colcon build --symlink-install

Setup colcon_cd to quickly navigate to a package Links to an external site.:

echo "source /usr/share/colcon_cd/function/colcon_cd.sh" >> ~/.bashrc
echo "export _colcon_cd_root=/opt/ros/humble/" >> ~/.bashrc

After sourcing ~/.bashrc (i.e., source ~/.bashrc), you should be able to navigate to a package using colcon_cd PACKAGE_NAME where you replace PACKAGE_NAME with the name of a package.

Setup colcon tab completion Links to an external site.:

echo "source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash" >> ~/.bashrc

Source Workspace

When you want to work with the software that we will develop in the course you need make sure that all necessary variables are set. You do this by executing the following command. If you don't do this ROS2 will not find your files.

source ~/ros2_ws/install/local_setup.bash

Automatic Source Workspace

Sourcing the setup file every time you open a new terminal is likely going to lead to you forgetting to do that from time to time. If you want this to be done automatically you can add this command to the .bashrc file which is run when a terminal is opened.

echo "source ~/ros2_ws/install/local_setup.bash" >> ~/.bashrc
source ~/.bashrc