Week 1: Linux Basics & ROS2 Introduction

Robotics Programming with ROS2 and Python

Week 1 of 16 Ubuntu 24.04 ROS2 Jazzy Python 3.12+

Week Overview

Learning Objectives

By the end of this week, you will be able to:

  1. Install and configure Ubuntu 24.04 LTS
  2. Navigate the Linux file system with confidence
  3. Execute essential Linux commands for file and system management
  4. Write basic bash scripts for automation
  5. Understand ROS2 architecture and DDS middleware
  6. Successfully install ROS2 Jazzy
  7. Control TurtleSim using ROS2 command-line tools
Course Information
  • Week: 1 of 16
  • Duration: 3 hours (2 hours in-campus + 1 hour asynchronous)
  • Office Hours: Every Day, 10:00 AM - 12:00 PM
  • Location: Innovation Center - Robotics Lab / Online (Teams)

Linux Fundamentals

Why Linux for Robotics?

Advantages of Linux
  • Open Source: Free, customizable, and transparent
  • Stability: Reliable for long-running robotic systems
  • Performance: Efficient resource utilization
  • Community: Vast ecosystem and extensive documentation
  • ROS Support: Native development environment for ROS2
  • Real-time Capabilities: Support for RT-PREEMPT kernel
  • Hardware Compatibility: Excellent driver support

Why Ubuntu 24.04?

  • LTS Release: 5 years of support until May 2029
  • Official Support: Primary platform for ROS2 Jazzy
  • Community: Largest Linux community for support
  • User-Friendly: Intuitive graphical interface
  • Updated Packages: Python 3.12, latest libraries

Linux File System Structure

Directory Purpose Example
/Root directoryTop of file hierarchy
/homeUser home directories/home/username
/binEssential binariesls, cp, mv commands
/etcConfiguration filesSystem settings
/varVariable dataLog files, caches
/usrUser programsInstalled applications
/tmpTemporary filesCleared on reboot
/optOptional softwareThird-party apps

Terminal Basics

Opening the Terminal:

  • Keyboard Shortcut: Ctrl + Alt + T
  • Search: Press Super key (Windows key), type "Terminal"

Understanding the Prompt:

username@hostname:~$
# username: Your login name
# hostname: Computer name
# ~: Current directory (home)
# $: Regular user (# means root/admin)

Essential Linux Commands

Navigation Commands

# Print Working Directory (where am I?)
pwd

# List files and directories
ls              # Basic list
ls -l           # Long format (detailed)
ls -a           # Show hidden files
ls -la          # Long format + hidden

# Change Directory
cd Documents    # Go to Documents folder
cd ..           # Go up one level
cd ~            # Go to home directory
cd /            # Go to root directory
cd -            # Go to previous directory

File Operations

# Create empty file
touch myfile.txt

# Create directory
mkdir myfolder
mkdir -p parent/child/grandchild  # Create nested directories

# Copy files/directories
cp file.txt backup.txt           # Copy file
cp -r folder1 folder2            # Copy directory recursively

# Move/Rename files
mv oldname.txt newname.txt       # Rename file
mv file.txt Documents/           # Move file

# Delete files/directories
rm file.txt                      # Delete file
rm -r folder                     # Delete directory
rm -rf folder                    # Force delete (use with caution!)

File Permissions

Permission Format: -rwxr-xr--

  • r (read) = 4
  • w (write) = 2
  • x (execute) = 1
# Make file executable
chmod +x script.sh

# Set specific permissions
chmod 755 file.txt    # rwxr-xr-x
chmod 644 file.txt    # rw-r--r--
chmod 600 file.txt    # rw-------

Bash Scripting Basics

Create your first script:

#!/bin/bash
# My first ROS2 setup script

echo "Setting up ROS2 environment..."
source /opt/ros/jazzy/setup.bash
echo "ROS2 environment loaded!"
echo "ROS Distribution: $ROS_DISTRO"
echo "Current directory: $(pwd)"

To run the script:

chmod +x setup_ros2.sh
./setup_ros2.sh

Useful Terminal Tips

Keyboard Shortcuts
  • Tab - Auto-complete commands and filenames
  • Ctrl + C - Cancel current command
  • Ctrl + L - Clear screen
  • / - Navigate command history
  • Ctrl + R - Search command history

ROS2 Introduction

What is ROS2?

Robot Operating System 2 (ROS2) is an open-source robotics middleware framework that provides tools, libraries, and conventions for building complex robot behaviors.

Key Features
  • Real-time Performance: Support for real-time systems and deterministic behavior
  • Multi-platform: Works on Linux, Windows, macOS, and RTOS
  • Security: Built-in security features (SROS2)
  • Scalability: From single robots to large multi-robot systems
  • Industry-grade: Production-ready quality
  • DDS Communication: Standard, reliable middleware

ROS1 vs ROS2

Feature ROS1 ROS2
CommunicationCustom TCP/UDPDDS Standard
Real-timeNot supportedSupported
Multi-robotComplex setupBuilt-in
SecurityBasicAdvanced (SROS2)
PlatformsLinux onlyLinux, Windows, macOS
Master NodeRequired (SPOF)Decentralized

ROS2 Architecture

ROS2 uses a layered architecture design:

  1. Operating System Layer: Linux, Windows, macOS, RTOS
  2. DDS Layer: Data Distribution Service middleware
  3. RCL Layer: ROS Client Library (C-based core API)
  4. Language Bindings: rclcpp (C++), rclpy (Python)
  5. Application Layer: Your robot application code

