---
# System prepended metadata

title: SDC Assignment 1.2 - ROS 2
tags: [Self-Driving Cars, ROS, ROS2]

---

# SDC Assignment 1.2 - ROS 2

###### tags: `Self-Driving Cars`, `ROS`, `ROS2`

## Part 1. Install ROS 2

### Environment
Ubuntu 20.04 LTS

ROS 2 foxy

### Set locale
Make sure you have a locale which supports UTF-8. If you are in a minimal environment (such as a docker container), the locale may be something minimal like POSIX. We test with the following settings. However, it should be fine if you’re using a different UTF-8 supported locale.

```bash
locale  # check for UTF-8

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

locale  # verify settings
```

### Setup Sources
You will need to add the ROS 2 apt repositories to your system. To do so, first authorize our GPG key with apt like this:

```bash
sudo apt update && sudo apt install curl gnupg2 lsb-release
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key  -o /usr/share/keyrings/ros-archive-keyring.gpg
```

And then add the repository to your sources list:
```bash
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
```

### Install ROS 2 packages
Update your apt repository caches after setting up the repositories.

```bash
sudo apt install -y python3-pip
sudo apt update && sudo apt install -y \
  build-essential \
  cmake \
  git \
  python3-colcon-common-extensions \
  python3-lark-parser \
  python3-pip \
  python-rosdep \
  python3-vcstool \
  wget
```

Desktop Install (Recommended): ROS, RViz, demos, tutorials.

```bash
sudo apt install ros-foxy-desktop
```

### Environment setup
Set up your environment by sourcing the following file.

```bash
source /opt/ros/foxy/setup.bash
```

Add `source /opt/ros/foxy/setup.bash` to your `.bashrc` file.

```bash
echo "source /opt/ros/foxy/setup.bash" >> ~/.bashrc
```

### Install argcomplete

ROS 2 command line tools use argcomplete to autocompletion. So if you want autocompletion, installing argcomplete is necessary.

```bash
pip3 install -U argcomplete
```

### Ckeck installation
```bash
ros2 -h
```

![ros2 -h](https://i.imgur.com/K1Bx8gC.png)

### Install other ROS package

```bash
sudo apt update
sudo apt install ros-foxy-rviz
rviz2
```

![rviz](https://i.imgur.com/UIIXZ0J.png)

### Tutorial
1. [Creating a workspace](https://index.ros.org/doc/ros2/Tutorials/Workspace/Creating-A-Workspace/#next-steps)
2. [Creating your first ROS 2 package](https://index.ros.org/doc/ros2/Tutorials/Creating-Your-First-ROS2-Package/)
4. [Writing a simple publisher and subscriber (C++)](https://index.ros.org/doc/ros2/Tutorials/Writing-A-Simple-Cpp-Publisher-And-Subscriber/)
5. [Writing a simple publisher and subscriber (Python)](https://index.ros.org/doc/ros2/Tutorials/Writing-A-Simple-Py-Publisher-And-Subscriber/)

### Assignment
The Screenshot of both ROS2 subscriber and publisher terminal in tutorial 3 or 4. 

Please include your personal information to prove that you have finished this on your own. (Ex. your username in terminals)

### Reference
[Installing ROS 2 via Debian Packages](https://index.ros.org/doc/ros2/Installation/Foxy/Linux-Install-Debians/)

---

## (Optional) Part 2. Install ROS1_bridge to bridge ROS1 and ROS2

This is an optional part for you if you have been working on ROS1 and need to bridge old package with ROS2. You can skip this part if you haven't tried ROS1 before.

### Install

```bash
sudo apt update
sudo apt install ros-foxy-ros1-bridge ros-foxy-turtlebot3
sudo apt-get install ros-foxy-ros2bag ros-foxy-rosbag2
```
- If you directly run the commands above, you may encounter errors of unmet dependency. This is because you haven't install ROS1 and there are no ROS1 packages in your package list. [Install ROS1](http://wiki.ros.org/noetic/Installation/Ubuntu) first and try these commands again.

### Tutorial
Please follow this [document](https://github.com/ros2/ros1_bridge/blob/master/README.md)

### Assignment
No assignment for this part.
