Content on this page is about out-of-date, since Debian 10 and ROS 1 will be End-Of-Life in 2025, please navigate to new tutorial 1.
comp.nus.edu.sg/~guoyi / tutorial / cg2111a / ros-setup-eol

Tutorial: Robot Operating System for EPP2


Engineering Principles and Practice II [CG2111A]

Author: Boyd Anderson; Chen Guoyi
Supervisors: Henry Tan; Nguyen Tien Khoa; Ravi S/O Suppiah; Sean Tan Rui Xiang; Tan Keng Yan, Colin.

This tutorial is sponsored by the NUS School of Computing and brought to you by the AY23/24 CG2111A Teaching Team.

Setup ROS on Raspberry Pi 4 (Debian 10)

This tutorial will take you from a basic operating system image to independently building up the Robot Operating System (ROS). Engaging in this setup personally will not only provide you with a deeper understanding of the fundamental principles of operating systems and ROS architecture but will also enhance your practical skills and theoretical knowledge within a real-world framework. This first-hand experience is invaluable for your future learning in advanced modules, such as EE3305 Robotic System Design, and will be a significant asset for any robotics-related internships.

Be aware that the setup process can take more than 3 hours to complete. To accommodate different needs and schedules, the CG2111A Teaching Team has prepared a backup plan for you: an OS image that already includes ROS pre-installed. This allows you to bypass the setup process described in this tutorial and jump straight into using ROS with a ready-to-use image. Please refer to the Lab Instructions in Canvas.

Each step in this tutorial is crucial, with later steps building upon the successful completion of earlier ones. Therefore, after finishing each step, please make sure to check the corresponding checkbox in this tutorial. This action will change the status from "Waiting Completion" to "Marked as Completed." This simple practice ensures you're progressing correctly through the material and helps prevent any oversight that could impact later stages.

1. Download Latest Buster Version of Raspberry Pi OS Image

Please be aware that ROS has evolved over time, leading to multiple versions and the introduction of ROS, which comes with its own set of packages and configurations. This diversity can lead to conflicts between different versions. It's important to navigate these differences carefully.

In our case, we're focusing on the ROS version known as "Noetic," which is specifically designed to operate on Debian 10, also known as Buster. If you're using a Raspberry Pi 4, ensure you download the latest Buster version of Raspberry Pi OS (Legacy), available at: https://downloads.raspberrypi.org/raspios_oldstable_armhf/images/.


This tutorial uses 2023-05-03-raspios-buster-armhf.img.xz as OS Image. You can download this image from NUS SoC Mirror Server.

Check Your Work Now 

Please check, have you downloaded the correct image?



2. Setup Raspberry Pi OS

Before You Do 

Important: back up everything on your Raspberry Pi 4 before proceeding, this operation will erase your SD card and all of your work!

Similar to the process in the previous session, utilize the Raspberry Pi Imager to flash the custom image you've previously downloaded onto your Raspberry Pi's SD card. Be prepared for this step to take some time. Start the image writing process, and while it progresses, continue reading ahead!

Ensuring a successful VNC connection to your Raspberry Pi is pivotal for the forthcoming steps in our tutorial. To verify that your operating system setup has been completed accurately, here's a concise checklist to guide your self-review:

Check Your Work Now 

Please check:

  1. The Raspberry Pi OS is installed correctly on your SD card.
  2. Your PC and your Raspberry Pi is connected to the same WiFi, the WiFi MUST have internet access!
  3. Turn on the VNC permission from 'Raspberry Pi Configuration'.
Have you done all the tasks correctly above?


Debugging Time 

Note: If you encounter the “Cannot currently show the desktop” error while using VNC, you can resolve this issue by editing the boot/config.txt file on your Raspberry Pi.

To do this, open a terminal on your Raspberry Pi and run the following commands:

sudo -s
echo 'hdmi_force_hotplug=1'>> /boot/config.txt
echo 'hdmi_group=2'>> /boot/config.txt
echo 'hdmi_mode=51'>> /boot/config

Please ensure no warning or error message when you do so, then reboot your Raspberry Pi 4 with this code:

sudo reboot

This issue should be solved elegantly!



3. Install ROS Noetic

To install ROS Noetic on our Raspberry Pi, we first need to add the ROS Noetic repository to our system. This ensures that we can download and install ROS Noetic directly from its official source. Follow these steps in a terminal window:

3.1 Add the ROS Noetic repository to system's software sources

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu buster main" > /etc/apt/sources.list.d/ros-noetic.list'

This command creates a new file in /etc/apt/sources.list.d/, which lists the ROS Noetic repository as a source for software packages.

3.2 Import the ROS package signing key

curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -

