# Getting Started

## Prerequisites

<span style="white-space: pre-wrap;">All development happens on </span>[Ubuntu 22.04 (Jammy Jellyfish)](https://releases.ubuntu.com/jammy/)<span style="white-space: pre-wrap;">. If you are running Windows, the easiest way to install it is </span>[through WSL2](https://learn.microsoft.com/en-us/windows/wsl/install).

<span style="white-space: pre-wrap;">If you prefer to work in Docker, you can use image </span>`<span class="editor-theme-code">docker.io/osrf/ros:humble-desktop-full</span>`.

<span style="white-space: pre-wrap;">You need to have a basic understanding of ROS2. Follow </span>[ROS2 tutorials](https://docs.ros.org/en/humble/Tutorials.html)<span style="white-space: pre-wrap;"> before you continue.</span>

## First time setup

<p class="callout info"><span style="white-space: pre-wrap;">See </span>[README.md](https://github.com/RoboTeamTwente/erc-software-rover/blob/main/README.md)<span style="white-space: pre-wrap;"> for more up-to-date instructions.</span></p>

<p class="callout danger">Watch out! NVIDIA “helpfully” keeps packages more up-to-date than stock Ubuntu, so e.g. OpenCV's version will be fresher on Jetson, compared to your development laptop.</p>

```bash
### Download the code
git clone https://github.com/RoboTeamTwente/erc-software-rover
cd erc-software-rover
git submodule update --init --recursive

### Launch ROS2 in Docker (only if you don't have Ubuntu 22.04)
#docker run --rm -it -v $PWD:/src -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY osrf/ros:humble-desktop-full
#cd /src

### Install dependencies
apt update
rosdep install -iy --from-path src

### Compile RealSense depth cam driver with custom flags
# It is a good time to grab some tea.
# Compilation will take about 5 minutes on a reasonably modern laptop,
# or about 30 minutes on Jonny Boi.
colcon build --packages-select librealsense2 --cmake-args \
  -DCHECK_FOR_UPDATES=OFF                                 \
  -DFORCE_RSUSB_BACKEND=ON
```

`<span class="editor-theme-code">librealsense2</span>`<span style="white-space: pre-wrap;"> is built from source to switch it to the </span>`<span class="editor-theme-code">RSUSB</span>`<span style="white-space: pre-wrap;"> backend. We use this backend because it does not require a kernel patch, unlike the default one. See the </span>[RealSense installation guide](https://github.com/realsenseai/librealsense/blob/9a0dd70db1a2c180b69c6c257cd2ee6120505499/doc/installation_jetson.md)<span style="white-space: pre-wrap;"> for details. We also disable the update checker, because it fails to build for some reason.</span>

## Common operations

### Compile

While working on a package, you'll frequently want to compile it and all its dependencies:

```bash
colcon build --packages-up-to=$PACKAGE
source install/local_setup.bash
```

<p class="callout warning"><span style="white-space: pre-wrap;">Don't forget to </span>`<span class="editor-theme-code">cd</span>`<span style="white-space: pre-wrap;"> to the root of the repo!</span></p>

<p class="callout info">`<span class="editor-theme-code">local_setup.bash</span>`<span style="white-space: pre-wrap;"> doesn't need to be sourced most of the time.</span></p>

### Run your code

<span style="white-space: pre-wrap;">There are two different things you can run in ROS2: A node, and a launch file. For more details see </span>[Understanding nodes](https://docs.ros.org/en/humble/Tutorials/Beginner-CLI-Tools/Understanding-ROS2-Nodes/Understanding-ROS2-Nodes.html)<span style="white-space: pre-wrap;"> and </span>[Launching nodes](https://docs.ros.org/en/humble/Tutorials/Beginner-CLI-Tools/Launching-Multiple-Nodes/Launching-Multiple-Nodes.html).

```bash
ros2 run $PACKAGE $EXECUTABLE
# -- or --
ros2 launch $PACKAGE $LAUNCH_FILE
```