Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

End to end planning #223

Merged
merged 93 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
8220081
v0
halil93ibrahim Jun 4, 2021
e4088d7
v0
halil93ibrahim Jun 4, 2021
1f0ae52
Ros nodes and documentation.
halil93ibrahim Jun 7, 2021
19b18bf
fit method
halil93ibrahim Jun 10, 2021
328b757
cleanup
halil93ibrahim Jun 10, 2021
fc65160
test for eval and infer
halil93ibrahim Jul 8, 2021
760cf9c
Merge branch 'master' into end-to-end-planning
halil93ibrahim Oct 8, 2021
ebc8619
env updated
halil93ibrahim Nov 29, 2021
a193ea3
env updated - tests passed
halil93ibrahim Dec 2, 2021
26cfc17
Merge branch 'master' into end-to-end-planning
halil93ibrahim Dec 8, 2021
95bbda1
Merge branch 'master' into end-to-end-planning
halil93ibrahim Dec 9, 2021
98783a8
pep8 - cleanup
halil93ibrahim Dec 12, 2021
6e7ee6b
Merge branch 'end-to-end-planning' of https://github.com/tasostefas/o…
halil93ibrahim Dec 12, 2021
ee919c8
Merge branch 'master' into end-to-end-planning
halil93ibrahim Dec 12, 2021
8f97914
Merge branch 'end-to-end-planning' of https://github.com/tasostefas/o…
halil93ibrahim Dec 12, 2021
df9ed8d
Merge branch 'master' into end-to-end-planning
ad-daniel Dec 13, 2021
c60d4cd
Merge branch 'master' into end-to-end-planning
ad-daniel Dec 13, 2021
e4c9173
pep8 - cleanup
halil93ibrahim Dec 20, 2021
a8e135f
Merge branch 'master' into end-to-end-planning
halil93ibrahim Dec 20, 2021
39e3b88
pep8
halil93ibrahim Dec 20, 2021
7d8605a
licenses fixed
halil93ibrahim Dec 20, 2021
122287d
clang
halil93ibrahim Dec 20, 2021
2433f8b
test_sources
halil93ibrahim Dec 20, 2021
b88f1f3
dep - test only this tool
halil93ibrahim Dec 21, 2021
dd35685
dep - test only this tool
halil93ibrahim Dec 21, 2021
2c97b46
test only this tool
halil93ibrahim Dec 21, 2021
caf220e
test only this tool
halil93ibrahim Dec 21, 2021
e89b3ec
test only this tool
halil93ibrahim Dec 21, 2021
b9d2644
test only this tool
halil93ibrahim Dec 21, 2021
18e2dda
test python 3.6
halil93ibrahim Dec 22, 2021
fa1b5f3
test python 3.6
halil93ibrahim Dec 22, 2021
6209337
test python 3.6
halil93ibrahim Dec 22, 2021
e9848b2
test python 3.8
halil93ibrahim Dec 24, 2021
2a5af78
test python 3.8
halil93ibrahim Dec 24, 2021
cd95864
test python 3.8
halil93ibrahim Dec 24, 2021
44d2764
test python 3.8
halil93ibrahim Dec 24, 2021
687f210
test python 3.8
halil93ibrahim Dec 24, 2021
10ca530
test python 3.8
halil93ibrahim Dec 24, 2021
b3da43b
Merge branch 'master' into end-to-end-planning
halil93ibrahim Dec 24, 2021
2727d9b
test python 3.8
halil93ibrahim Dec 25, 2021
064f9c2
test python 3.8
halil93ibrahim Dec 25, 2021
95d6072
test - exclude control/mm
halil93ibrahim Dec 25, 2021
3b079b8
test all
halil93ibrahim Dec 26, 2021
c9e6254
clean up
halil93ibrahim Dec 27, 2021
96011ed
clean up
halil93ibrahim Dec 27, 2021
f1babcc
test
ad-daniel Dec 27, 2021
fb7c764
undo
ad-daniel Dec 27, 2021
d4edea3
Merge branch 'master' into end-to-end-planning
halil93ibrahim Dec 27, 2021
dcf4b7f
Merge branch 'master' into end-to-end-planning
ad-daniel Jan 3, 2022
f954091
install webots
ad-daniel Jan 3, 2022
640799b
Merge branch 'master' into end-to-end-planning
ad-daniel Jan 4, 2022
bc0c309
Merge branch 'develop' into end-to-end-planning
halil93ibrahim Feb 13, 2022
eede5e2
Update e2e_planning_learner.py
halil93ibrahim Mar 1, 2022
214964e
Update download_ardupilot_files.py
halil93ibrahim Mar 1, 2022
1dd3090
Update range_image.py
halil93ibrahim Mar 1, 2022
3e61f19
Update agi_env.py
halil93ibrahim Mar 1, 2022
6c543b5
Update children_robot.cpp
halil93ibrahim Mar 1, 2022
350e3de
Update take_off.cpp
halil93ibrahim Mar 1, 2022
37ff3b0
gym version issue with save and load
iliiliiliili Mar 1, 2022
2e94c24
gym version
halil93ibrahim Mar 3, 2022
f27efa7
Merge branch 'develop' into end-to-end-planning
ad-daniel Mar 3, 2022
39984ee
Merge branch 'develop' into end-to-end-planning
ad-daniel Mar 3, 2022
5c20ca5
clean up test licence skipped directory
halil93ibrahim Mar 8, 2022
fd7b632
Merge branch 'develop' into end-to-end-planning
halil93ibrahim Mar 8, 2022
345f8cf
gym version issue
halil93ibrahim Mar 8, 2022
2ec0775
gym version 0.19
halil93ibrahim Mar 8, 2022
c6a1dd6
stable baselines3 version 1.3
halil93ibrahim Mar 8, 2022
6de18f0
gym ver 0.20 sb3 ver 1.1
halil93ibrahim Mar 9, 2022
44dbec2
docs updated
halil93ibrahim Mar 10, 2022
7471fd2
docs updated
halil93ibrahim Mar 11, 2022
30bf80c
docs updated
halil93ibrahim Mar 11, 2022
879c8a6
fix
halil93ibrahim Mar 11, 2022
8cd84e6
Merge branch 'develop' into end-to-end-planning
halil93ibrahim Mar 11, 2022
353b152
Update .github/workflows/tests_suite.yml
halil93ibrahim Mar 14, 2022
065a170
Update .github/workflows/tests_suite_develop.yml
halil93ibrahim Mar 14, 2022
dffaff7
Update docs/reference/end_to_end_planning.md
halil93ibrahim Mar 14, 2022
ec9c0df
update tests_suite.yml and tests_suite_develop.yml
halil93ibrahim Mar 14, 2022
56f5083
Merge branch 'end-to-end-planning' of https://github.com/tasostefas/o…
halil93ibrahim Mar 14, 2022
1e5129f
added infer to docs
halil93ibrahim Mar 14, 2022
0c3ff5e
requested changes
halil93ibrahim Mar 14, 2022
2d15151
fix pep8
halil93ibrahim Mar 14, 2022
bc9c98b
init files
halil93ibrahim Mar 14, 2022
8b2400a
preformance evaluation and init files under tests & test/sources
halil93ibrahim Mar 16, 2022
4afedfc
undo
ad-daniel Mar 21, 2022
9da581d
Merge branch 'develop' into end-to-end-planning
ad-daniel Mar 22, 2022
7f20428
test
ad-daniel Mar 22, 2022
fff8fcf
Revert "test"
ad-daniel Mar 22, 2022
52b8545
Update CHANGELOG.md
halil93ibrahim Mar 25, 2022
8b25721
Update CHANGELOG.md
halil93ibrahim Mar 25, 2022
509b643
Update CHANGELOG.md
halil93ibrahim Mar 25, 2022
cc1fbac
added TEST_DEVICE in tests
halil93ibrahim Mar 25, 2022
e6a6e97
eval/fit return dictionary
halil93ibrahim Mar 30, 2022
5529aec
Merge branch 'develop' into end-to-end-planning
passalis Mar 30, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/tests_suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ jobs:
- simulation/human_model_generation
- perception/facial_expression_recognition
- control/single_demo_grasp
- planning/end_to_end_planning
halil93ibrahim marked this conversation as resolved.
Show resolved Hide resolved
# - perception/object_tracking_3d
include:
- os: ubuntu-20.04
Expand Down Expand Up @@ -328,6 +329,7 @@ jobs:
- control/mobile_manipulation
- simulation/human_model_generation
- control/single_demo_grasp
- planning/end_to_end_planning
# - perception/object_tracking_3d
runs-on: ubuntu-20.04
steps:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/tests_suite_develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ jobs:
- simulation/human_model_generation
- perception/facial_expression_recognition
- control/single_demo_grasp
- planning/end_to_end_planning
halil93ibrahim marked this conversation as resolved.
Show resolved Hide resolved
# - perception/object_tracking_3d
include:
- os: ubuntu-20.04
Expand Down Expand Up @@ -330,6 +331,7 @@ jobs:
- control/mobile_manipulation
- simulation/human_model_generation
- control/single_demo_grasp
- planning/end_to_end_planning
# - perception/object_tracking_3d
runs-on: ubuntu-20.04
steps:
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Released on XX, XXth, 2022.

