# Setup - Introduction

### Welcome to your first AVC - F1Tenth tutorial!

Today, we will master basic terminal commands and establish a robust development environment for our ROS 2 autonomous project.

Before we dive in, we need to set up a few prerequisites. This step is crucial for the smooth operation of our project.<br>
**Do not skip this step** (unless the libraries are already installed and up-to-date), or you may encounter issues with commands not working.

---

## 🔨 Prerequisite Installation

### Installing Docker and Git

+++ macOS

!!!secondary
_Note: macOS usually comes with Git pre-installed. You can check if it's already installed by typing `git --version` in your terminal. If it's not installed, or you want to update it to the latest version, follow the steps below._
!!!

1. **Docker:**
   Download Docker Desktop for Mac from the official [Docker website](https://www.docker.com/products/docker-desktop). Open the downloaded `.dmg` file and drag Docker.app to your Applications folder.

2. **Git:**
   If you have Homebrew installed, open your terminal and type the following command:
   ```
   brew install git
   ```
   If you don't have Homebrew installed, you can install it first by following the instructions on the [Homebrew website](https://brew.sh).

+++ Windows

1. **Docker:**
   Download Docker Desktop for Windows from the official [Docker website](https://www.docker.com/products/docker-desktop). Follow the installation instructions provided by the installer.

2. **Git:**
   Download the official Git for Windows from the [Git website](https://git-scm.com/download/win). When you've downloaded the installer, run it and follow the instructions.

3. **WSL**
   Follow this tutorial to enable WSL which will allow running `bash` commands: [Using bash natively - Windows](https://www.geeksforgeeks.org/use-bash-shell-natively-windows-10/)

!!!danger **Windows 11 and WSL2**
if you run into any errors like `execvpe /bin/bash failed 2`:
- run `wsl --install -d Ubuntu`
- then `wsl --set-default Ubuntu`
- you should then be able to run `bash` and enter the Linux terminal.

If you have issues about `\r` not being a known character, delete your `f1tenth` folder then clone it again *inside the Linux environment*.
!!!

+++ Ubuntu/Linux

!!!secondary
_Note: Most Linux distributions come with Git pre-installed. You can check if it's already installed by typing `git --version` in your terminal. If it's not installed, or you want to update it to the latest version, follow the steps below._
!!!

!!!info
_Optionally:_ Linux users can opt to skip Docker steps as the code is already native on Linux distributions. However, it requires downloading any requirements that are handled by the Dockerfile. Advanced users should choose this option.
!!!

1. **Docker:**
   Open a terminal and type the following commands:

   ```
   sudo apt-get update
   sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
   curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
   sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
   sudo apt-get update
   sudo apt-get install docker-ce
   ```

2. **Git:**
   Open a terminal and type the following command:
   ```
   sudo apt install git
   ```

+++ Fedora

!!!secondary
_Note: Fedora comes with Git pre-installed. You can check if it's already installed by typing `git --version` in your terminal. If you want to update it to the latest version, follow the steps below._
!!!

1. **Docker:**
   Open a terminal and type the following commands:

   ```
   sudo dnf -y install dnf-plugins-core
   sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
   sudo dnf install docker-ce
   sudo systemctl start docker
   sudo systemctl enable docker
   ```

2. **Git:**
   Open a terminal and type the following command:
   ```
   sudo dnf install git
   ```
   +++

Remember to check if these programs were installed correctly by typing `docker --version` and `git --version` in your terminal. You should see the installed version of Docker and Git respectively.

==- Note for Windows users

This and following tutorials are written with a _UNIX_ shell in mind. If you are not in a _UNIX_ shell, some commands are different.
Make sure to replace the following:

|      Bash command | Windows command {class="compact"} |
| ----------------: | ----------------------------------- |
|              `ls` | `dir`                               |
|           `clear` | `cls`                               |
|              `rm` | `del`                               |
|           `rm -r` | `rmdir`                             |
|             `man` | `help`                              |
|              `mv` | `move`                              |
|             `cat` | `type`                              |
| `vi, emacs, nano` | `edit`                              |

===

---

### 📁 Step 1: Create a New Folder Structure

Let's start by navigating to your home directory. Open your terminal and enter the commands:

```bash
cd ~/
```

The `cd` command will change your current directory.

!!!info Knowledge check
<sub>Experiment with `cd {directory}` ("**C**hange **D**irectory") to navigate folders.
Keep in mind that `~` signifies your HOME directory (`/home/{your name}` on Linux, `C:\Users\{your name}` on Windows, and `/Users/{your name}/` on Mac). Finally, `cd ..` brings you back one directory.</sub><br>
!!!

---

### 📚 Step 2: Clone the Repository

Now, let's clone the tutorial repository from GitHub using the `git` command.
```bash
git clone https://gitlab.msu.edu/canvas/soar/public/f1tenth
```

This will create a new directory named `f1tenth` inside your home directory, which will contain all the files for the tutorials.

---

### 🚀 Step 3: Set Up the Docker Container

Next, navigate to the `f1tenth` directory, and list the new files that have been added:

```bash
cd f1tenth
ls
```

You should see some scripts (`.sh` files), a `src` directory, and other files.

Ensure that you have Docker installed and running. You can verify this by typing:

```bash
docker --version
```

You should see Docker's version number if it's correctly installed. If not, please verify Docker Desktop is running or revisit the installation instructions to ensure Docker is set up correctly.

To get the Docker container up and running, use the provided `run_docker.sh` script:

```bash
bash run_docker.sh
```

This will build and launch the Docker container needed for the tutorials.

If successful, you should see a prompt that says: `{your_name}@{random_stuff}[DOCKER]:/ros2_ws# `

---

### 🧼 Step 4: Prepare the `src/` folder.

Next, delete the contents of the `src/` directory as we will be setting up the code on our own. You can always refer to the complete codebase [here](https://github.com/MSU-AVC/f1tenth) if you get stuck later.

```bash
find src/ -mindepth 1 -maxdepth 1 -type d ! -name 'f1tenth_gym_ros' -exec rm -rf {} +
```
This command will remove all files in `src/` except for `f1tenth_gym_ros` and `.gitignore`, which is the simulator and some hidden files.

---

And _voilà_! You've successfully set up your environment for the F1Tenth tutorials.

Congratulations! 🎉 Now, let's get coding