This step authenticates the repository, ensuring that our system trusts the packages coming from it, which is crucial for security.

After completing these steps, our system will be ready to install ROS Noetic packages.

Check Your Work Now 

Please check by running the codes in this section; you received no warnings or errors. The successful message from the terminal should look like this:


Have you done all the tasks correctly above?



4. Setup Python Dependencies for ROS Noetic

To ensure a smooth ROS Noetic setup on Debian Buster, it's important to install several prerequisite packages that ROS depends on, including Python development tools, build essentials, and specific Python libraries. Here's a streamlined guide to help you through the installation process:

4.1 Update package lists

Update your package lists to ensure you have the latest versions of the packages and their dependencies:

sudo apt update

4.2 Install ROS Prerequisites

Install ROS prerequisites including Python tools for ROS, build essentials, and CMake, which are necessary for compiling ROS packages:

sudo apt-get install -y python-rosdep python-rosinstall-generator python-wstool python-rosinstall build-essential cmake

4.3 Install Additional Python Dependencies


4.3.1 Install Eigen Library

Address additional Python dependencies that are crucial for ROS development. This includes installing Eigen (a C++ template library for linear algebra) and ensuring Python 3 is installed:

sudo apt-get install libeigen3-dev python3

4.3.2 Install Python YAML Library

Install YAML library, required for parsing YAML files, which are frequently used in ROS for configuration and parameter files:

sudo apt-get install python3-yaml

4.3.3 Install Catkin Package

Install catkin_pkg, a Python library essential for building and packaging ROS packages:

sudo pip3 install --upgrade pip
sudo pip3 install catkin_pkg

4.3.4 Install SIP and PyQt5 Development Tools

Install SIP and PyQt5 development tools, which are used for creating graphical user interfaces with Python. These are not directly related to ROS but might be useful for developing custom tools:

You should run the code below line by line!

sudo apt-get install sip-dev pyqt5-dev python-sip-dev pyqt5-dev-tools
sudo apt-get install python3-pyqt5
sudo pip3 install sip
sudo pip3 install PyQt5-sip
sudo apt-get install python3-sip python3-sip-dev
sudo apt-get install pyqt5-dev-tools qttools5-dev-tools

4.3.5 Install python3-empy

Finally, install python3-empy, a template system for Python that's used in the generation of ROS package files:

sudo apt-get install python3-empy

After running these commands, your system should be well-prepared for ROS Noetic development, with all the necessary tools and libraries installed. Make sure to run sudo apt update before installing new packages to ensure you're getting the latest versions.

Check Your Work Now 

Please check by running the codes in this section; you received no warnings or errors.


Have you done all the tasks correctly above?



5. Setup ROS Noetic

Setting up ROS Noetic on your system involves initializing the ROS dependency management tool, rosdep, and using rosinstall_generator and wstool to manage your source workspace. Here's a breakdown of the steps you provided, refined for clarity and completeness:

5.1 Initialize rosdep

rosdep is a command-line tool for installing system dependencies for ROS packages. To initialize it, run:

sudo rosdep init && rosdep update

This command initializes rosdep and then updates its database to ensure it has the latest information about available packages and dependencies.

Debugging Time 

Note: If you encounter error messages like:

Just ignore and continue doing next step!


5.2 Create a ROS workspace

ROS workspaces are directories where you can build ROS packages. Create a new workspace for ROS Noetic and navigate into it with:

mkdir -p ~/ros_catkin_ws && cd ~/ros_catkin_ws

This creates a directory named ros_catkin_ws in your home folder and changes the current directory to it.

5.3 Generate a ROS installation manifest

Use rosinstall_generator to create a custom ROS installation manifest. This tool helps you specify which ROS packages you want to include in your workspace.

rosinstall_generator ros_comm common_msgs ros_tutorials rviz --rosdistro noetic --deps --wet-only --tar > noetic-ros_comm-wet.rosinstall

This command generates a .rosinstall file for the ROS communication libraries, common message types, tutorials, and RViz, along with their dependencies, specifically for ROS Noetic.

5.4 Initialize your workspace with wstool

wstool is a command-line tool for managing source code repositories in your ROS workspace.

wstool init src noetic-ros_comm-wet.rosinstall

This initializes your workspace's src directory based on the .rosinstall file, pulling in the specified sources.

5.5 Install dependencies using rosdep

Finally, install any missing dependencies for the packages in your workspace with rosdep. This command checks your src directory for packages, identifies their system dependencies, and installs them.

rosdep install -y --from-paths src --ignore-src --rosdistro noetic -r --os=debian:buster

