-
Notifications
You must be signed in to change notification settings - Fork 342
Adds an initial StableBaselines3 RL environment as an example #2667
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
Merged
Merged
Changes from 31 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
2a658f9
Adds support for Reset in test fixture
arjo129 053152f
Add support for simulation reset via a publicly callable API
arjo129 ff468b7
Style
arjo129 e0ee0dd
Style
arjo129 047be5b
Style
arjo129 76adc26
Typo
arjo129 83b30c2
Adds an initial StableBaselines3 RL environment as an example
arjo129 c3eea00
Fixed readme instructions
arjo129 9a2b742
Style
arjo129 da33f11
Got the gui working. Time for gradient descent by grad student
arjo129 3e83828
Address feedback
arjo129 35eca3e
Merge remote-tracking branch 'origin/main' into arjo/feat/server_rese…
arjo129 15fa867
Add support for individual resets
arjo129 ed502ee
Merge branch 'main' into arjo/feat/server_reset_public_api
arjo129 120c1ec
Merge branch 'arjo/feat/server_reset_public_api' into arjo/examples/r…
arjo129 16d4407
Style
arjo129 6c8131c
Bind installation directories and install
arjo129 5117071
Missed the file in the last commit
arjo129 e602467
Merge remote-tracking branch 'refs/remotes/origin/arjo/examples/rl_ex…
arjo129 46e3ca8
style
arjo129 6799df2
Style
arjo129 ad1ace4
Merge branch 'arjo/feat/server_reset_public_api' into arjo/examples/r…
arjo129 856f316
Style
arjo129 f8ddbf6
Enable GUI rollout
arjo129 648fa11
Merge branch 'main' into arjo/examples/rl_example
j-rivero 5318663
Merge branch 'main' into arjo/examples/rl_example
arjo129 9cf5b69
Merge branch 'main' into arjo/examples/rl_example
iche033 e540136
Address feedback and more thorough Docs
arjo129 3343fe0
Fix SDF file
arjo129 6c083c6
Fix style
arjo129 5b8af2a
Merge branch 'main' into arjo/examples/rl_example
iche033 748d979
Merge branch 'main' into arjo/examples/rl_example
arjo129 bb2a515
Fix compilation errors
arjo129 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
examples/scripts/reinforcement_learning/simple_cart_pole/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Example for Reinforcement Learning (RL) With Gazebo | ||
|
||
This demo world shows you an example of how you can use SDFormat, Stable Baselines 3 and Gazebo to perform RL with python. | ||
We start with a very simple cart-pole world. This world is defined in our sdf file `cart_pole.sdf`. It is analogous to the cart-pole world in gymnasium. | ||
|
||
## Create a VENV | ||
|
||
First create a virtual environment using python, | ||
``` | ||
python3 -m venv venv | ||
``` | ||
Let's activate it and install stablebaselines3 and pytorch. | ||
``` | ||
. venv/bin/activate | ||
``` | ||
|
||
Lets install our dependencies | ||
``` | ||
pip install stable-baselines3[extra] | ||
``` | ||
For visuallization to work you will also need to: | ||
``` | ||
pip uninstall opencv-python | ||
pip install opencv-python-headless | ||
``` | ||
This is because `opencv-python` brings in Qt5 by default. | ||
|
||
In the same terminal you should add your gazebo python install directory to the `PYTHONPATH`. | ||
If you built gazebo from source in the current working directory this would be: | ||
``` | ||
# cd to the colcon workspace where you built gazebo | ||
cd <path_to_colcon_workspace> | ||
export PYTHONPATH=$PYTHONPATH:`pwd`/install/lib/python | ||
. install/setup.bash | ||
``` | ||
|
||
You will also need to set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION to python due to version | ||
mismatches. | ||
``` | ||
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python | ||
``` | ||
|
||
|
||
## Exploring the environment | ||
|
||
You can see the environment by using `gz sim cart_pole.sdf`. | ||
|
||
## Perform RL | ||
|
||
To perform RL take a look at `cart_pole_env.py`. We simply subclass `gym.Env` and | ||
create a new gazebo system. Close any instance of gazebo you may be running. | ||
To run the script, in your terminal with the venv sourced run: | ||
``` | ||
python3 cart_pole_env.py | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.