Skip to content

Commit

Permalink
Dependency script (#60)
Browse files Browse the repository at this point in the history
Add bash script to install all dependencies.
  • Loading branch information
wil3 authored Jun 3, 2020
1 parent 9686929 commit 1b5857f
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 34 deletions.
97 changes: 69 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ Please use the following BibTex entries to cite our work,

![Architecture](https://github.com/wil3/gymfc/blob/master/images/gymfc2-arch.png)

> :warning: **Warning:** Documentation is lagging behind in regards to the new
> framework and installation instructions. Migration to GymFC2 is going to take
> some effort however it provides a sustainable framework moving forward.
> Documentation and additional examples will be added with time. Best bet at
> the moment is to read through the code, python side is in good shape, c++
> needs love.

## Table of contents

Expand Down Expand Up @@ -91,28 +85,75 @@ Please use the following BibTex entries to cite our work,

# Installation

Note, Ubuntu 16.04 LTS and 18.04 LTS are the only OS currently supported. Please submit a PR for the
README.md if you are
able to get it working on another platform. To ensure accurate and stable
simulations it is recommended to use DART with Gazebo. This requires Gazebo to
be installed from source. For more information please see this
[video](https://www.youtube.com/watch?v=d3NyFU0bVT0). We have found these
versions to work well together,
1. Compile and install DART v6.7 from source
[here](https://github.com/dartsim/dart/tree/v6.7.0).
1. Compile and install [Gazebo 10](http://gazebosim.org/tutorials?tut=install_from_source&cat=install).
2. (Optional) It is suggested to set up a [virtual environment](https://docs.python.org/3/library/venv.html). From the project root,
## Quick start
To install GymFC and its dependencies on Ubuntu 18.04 execute,
```
sudo MAKE_FLAGS=-j4 ./install_dependencies.sh
pip3 install .
```

## Dependencies
GymFC runs on Ubuntu 18.04 and uses [Gazebo v10.1.0](http://gazebosim.org/tutorials?tut=install_from_source&cat=install) with [Dart v6.7.0](https://github.com/dartsim/dart/tree/v6.7.0) for the backend simulator. To use Dart with Gazebo, they must be installed from source. For why Gazebo must be used with Dart see this [video](https://www.youtube.com/watch?v=d3NyFU0bVT0). The easiest way to install the dependencies is with the provided `install_dependencies.sh` script. By default it will run `make` with a single job. You can override the `make` flags with the `MAKE_FLAGS` environment variable. Building Gazebo from source is very resource intensive. If you have sufficient memory increase the number of jobs to run in parallel. For example to run four jobs in parallel execute,
```
sudo MAKE_FLAGS=-j4 ./install_dependencies.sh
```
Note, this script may take more than an hour to execute. If your build fails
check `dmesg` but the most common reason will be out-of-memory failures.

## GymFC
(Optional) It is suggested to set up a [virtual environment](https://docs.python.org/3/library/venv.html) to install GymFC into. From the project root run,
`python3 -m venv env`. This will create an environment named `env` which
will be ignored by git. To enable the virtual environment, `source
env/bin/activate` and to deactivate, `deactivate`.
2. From root directory of this project, `pip3 install .` If you plan to work with the GymFC source code you will want to install it in
development mode, `pip3 install -e .` You will also
need to build the plugin manually by running the script
`gymfc/envs/assets/gazebo/plugins/build_plugin.sh`.
3. Confirm `SetupFile` in `gymfc.ini` is pointing to the correct location.

## Installation using Docker
This repository includes an experimental docker build that demos the usage of GymFC.

Install GymFC,
```
pip3 install .
```
This will install the Python dependencies and also build the Gazebo plugins and
messages.

## Developing with GymFC
If you plan to modify the GymFC code you will need to install in
edit/development mode.
```
pip3 install -e .
```
You will also have to manually install the Gazebo plugins by executing,
```
gymfc/envs/assets/gazebo/plugins/build_plugin.sh
```
If you deviate from this installation instructions (e.g., installing Gazebo in
a different location other than specific in `install_dependencies.sh`), you
may need to change the location of the Gazebo `setup.sh` defined by the
variable SetupFile in `gymfc/gymfc.ini`.

## Verifying install

GymFC requires an aircraft model (digital twin) to run. The NF1 racing
quadcopter model is available in `examples/gymfc_nf/twins/nf1` if you need a
model for testing. To test everything is installed correctly run,

```
python3 tests/test_start_sim.py --verbose examples/gymfc_nf/twins/nf1/model.sdf
```
If everything is OK you should see the NF1 quadcopter model in Gazebo.

You will see the following error message because you have not built the
motor and IMU plugins yet.
```
[Err] [Plugin.hh:187] Failed to load plugin libgazebo_motor_model.so: libgazebo_motor_model.so: cannot open shared object file: No such file or directory
[Err] [Plugin.hh:187] Failed to load plugin libgazebo_imu_plugin.so: libgazebo_imu_plugin.so: cannot open shared object file: No such file or directory
```
Also the following error message is normal,
```
[Err] [DARTJoint.cc:195] DARTJoint: SetAnchor is not implemented
```

To use the NF1 model for further testing read examples/README.md.

## Install by Docker
This repository includes an experimental docker build in `docker/demo` that demos the usage of GymFC.
It has been tested on MacOS 10.14.3 and Ubuntu 18.04, however the Gazebo client
has not been verified to work for Ubuntu. This docker image can help ensure you
are running a supported environment for GymFC.
Expand All @@ -126,7 +167,7 @@ For Ubuntu, install [Docker for Ubuntu](https://docs.docker.com/engine/install/u
Build the docker image

```bash
docker build -f Dockerfile-demo . -t gymfc:demo
docker build . -t gymfc:demo
```
This will take a while as it compiles mesa drivers, gazebo and dart. It is recommended to give Docker a large part of the host's resources.
All incoming connections will forward to xquartz:
Expand All @@ -144,7 +185,7 @@ gymfc:demo \
```

Replace _<hostip>_ by the external ip of your system to allow gymfc to connect to your XQuartz server and _<path-to-gymfc-digitaltwin-solo>_ to where you cloned the Solo repo.
Take special note that the test_step_sim.py parameters are using the containers
Take special note that the `test_step_sim.py` parameters are using the containers
path, not the host's path.


Expand Down Expand Up @@ -316,4 +357,4 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->

Want to become a contributor?! Visit [CONTRIBUTING.md](https://github.com/wil3/gymfc/blob/master/CONTRIBUTING.md) for more information to get started.
Want to become a contributor?! Visit [CONTRIBUTING.md](https://github.com/wil3/gymfc/blob/master/CONTRIBUTING.md) for more information to get started.
File renamed without changes.
11 changes: 11 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ save Tensorflow checkpoints. In the same virtual environment you use for GymFC,
```
pip3 install .
```
3. Build the motor models.
```
pip3 install .
mkdir gymfc_nf/twins/nf1/plugins
cd gymfc_nf/twins/nf1/plugins
git clone https://github.com/wil3/gymfc-aircraft-plugins.git
mkdir build
cd build
cmake ../gymfc-aircraft-plugins
make
```


# Aircraft model / digital twin
Expand Down
2 changes: 1 addition & 1 deletion examples/gymfc_nf/envs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, max_sim_time = 30, state_fn = None):
# IMU noise is aircraft specific and thus can not be included as
# initial values for the registered environment. After the environment
# has been created the user can update this function.
self.sample_noise = None
self.sample_noise = lambda _: 0

def set_aircraft_model(self, model):
"""Set the aircraft's model.sdf
Expand Down
4 changes: 2 additions & 2 deletions examples/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
author='William Koch',
author_email='wfkoch [at] gmail [dot] com',
license='MIT',
# packages=find_packages(),
install_requires=['gymfc', 'gym', 'numpy'],
packages=find_packages(),
install_requires=['matplotlib', 'gym', 'numpy'],
)
10 changes: 8 additions & 2 deletions gymfc/envs/fc_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def load_config(self, aircraft_config, config_filepath = None):

# Priotiry of load, constructor -> environment variable -> default
current_dir = os.path.dirname(__file__)
default_config_path = os.path.join(current_dir, "../../gymfc.ini")
default_config_path = os.path.join(current_dir, "../gymfc.ini")
if config_filepath:
if not os.path.isfile(config_filepath):
message = "Error, provided configuration file at constructor but not found {}, aborting.".format(config_filepath)
Expand Down Expand Up @@ -208,7 +208,7 @@ def load_config(self, aircraft_config, config_filepath = None):
# Gazebo configuration
self.setup_file = os.path.expandvars(default["SetupFile"])
if not os.path.isfile(self.setup_file):
message = "Could not find Gazebo setup.sh file at '{}'. Typo?".format(self.setup_file)
message = "Could not find Gazebo setup.sh file at '{}'. Confirm SetupFile in gymfc/gymfc.ini is pointing to the correct location.".format(self.setup_file)
raise ConfigLoadException(message)
self.world = default["World"]
self.host = default["Hostname"]
Expand Down Expand Up @@ -474,6 +474,12 @@ def _start_sim(self):
container_env["GAZEBO_RESOURCE_PATH"] += os.pathsep + world_path
container_env["GAZEBO_PLUGIN_PATH"] += (os.pathsep + plugin_path + os.pathsep +
aircraft_plugin_dir)
# When installing via pip the FlightControllerPlugin plugin is unable
# to find the custom control and sensor messages unless the path is
# included in this variable. It may be due how the library files move
# after they are built. This behavior is not observed when installing
# with pip in edit/develop mode.
container_env["LD_LIBRARY_PATH"] += os.pathsep + plugin_path


print ("Gazebo Model Path =", container_env["GAZEBO_MODEL_PATH"])
Expand Down
2 changes: 1 addition & 1 deletion gymfc.ini → gymfc/gymfc.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# In most cases this should not be modified
[DEFAULT]

SetupFile = $HOME/local/share/gazebo/setup.sh
SetupFile = /usr/local/share/gazebo/setup.sh
World = attitude.world
Hostname = localhost

Expand Down
80 changes: 80 additions & 0 deletions install_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash
# Install the dependencies for GymFC on Ubuntu 18.04.
# Requires sudo

GAZEBO_MAJOR_VERSION=10
GAZEBO_VERSION=gazebo10_10.1.0
# Running sudo on this script will give $USER as root so get the currently logged in user instead
USERNAME=$(logname)
DART_VERSION=v6.7.0
ROS_DISTRO=dummy
# Compiling Gazebo can be very memory intensive, this variable passes additional flags to make for dart and gazebo.
# By default this sets the number of parallel jobs to 1. If you set this too high make will crash with out of memory errors.
# If you have sufficient memory, increase this value for a faster install.
MAKE_FLAGS=${MAKE_FLAGS:=-j1}

# Remove any other installations of Dart installed through debian packages
apt-get remove -y libdart*

# Install Dart dependencies
apt-get update && apt-get -y install \
build-essential \
cmake \
pkg-config \
git \
libeigen3-dev \
libassimp-dev \
libccd-dev \
libfcl-dev \
libboost-regex-dev \
libboost-system-dev

# Octomap is specified as an optional dependency but building is not linking without it, http://dartsim.github.io/install_dart_on_ubuntu.html
apt-get update && apt-get -y install \
liboctomap-dev

# Build Dart
git clone "https://github.com/dartsim/dart.git" /tmp/dart \
&& cd /tmp/dart && git checkout $DART_VERSION \
&& mkdir build && cd build \
&& cmake .. \
&& make $MAKE_FLAGS \
&& make install

# Install Gazebo from source following the instructions from here: http://gazebosim.org/tutorials?tut=install_from_source&cat=install

# Prepare Gazebo
apt-get -y remove '.*gazebo.*' '.*sdformat.*' '.*ignition-math.*' '.*ignition-msgs.*' '.*ignition-transport.*'

apt-get update && apt-get -y install \
lsb-release \
wget \
mercurial \
libboost-all-dev

sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list' \
&& wget http://packages.osrfoundation.org/gazebo.key -O - | apt-key add - && apt-get update


# Install Gazebo dependencies
wget https://raw.githubusercontent.com/ignition-tooling/release-tools/master/jenkins-scripts/lib/dependencies_archive.sh -O /tmp/dependencies.sh
. /tmp/dependencies.sh && echo ${BASE_DEPENDENCIES} ${GAZEBO_BASE_DEPENDENCIES} ${DART_DEPENDENCIES} | tr -d '\\' | xargs apt-get -y install


# Build Gazebo
hg clone https://bitbucket.org/osrf/gazebo /tmp/gazebo \
&& cd /tmp/gazebo \
&& hg up $GAZEBO_VERSION \
&& mkdir build && cd build \
&& cmake ../ \
&& make $MAKE_FLAGS \
&& make install

# /usr/local/lib is not on the load path by defalut so add it
echo '/usr/local/lib' | sudo tee /etc/ld.so.conf.d/gazebo.conf
ldconfig

# Install GymFC dependencies
apt-get update && apt-get install -y \
python3-pip \
python3
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def run(self):
license='MIT',
packages=find_packages(),
package_data={'gymfc': [
'gymfc.ini',
'envs/assets/gazebo/models/attitude_control_training_rig/*.config',
'envs/assets/gazebo/models/attitude_control_training_rig/*.sdf',
'envs/assets/gazebo/worlds/*.world',
Expand Down

0 comments on commit 1b5857f

Please sign in to comment.