- New Features:
- None.
- Added end-to-end planning tool ([#223](https://github.com/opendr-eu/opendr/pull/223)).
- Enhancements:
- Added support for modular pip packages allowing tools to be installed separately ([#201](https://github.com/opendr-eu/opendr/pull/201)).
- Simplified the installation process for pip by including the appropriate post-installation scripts ([#201](https://github.com/opendr-eu/opendr/pull/201)).
Expand Down
185 changes: 185 additions & 0 deletions docs/reference/end-to-end-planning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
# end_to_end_planning module

The *end_to_end_planning* module contains the *EndToEndPlanningRLLearner* class, which inherits from the abstract
class *LearnerRL*.

### Class EndToEndPlanningRLLearner
Bases: `engine.learners.LearnerRL`

The *EndToEndPlanningRLLearner* is an agent that can be used to train quadrotor robots equipped with a depth sensor to
follow a provided trajectory while avoiding obstacles.

The [EndToEndPlanningRLLearner](/src/opendr/planning/end_to_end_planning/e2e_planning_learner.py) class has the
following public methods:

#### `EndToEndPlanningRLLearner` constructor

Constructor parameters:

- **env**: *gym.Env*\
Reinforcment learning environment to train or evaluate the agent on.
- **lr**: *float, default=3e-4*\
Specifies the initial learning rate to be used during training.
- **n_steps**: *int, default=1024*\
Specifies the number of steps to run for environment per update.
- **iters**: *int, default=5e4*\
Specifies the number of steps the training should run for.
- **batch_size**: *int, default=64*\
Specifies the batch size during training.
- **checkpoint_after_iter**: *int, default=500*\
Specifies per how many training steps a checkpoint should be saved.
- **temp_path**: *str, default=''*\
Specifies a path where the algorithm stores log files and saves checkpoints.
- **device**: *{'cpu', 'cuda'}, default='cuda'*\
Specifies the device to be used.

#### `EndToEndPlanningRLLearner.fit`
```python
EndToEndPlanningRLLearner.fit(self, env, logging_path, silent, verbose)
```

Train the agent on the environment.

Parameters:

- **env**: *gym.Env, default=None*\
If specified use this env to train.
- **logging_path**: *str, default=''*\
Path for logging and checkpointing.
- **silent**: *bool, default=False*\
Disable verbosity.
- **verbose**: *bool, default=True*\
Enable verbosity.


#### `EndToEndPlanningRLLearner.eval`
```python
EndToEndPlanningRLLearner.eval(self, env)
```
Evaluate the agent on the specified environment.

Parameters:

- **env**: *gym.Env, default=None*\
Environment to evaluate on.


#### `EndToEndPlanningRLLearner.save`
```python
EndToEndPlanningRLLearner.save(self, path)
```
Saves the model in the path provided.

Parameters:

- **path**: *str*\
Path to save the model, including the filename.


#### `EndToEndPlanningRLLearner.load`
```python
EndToEndPlanningRLLearner.load(self, path)
```
Loads a model from the path provided.

Parameters:

- **path**: *str*\
Path of the model to be loaded.


#### `EndToEndPlanningRLLearner.infer`
```python
EndToEndPlanningRLLearner.infer(self, batch, deterministic)
```
Performs inference on a single observation or a list of observations.

Parameters:

- **batch**: *dict or list of dict, default=None*\
Single observation or list of observations.
- **deterministic**: *bool, default=True*\
Use deterministic actions from the policy

### Simulation environment setup

The environment includes an Ardupilot controlled quadrotor in Webots simulation.
For the installation of Ardupilot instructions are available [here](https://github.com/ArduPilot/ardupilot).

The required files to complete Ardupilot setup can be downloaded by running [`download_ardupilot_files.py`](src/opendr/planning/end_to_end_planning/download_ardupilot_files.py) script.
The downloaded files (zipped as `ardupilot.zip`) should be replaced under the installation of Ardupilot.
In order to run Ardupilot in Webots 2021a, controller codes should be replaced. (For older versions of Webots, these files can be skipped.)
The world file for the environment is provided under `/ardupilot/libraries/SITL/examples/webots/worlds/` for training and testing.

Install `mavros` package for ROS communication with Ardupilot.
Instructions are available [here](https://github.com/mavlink/mavros/blob/master/mavros/README.md#installation).
Source installation is recomended.

### Running the environment

The following steps should be executed to have a ROS communication between Gym environment and simulation.
- Start the Webots and open the provided world file.
The simulation time should stop at first time step and wait for Ardupilot software to run.
- Run following script from Ardupilot directory: `./libraries/SITL/examples/Webots/dronePlus.sh` which starts software in the loop execution of the Ardupilot software.
- Run `roscore`.
- Run `roslaunch mavros apm.launch` which creates ROS communication for Ardupilot.
- Run following ROS nodes in `src/opendr/planning/end_to_end_planning/src`:
- `children_robot` which activates required sensors on quadrotor and creates ROS communication for them.
- `take_off` which takes off the quadrotor.
- `range_image` which converts the depth image into array format to be input for the learner.

After these steps the [AgiEnv](src/opendr/planning/end_to_end_planning/envs/agi_env.py) gym environment can send action comments to the simulated drone and receive depth image and pose information from simulation.

### Examples

Training in Webots environment:

```python
from opendr.planning.end_to_end_planning import EndToEndPlanningRLLearner, AgiEnv

env = AgiEnv()
learner = EndToEndPlanningRLLearner(env, n_steps=1024)
learner.fit(logging_path='./end_to_end_planning_tmp')
```


Running a pretrained model:

```python
from opendr.planning.end_to_end_planning import EndToEndPlanningRLLearner, AgiEnv

env = AgiEnv()
learner = EndToEndPlanningRLLearner(env)
learner.load('{$OPENDR_HOME}/src/opendr/planning/end_to_end_planning/pretrained_model/saved_model.zip')
obs = env.reset()
sum_of_rew = 0
number_of_timesteps = 20
for i in range(number_of_timesteps):
action, _states = learner.infer(obs, deterministic=True)
obs, rewards, dones, info = env.step(action)
sum_of_rew += rewards
if dones:
obs = env.reset()
print("Reward collected is:", sum_of_rew)
```

### Performance Evaluation

TABLE 1: Speed (FPS) and energy consumption for inference on various platforms.

| | TX2 | Xavier | RTX 2080 Ti |
| --------------- | ----- | ------ | ----------- |
| FPS Evaluation | 153.5 | 201.6 | 973.6 |
| Energy (Joules) | 0.12 | 0.051 | \- |

TABLE 2: Platform compatibility evaluation.

| Platform | Test results |
| -------------------------------------------- | ------------ |
| x86 - Ubuntu 20.04 (bare installation - CPU) | Pass |
| x86 - Ubuntu 20.04 (bare installation - GPU) | Pass |
| x86 - Ubuntu 20.04 (pip installation) | Pass |
| x86 - Ubuntu 20.04 (CPU docker) | Pass |
| x86 - Ubuntu 20.04 (GPU docker) | Pass |
| NVIDIA Jetson TX2 | Pass |
| NVIDIA Jetson Xavier AGX | Pass |
33 changes: 33 additions & 0 deletions src/opendr/planning/end_to_end_planning/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# End-to-end Planning

This folder contains the OpenDR Learner class for end-to-end planning tasks.
This method uses reinforcement learning to train an agent that is able to generate local motion plans for a quadrotor UAV equipped with a depth camera.

### Simulation environment setup

The environment includes an Ardupilot controlled quadrotor in Webots simulation.
For the installation of Ardupilot instructions are available [here](https://github.com/ArduPilot/ardupilot).

The required files to complete Ardupilot setup can be downloaded by running [`download_ardupilot_files.py`](src/opendr/planning/end_to_end_planning/download_ardupilot_files.py) script.
The downloaded files (zipped as `ardupilot.zip`) should be replaced under the installation of Ardupilot.
In order to run Ardupilot in Webots 2021a, controller codes should be replaced. (For older versions of Webots, these files can be skipped.)
The world file for the environment is provided under `/ardupilot/libraries/SITL/examples/webots/worlds/` for training and testing.

Install `mavros` package for ROS communication with Ardupilot.
Instructions are available [here](https://github.com/mavlink/mavros/blob/master/mavros/README.md#installation).
Source installation is recomended.

### Running the environment

The following steps should be executed to have a ROS communication between Gym environment and simulation.
- Start the Webots and open the provided world file.
The simulation time should stop at first time step and wait for Ardupilot software to run.
- Run following script from Ardupilot directory: `./libraries/SITL/examples/Webots/dronePlus.sh` which starts software in the loop execution of the Ardupilot software.
- Run `roscore`.
- Run `roslaunch mavros apm.launch` which creates ROS communication for Ardupilot.
- Run following ROS nodes in `src/opendr/planning/end_to_end_planning/src`:
- `children_robot` which activates required sensors on quadrotor and creates ROS communication for them.
- `take_off` which takes off the quadrotor.
- `range_image` which converts the depth image into array format to be input for the learner.

After these steps the [AgiEnv](src/opendr/planning/end_to_end_planning/envs/agi_env.py) gym environment can send action comments to the simulated drone and receive depth image and pose information from simulation.
4 changes: 4 additions & 0 deletions src/opendr/planning/end_to_end_planning/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from opendr.planning.end_to_end_planning.e2e_planning_learner import EndToEndPlanningRLLearner
from opendr.planning.end_to_end_planning.envs.agi_env import AgiEnv

__all__ = ['EndToEndPlanningRLLearner', 'AgiEnv']
16 changes: 16 additions & 0 deletions src/opendr/planning/end_to_end_planning/dependencies.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[compilation]
linux=libeigen3-dev
python=vcstool
rosdep
rospkg
catkin_pkg
catkin_tools
roslibpy
empy
gym==0.20.0
stable-baselines3==1.1.0
[runtime]
# 'python' key expects a value using the Python requirements file format
# https://pip.pypa.io/en/stable/reference/pip_install/#requirements-file-format
python=stable-baselines3
linux=ros-noetic-webots-ros
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2020-2022 OpenDR European Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from urllib.request import urlretrieve
from opendr.engine.constants import OPENDR_SERVER_URL

url = OPENDR_SERVER_URL + "planning/end_to_end_planning/ardupilot.zip"
file_destination = "./ardupilot.zip"
urlretrieve(url=url, filename=file_destination)
Loading