Assignments Setup

We assumed that you have Linux installed already Computer Environment. This is already done on the external SSD we provide at the first meeting for you to borrow.

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!

If you use the external SSD that we provide you find Webots in the Download folder. To install it:

sudo apt install ~/Downloads/webots_2023b_amd64.deb

Otherwise, you can download it from the Webots GitHub repo Links to an external site..

To download and install it:

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 ht24

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

Limit ROS Nodes to Localhost

By default, ROS 2 communication is not limited to localhost (see configure environment Links to an external site. where this text is taken from). ROS_LOCALHOST_ONLY environment variable allows you to limit ROS 2 communication to localhost only. This means your ROS 2 system, and its topics, services, and actions will not be visible to other computers on the local network. Using ROS_LOCALHOST_ONLY is helpful in certain settings, such as classrooms, where multiple robots may publish to the same topic causing strange behaviors. You can set the environment variable with the following command:

export ROS_LOCALHOST_ONLY=1

To maintain this setting between shell sessions, you can add the command to your shell startup script:

echo "export ROS_LOCALHOST_ONLY=1" >> ~/.bashrc