---
# System prepended metadata

title: Driverless Simulating Environment
tags: [NTURT, electrical_system, driverless]

---

# Driverless Simulating Environment
###### tags: `driverless` `electrical_system` `NTURT`

## Introduction

Simulating environment is vital for a driverless system to first test the algorithm in simulation before deploying to the actual hardware. And two simulating environments will be serving the purpose here which are:

- [F1TENTH Gym](https://f1tenth-gym.readthedocs.io/en/latest/)
- [Formula Student Driverless Simulator (FSDS)](https://fs-driverless.github.io/Formula-Student-Driverless-Simulator/v2.2.0/)

Both of them provides excellent support for ROS2, yet FSDS uses mature Unreal Engine with AirSim plugin as the physics engine and F1TENTH Gym uses custom vehicle model written in python. And FSDS also provides various simulated sensors, ranging from cameras, IMUs, GPSs, ect. Hence is the better representation of the real race car and that's why we will use it as the simulation for developing mapping algorithm and testing the driverless system for the sctual race car.

However, F1TENTH Gym will still be utilized for our small car model as it better fits the limition and environment of it (i.e. only lidar as the snesnor input and walls instead of cones as the track boundries).

## F1TENTH Gym

### Install

Follow the instruction: [Install: Native on Ubuntu 20.04](https://github.com/f1tenth/f1tenth_gym_ros#native-on-ubuntu-2004) to install it, remember to replace all instance of `foxy` with the current ROS2 distro you're using.


First, install [f1tenth_gym](https://github.com/f1tenth/f1tenth_gym) by

```bash
git clone https://github.com/f1tenth/f1tenth_gym
cd f1tenth_gym && pip3 install -e .
```

Second, install our custom package built around f1tenth_gym and [ros nav2](https://navigation.ros.org/) by

```bash
# in PATH/TO/ROS/WORKSPACE
git clone https://github.com/NTURacingTeam/nturt_nms src/nturt_nms1
rosdep install --from-paths src --ignore-src -r -y
colcon build
```

### Usage

After installation, you can run the simulation by:

```bash
ros2 launch nturt_nms1_sim nms1_sim.launch.py
```

### Configuration

As for the configuration and what topics are published or subscribed, please checkout: [Configuring the simulation](https://github.com/f1tenth/f1tenth_gym_ros#configuring-the-simulation) for more info.

As for further tuning of the simulation, please checkout the documentation: [F1TENTH Gym](https://f1tenth-gym.readthedocs.io/en/latest/index.html).

## FSDS

### Install

First download the precompiled package as mentioned in the tutorial: [Getting started](https://fs-driverless.github.io/Formula-Student-Driverless-Simulator/v2.2.0/getting-started/) **to your home directory**.

> Note: The precompiled binary only targets `x86` computers, so for other archs, you have to compile it from source following the `From source using the Unreal Engine Editor` section of [Getting started](https://fs-driverless.github.io/Formula-Student-Driverless-Simulator/v2.2.0/getting-started/).

Next, install `fsds_ros2_bridge` by

```bash
# in PATH/TO/ROS/WORKSPACE
clone https://github.com/NTURacingTeam/FSDS src/FSDS
./src/FSDS/AirSim/setup.sh
rosdep install --from-paths src --ignore-src -r -y
colcon build
```

### Usage

After installation, you can run the simulation by

```bash
# in PATH/TO/Formula-Student-Driverless-Simulator/binary/install
./FSDS.sh
```

and launch `fsds_ros2_bridge` by

```bash
ros2 launch fsds_ros2_bridge fsds_ros2_bridge.launch.py
```

### Configuration

TBD