The -y flag automatically confirms the installation of dependencies, --from-paths src tells rosdep where to look for packages (in the src directory of your workspace), --ignore-src skips installing packages that are already present in the source directory, --rosdistro noetic specifies the ROS distribution, -r continues installing dependencies even if some are missing, and --os=debian:buster specifies your operating system and version.

After completing these steps, your ROS Noetic workspace will be set up with the necessary packages and dependencies, ready for development.

Check Your Work Now 

Please check by running the codes in this section; you received no warnings or errors. You will see "All required rosdeps installed successfully" at last!

Have you done all the tasks correctly above?



6. Build ROS Noetic

To build ROS Noetic from source and ensure it's properly installed on your system, the command you provided outlines a critical step in compiling the ROS workspace you've prepared. Here's a detailed explanation of what this command does and some slight refinements for clarity:

sudo src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release --install-space /opt/ros/noetic -j1 -DPYTHON_EXECUTABLE=/usr/bin/python3

Here are explainations of parameters of the command above:

  • src/catkin/bin/catkin_make_isolated: This invokes the catkin_make_isolated script, which is part of the catkin toolset designed to build ROS packages. Unlike catkin_make, catkin_make_isolated builds each package in isolation, avoiding potential conflicts between packages.
  • --install: This flag indicates that the build artifacts should be installed after compilation, making them available system-wide.
  • -DCMAKE_BUILD_TYPE=Release: Sets the build type to "Release," optimizing the compiled software for performance rather than debugging ease. This is useful for a production environment or when you don't need detailed debug information.
  • --install-space /opt/ros/noetic: Specifies the installation directory. This is where the built packages will be installed. /opt/ros/noetic is the conventional location for ROS installations, keeping different ROS distributions separate.
  • -j1: This option limits the build process to use only one job at a time. Building with a single job can reduce memory usage during the compilation, which is beneficial on systems with limited resources.
  • -DPYTHON_EXECUTABLE=/usr/bin/python3: Explicitly sets the path to the Python 3 executable. This is important for ensuring that ROS uses Python 3, as ROS Noetic is designed to work with Python 3 due to Python 2 reaching the end of its life.

Executing this command will compile and install ROS Noetic to the specified install space, making it available for development and use.


Warning! 

Building ROS from source can be time-consuming, especially with -j1, so it might take a while to complete. You may relax and wait until it is done!

Why not try to play a game to help SoC train AI? Click here to play!



Debugging Time 

Note: If you encounter error messages like Command failed, exiting.. This highly likely means you did not install and set up Python prerequisites correctly. Please redo section 4 again and retry running section 6 code.

This issue should be solved elegantly!



Check Your Work Now 

Please check by running the codes in this section; you received no warnings or errors.

Have you done all the tasks correctly above?



7. Initialize and Test ROS Noetic

We will use the pre-installed turtlesim to test the functionalities of ROS. Before we run the ROS, we need install some python packages manually. Please enter a terminal, and use these commands to install packages:

sudo apt update
sudo pip3 install defusedxml
sudo pip3 install rospkg
sudo pip3 install netifaces
Then, please follow these steps to test your ROS:

  1. Open a terminal and enter source /opt/ros/noetic/setup.bash. [Note: You need to do this for all new terminals to add the packages to the ROS searching directory list. The configuration only works for the current terminal.]
  2. Enter roscore to start the ROS master program, you will see:


  3. Open another terminal, perform the command from step 1 again, then enter rosrun turtlesim turtlesim_node. You should see a window titled "TurtleSim" on your screen:


    This window simulates a turtle. Note: The turtle drawing is random, so your turtle may appear differently. Do NOT close the turtlesim window.
  4. To find out how many ROS nodes are involved, open a new terminal and enter rosnode list. You should see the following output:
    /rosout
    /turtlesim
    The turtlesim node is what you see visualized, while rosout is the default console log output.
  5. In a new terminal, perform the command from step 1, then enter rosrun turtlesim turtle_teleop_key. This command starts another ROS node turtle_teleop_key which allows you to control the turtle simulation using your keyboard. Use the arrow keys to move your turtle around, here is a GIF demostration:


This hands-on experience with turtlesim helps solidify your understanding of ROS Noetic's basic functionalities and node interaction.

· End of Tutorial ·


★ Bonus Time! 

You have done 0 out of 6!

Hip, hip, hooray! You have successfully set up the ROS on your Raspberry Pi by yourself! We highly recommend trying out Tutorial 2: Listener & Talker Exercise to familiarize yourself with the ROS. Detailed instructions will be provided in the next tutorial.




References:

  • Prof. Boyd Anderson; CG2111A, AY22/23 Semester II;

< Prev  Tutorial Homepage    |    Tutorial 2: Listener & Talker  Next >