# PyBullet Mapping Simulation Template

**Python Robotics Workshop, Existential Robotics Lab at UC San Diego**

## Resources

The algorithms to be implemented for this template are showcased on the [Robot Proving Grounds](https://existentalrobotics.org/RobotProvingGrounds/) website and will be presented on the [workshop slides](https://docs.google.com/presentation/d/1dz7LrNmw8jzC080YQJJN5dfScTV3EXVjPDQCp_U9S84/edit?usp=sharing). Please complete the workshop Colab tutorials before moving onto this PyBullet simulation.

## Getting Started with the Simulation Environment

To install and run the simulation environment, we will be using Conda.
In your command terminal, navigate to the pybullet-sim/pybullet-sim directory.
Then, run these two commands:

Bash:
```bash
$ chmod +x ./setup/setup.sh
$ ./setup/setup.sh
```

Z shell:
```zsh
$ bash ./setup/setup.sh
```

Windows:

Open powershell as an administrator and run the following lines:

```powershell
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass # This allows scripting (only for this session)
./setup/setup.ps1
```

The setup script will accept Conda TOS for you and automatically build
a virtual environment to run our simulation. You will also be asked if you want
"base" to become a default virtual environment. You can deactivate any environment
by typing deactivate.

The environment built will be called RPG_Workshop1. To enter the environment, type

```bash
Conda activate RPG_Workshop1
```

This command is the same for Windows.

The simulation environment currently supports two robots:

* Ackermann Drive F1TENTH Racecar
* Differential Drive Husky Robot with Kuka Arm attached

The provided template will be using the Ackermann Drive F1TENTH Racecar. 

## Your Tasks

Paste your functions from your completed Colab tutorials into the ```functions.py``` file. After doing so, run the simulation using the following command:

```bash
python pybullet_map.py
```

## Controlling the Robot

The arrow keys can be used to control the car. Drive the car around the environment to see how the LiDAR data updates the map. Press "x" on your keyboard while on the map window to close the simulation.


![](./docs/images/simulation_car.gif)


## Simulation Information

Running the simulation will open 3 windows, the PyBullet simulation, an OGM of the environment displayed in a probability or log-odds color map, and a colorbar for reference. 

The simulated environment spans an area of a square the size of 10 x 10 meters.

The simulated LiDAR rays are displayed in red or green, which indicates whether the ray is out of range (green) or in range (red). 

Some details about the simulation and the specfications of the map can be tweaked in the configs, which is described below.

## Changing Simulation Specfications

Simulation Specfications can be edited in the ```pybullet_map.py```, ```map_config.yaml```, and ```src\configs\car\car_config.yaml``` files.

* In ```pybullet_map.py```, the Hertz at which certain parts of the simulation are simulated can be edited at lines 34-37. It is recommended to only tweak the ```LIDAR_FPS```.
* In ```map_config.yaml```, the map's configs can be edited. It is recommended to tweak any values except for ```lidar_offset```.
* In ```car_config.yaml```, the car's configs can be edited. It is recommended to only tweak the ```lidar_angle1```, ```lidar_angle2```, ```num_rays```, ```ray_len```.

Specifications can be edited further through other methods and files besides the recommended ones listed above. Feel free to explore ways to change parameters on your own.