Skip to content

Commit

Permalink
Add docker support (#6)
Browse files Browse the repository at this point in the history
* Add dockerfile
* Add docker run commands
* Add instructions for noetic docker
  • Loading branch information
kanishkegb authored Aug 20, 2023
1 parent 9008659 commit 30ecc3a
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 19 deletions.
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM ros:noetic-ros-core-focal
RUN apt update
RUN apt -y install python3-pip python3-gi python3-pip tmux
RUN apt -y install mesa-utils libgl1-mesa-glx dbus
RUN apt -y install libgtk-3-dev python3-gi gobject-introspection
RUN apt -y install ros-noetic-gazebo-ros-pkgs ros-noetic-gazebo-ros-control ros-noetic-xacro
RUN python3 -m pip install pip --upgrade
RUN python3 -m pip install numpy pandas matplotlib

RUN python3 -m pip install -U rosdep
RUN sudo rosdep init
RUN rosdep update

RUN adduser --disabled-password sim
USER sim

WORKDIR /home
73 changes: 55 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This repository includes Python codes for the position control a UAV in a Gazebo
* Can easily find modules or libraries for different tasks

## Which controller is used for the UAV control?
* A geometric controller with decouppled-yaw attitude control is used
* A geometric controller with decoupled-yaw attitude control is used
* The controller is published in:
```sh
@InProceedings{Gamagedara2019b,
Expand Down Expand Up @@ -68,7 +68,31 @@ This repository includes Python codes for the position control a UAV in a Gazebo
:bangbang: If you are running this on a virtual machine, please make sure that Gazebo can run at real-time speed.
It is known that this simulation exhibits unintended behavior if the "real-time factor" of the Gazebo simulation is not closer to 1.0 (See [issue#3](https://github.com/fdcl-gwu/uav_simulator/issues/3)).

### Setting-up the repository
1. Clone the repository.
```sh
git clone https://github.com/fdcl-gwu/uav_simulator.git
```
1. Update the submodules.
```sh
cd uav_simulator
git submodule update --init --recursive
```

### Dependencies

You have to options here:
1. Installing everything locally
1. Running a docker container

Installing everything locally is probably the fastest way, but you may have to instal dependencies manually, or may have to deal with package version changes.
Docker solves this by streamlining all the dependencies, up-to the OS.
For example, if you are on Ubuntu 22.04 and want to test the ROS-Melodic version, docker will be the only way.

If you want to install everything locally, follow [Local Install](#local-install).
If you want to run a docker container instead, skip to [Docker Setup](#docker-setup).

#### Local Install
1. [ROS](http://wiki.ros.org/): this repository has been developed using ROS Noetic, on Ubuntu 20.04. If you are on ROS Melodic with Ubuntu 18.04, please checkout `ros-melodic` branch before installing dependencies.
1. Python GTK libraries for GUI (not required if you opt to not to use the GUI)
```sh
Expand All @@ -82,37 +106,50 @@ It is known that this simulation exhibits unintended behavior if the "real-time
python3 -m pip install numpy pandas matplotlib
```

### Setting-up the repository
1. Clone the repositroy.
```sh
git clone https://github.com/fdcl-gwu/uav_simulator.git
```
1. Update the submodules.
```sh
cd uav_simulator
git submodule update --init --recursive
```
Now, skip to [Setting-up the plugins and Gazebo](#setting-up-the-plugins-and-gazebo).

#### Docker Setup

The instructions here assume you are on Ubuntu.
This has not been tested on other OS versions.

1. Install docker following [official instructions](https://docs.docker.com/engine/install/ubuntu/).
1. If you are not already there, `cd uav_simulator`
1. Enable xhost (required for Gazebo and GUI): `xhost +`
1. Build the docker image: `docker build -t uav_simulator .`
1. Run a container: `bash docker_run.sh`

The last command will start a docker container, install all the dependencies, and mount the local directory there.
The first time you run the build command will take a while as it installs all the libraries.

After that, you only need to run the `bash docker_run.sh` every time you need to run the simulation.
Since this mounts the local repository inside the docker, you just need to change the code in your local repository, and it will be automatically update inside the docker.

For running the code, simply follow [Setting-up the plugins and Gazebo](#setting-up-the-plugins-and-gazebo), and onwards.


### Setting-up the plugins and Gazebo
You only need to do the followings once (unless you change the Gazebo plugins)
1. Make the pluging.
1. Make the plugging.
```sh
cd uav_simulator
# From uav_simulator
catkin_make
```
1. Source the relevant directories (**NOTE**: you need to do this on every new terminal).
```sh
cd uav_simulator
# From uav_simulator
cd devel && source setup.bash && cd ../
```

### Runing the simulation environment
### Running the simulation environment
1. In the current terminal window, launch the Gazebo environment:
```sh
# From uav_simulator
roslaunch uav_gazebo simple_world.launch
```
1. Once the Gazebo is launched, run the rover code from a different rover terminal (if you already don't know, you may find [**tmux**](https://github.com/tmux/tmux/wiki) a life-saver):
```sh
# From uav_simulator/scripts
python3 main.py
```
If you change the Python code, simply re-run the Python code.
Expand All @@ -121,7 +158,7 @@ You only need to do the followings once (unless you change the Gazebo plugins)
![Terminal](images/running.gif)
### Tips
1. Everytime you change the simulation environment, you have to kill the program, `catkin_make` and re-run it.
1. Every time you change the simulation environment, you have to kill the program, `catkin_make` and re-run it.
1. If you do not make any changes to the simulation environment, you only need to kill the Python program.
1. The UAV will re-spawn at the position and orientation defined in `reset_uav()` in `rover.py` when you run the Python code.
Expand All @@ -132,7 +169,7 @@ You only need to do the followings once (unless you change the Gazebo plugins)
* When take-off, stay, and circle trajectories end, the UAV switched to the "manual" mode.
* When the UAV is in manual, you can use following keys (these are not case sensitive):
* `WASD`: to move in horizontal plane
* `P`: increase altitiude
* `P`: increase altitude
* `L`: decrease altitude
* `Q`: yaw rotation in anti-clockwise direction
* `E`: yaw rotation in clockwise direction
Expand All @@ -146,4 +183,4 @@ You only need to do the followings once (unless you change the Gazebo plugins)
* Make sure you are in the main directory.
* Run `python -m unittest`.
* Unit tests have only been tested on Python 3.9.
* Currently, unit test only covers the `matrix_utils.py` module.
* Currently, unit test only covers the `matrix_utils.py` module.
9 changes: 9 additions & 0 deletions docker_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
docker run \
--rm \
--mount source="$(pwd)",target=/home/uav_simulator,type=bind \
--net host \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-u sim \
-e DISPLAY=unix$DISPLAY \
--privileged \
-it uav_simulator bash
6 changes: 5 additions & 1 deletion scripts/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def on_btn_close_clicked(self, *args):
def on_btn_plot_clicked(self, widget):
print('GUI: generating plots ..')
# plot_data()
os.system('python plot_utils.py')
os.system('python3 plot_utils.py')


def on_tgl_save_toggled(self, widget):
Expand Down Expand Up @@ -218,3 +218,7 @@ def thread_gui():

rover.on = False
print('GUI: thread closed!')


if __name__=='__main__':
thread_gui()

0 comments on commit 30ecc3a

Please sign in to comment.