ROS2 Core Concepts

Nodes

Independent processes that perform computation. Each node should have a single, well-defined purpose.

Topics

Named buses for asynchronous data streaming using publish-subscribe pattern.

Services

Synchronous request-response communication for remote procedure calls.

Actions

Asynchronous, long-running tasks with feedback and ability to cancel.

ROS2 Jazzy Jalisco

  • Release Date: May 23, 2024
  • Support Period: Until May 2029 (5 years - LTS)
  • Target OS: Ubuntu 24.04 Noble Numbat
  • Python Version: 3.12
  • Status: Long Term Support (LTS) Release

ROS2 Jazzy Installation

System Requirements
  • Ubuntu 24.04 LTS (64-bit) installed
  • At least 4GB RAM (8GB recommended)
  • At least 10GB free disk space
  • Active internet connection

Installation Steps

Step 1: Setup Locale

locale
sudo apt update && sudo apt install locales
sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8

Step 2: Setup Sources

sudo apt install software-properties-common
sudo add-apt-repository universe
sudo apt update && sudo apt install curl -y
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key \
  -o /usr/share/keyrings/ros-archive-keyring.gpg

Step 3: Add ROS2 Repository

echo "deb [arch=$(dpkg --print-architecture) \
signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] \
http://packages.ros.org/ros2/ubuntu \
$(. /etc/os-release && echo $UBUNTU_CODENAME) main" | \
sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null

sudo apt update
sudo apt upgrade

Step 4: Install ROS2 Jazzy

sudo apt install ros-jazzy-desktop
Installation Time: This may take 10-20 minutes depending on your internet speed. Download size is approximately 1-2 GB.

Step 5: Install Development Tools

sudo apt install ros-dev-tools
sudo apt install python3-colcon-common-extensions
sudo apt install python3-rosdep python3-pip

sudo rosdep init
rosdep update

Environment Setup

# Source ROS2 (temporary)
source /opt/ros/jazzy/setup.bash

# Make it permanent
echo "source /opt/ros/jazzy/setup.bash" >> ~/.bashrc
source ~/.bashrc

Verify Installation

ros2 --help
ros2 doctor
echo $ROS_DISTRO  # Should output: jazzy
✓ Installation Complete! If all commands execute without errors, ROS2 Jazzy is successfully installed!

ROS2 Command Line Tools

ros2 node       # Work with nodes
ros2 topic      # Work with topics
ros2 service    # Work with services
ros2 action     # Work with actions
ros2 param      # Work with parameters
ros2 pkg        # Work with packages
ros2 run        # Run a node from a package
ros2 launch     # Launch multiple nodes
ros2 interface  # Show message/service/action definitions
ros2 bag        # Record and play back data
ros2 doctor     # Check system status

TurtleSim Tutorial

TurtleSim is a lightweight 2D simulator designed for learning ROS2 concepts.

Running TurtleSim

# Install TurtleSim
sudo apt install ros-jazzy-turtlesim

# Run TurtleSim node
ros2 run turtlesim turtlesim_node

Controlling TurtleSim

# In a NEW terminal, run teleop node
ros2 run turtlesim turtle_teleop_key

# Control with arrow keys

Publishing Commands Directly

# Make turtle move forward
ros2 topic pub /turtle1/cmd_vel geometry_msgs/msg/Twist \
"{linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}"

# Make turtle rotate
ros2 topic pub /turtle1/cmd_vel geometry_msgs/msg/Twist \
"{linear: {x: 0.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.8}}"

TurtleSim Services

# Spawn a new turtle
ros2 service call /spawn turtlesim/srv/Spawn \
"{x: 2.0, y: 2.0, theta: 0.2, name: 'turtle2'}"

# Change pen color
ros2 service call /turtle1/set_pen turtlesim/srv/SetPen \
"{r: 255, g: 0, b: 0, width: 5, off: 0}"

# Clear background
ros2 service call /clear std_srvs/srv/Empty

Inspecting TurtleSim

# List all nodes
ros2 node list

# List all topics
ros2 topic list

# Monitor turtle's position
ros2 topic echo /turtle1/pose

# List parameters
ros2 param list /turtlesim

Week 1 Project: TurtleSim Mastery

Project Requirements
1. Linux Setup
  • Install Ubuntu 24.04 (screenshot required)
  • Complete 10 file system navigation exercises
  • Create a directory structure for your ROS2 workspace
2. Bash Scripting
  • Write a script to automatically source ROS2 and spawn multiple turtles
  • Script should accept turtle name and position as arguments
  • Include error handling
3. TurtleSim Control
  • Draw the following shapes: square, circle, star, figure-8
  • Change pen colors for each shape
4. ROS2 Commands
  • Spawn at least 3 turtles in different positions
  • Change background color to your choice
  • Demonstrate use of services, topics, and parameters
5. Creative Challenge
  • Create "TurtleSim Art" - draw something creative
  • Use multiple colors and turtles

Grading Rubric

Component Points
Linux Setup & Commands20
Bash Script Quality20
TurtleSim Basic Control20
ROS2 Commands Mastery20
Creative Challenge10
Documentation Quality10
Total100

Resources & References

Official Documentation
Community Resources
Next Week Preview
Week 2: Workspace & Package Management
  • Creating ROS2 workspaces with colcon
  • Understanding package structure
  • Building Python packages
  • Managing dependencies