-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add 'FetchReachCost' environment (#204)
This commit adds a modified version of the [FetchReach environment](https://robotics.farama.org/envs/fetch/reach/) found in the [gymnasium robotics](https://robotics.farama.org) package. In this modified version, the cost was replaced by a reward. This cost is the Euclidean distance between the achieved goal position and the desired goal:
- Loading branch information
Showing
25 changed files
with
326 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,2 @@ | ||
.. include:: ../../../../stable_gym/envs/robotics/fetch/fetch_reach_cost/README.md | ||
:parser: myst_parser.sphinx_ |
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,17 @@ | ||
"""Stable Gym gymnasium environments that are based on the environments found in the | ||
:gymnasium-robotics:`Gymnasium Robotics <>` package. | ||
.. note:: | ||
Some of these environments are based on the :class:`gym.GoalEnv` class. This means | ||
that the ``step`` method returns a dictionary with the following keys: | ||
- ``observation``: The observation of the environment. | ||
- ``achieved_goal``: The goal that was achieved during execution. | ||
- ``desired_goal``: The desired goal that we asked the agent to attempt to achieve. | ||
If you want to use these environments with RL algorithms that expect the ``step`` | ||
method to return a :obj:`np.ndarray` instead of a dictionary, you can use the | ||
:class:`gym.wrappers.FlattenObservation` wrapper to flatten the dictionary into a | ||
single :obj:`np.ndarray`. | ||
""" |
This file contains 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,5 @@ | ||
# FetchCost gymnasium environments | ||
|
||
The [stable-gym package](https://github.com/rickstaa/stable-gym) contains modified versions of the [fetch environments](https://robotics.farama.org/envs/fetch/) found in the [gymnasium robotics package](https://robotics.farama.org). These environments are different because they return a (positive) cost instead of a (negative) reward, making them compatible with stable RL algorithms. Please check the [gymnasium robotics](https://robotics.farama.org/env/fetch) package for more information about these environments. The [stable-gym package](https://github.com/rickstaa/stable-gym) currently contains the following FetchCost environments: | ||
|
||
* [FetchReachCost-v1](https://github.com/rickstaa/stable-gym/stable_gym/envs/robotics/fetch/fetch_reach_cost/README.md): Fetch has to move its end-effector to the desired goal position. |
This file contains 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,21 @@ | ||
"""Stable Gym gymnasium environments that are based on the | ||
:gymnasium-robotics:`Fetch environments <envs/fetch/>` in the | ||
:gymnasium-robotics:`Gymnasium Robotics <>` package. | ||
.. note:: | ||
These environments are based on the :class:`gym.GoalEnv` class. This means | ||
that the ``step`` method returns a dictionary with the following keys: | ||
- ``observation``: The observation of the environment. | ||
- ``achieved_goal``: The goal that was achieved during execution. | ||
- ``desired_goal``: The desired goal that we asked the agent to attempt to achieve. | ||
If you want to use these environments with RL algorithms that expect the ``step`` | ||
method to return a :obj:`np.ndarray` instead of a dictionary, you can use the | ||
:class:`gym.wrappers.FlattenObservation` wrapper to flatten the dictionary into a | ||
single :obj:`np.ndarray`. | ||
""" | ||
from stable_gym.envs.robotics.fetch.fetch_reach_cost.fetch_reach_cost import ( | ||
FetchReachCost, | ||
) |
This file contains 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,30 @@ | ||
# FetchReachCost gymnasium environment | ||
|
||
<div align="center"> | ||
<img src="https://github.com/rickstaa/stable-gym/assets/17570430/d395ee04-a0e2-4320-9bd2-f248c207bf06" alt="Fetch Reach Cost environment" width="200px"> | ||
</div> | ||
</br> | ||
|
||
An actuated 7-DOF [Fetch Mobile manipulator](https://fetchrobotics.com/). This environment corresponds to the [FetchReach-v2](https://robotics.farama.org/envs/fetch/reach/) environment included in the [gymnasium robotics package](https://robotics.farama.org/). It is different in the fact that: | ||
|
||
* The reward was replaced with a cost. This was done by taking the absolute value of the reward. | ||
|
||
The rest of the environment is the same as the original FetchReach environment. Below, the modified cost is described. For more information about the environment (e.g. observation space, action space, episode termination, etc.), please refer to the [gymnasium robotics library](https://robotics.farama.org/envs/fetch/reach/). | ||
|
||
## Cost function | ||
|
||
The cost function of this environment is designed in such a way that it tries to minimize the error between FetchReach's end-effector position and the desired goal position. It is defined as the Euclidean distance between the achieved goal position and the desired goal: | ||
|
||
$$ | ||
cost = -reward_{original} | ||
cost = \left \| p - p_{goal} \right \| | ||
$$ | ||
|
||
Where: | ||
|
||
* $p$ is the achieved goal position (i.e. the end-effector positio in Cartesian space). | ||
* $p_{goal}$ is the desired goal position in Cartesian space. | ||
|
||
## How to use | ||
|
||
This environment is part of the [Stable Gym package](https://github.com/rickstaa/stable-gym). It is therefore registered as the `stable_gym:FetchReachCost-v1` gymnasium environment when you import the Stable Gym package. If you want to use the environment in stand-alone mode, you can register it yourself. |
11 changes: 11 additions & 0 deletions
11
stable_gym/envs/robotics/fetch/fetch_reach_cost/__init__.py
This file contains 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,11 @@ | ||
"""Modified version of the FetchReach Mujoco environment in v1.2.2 of the | ||
`Gymnasium Robotics library <https://robotics.farama.org/envs/fetch/>`_. | ||
This modification was first described by `Han et al. 2020 <https://arxiv.org/abs/2004.14288>`_. | ||
In this modified version: | ||
- The reward was replaced with a cost. This was done by taking the absolute value of | ||
the reward. | ||
""" # noqa: E501 | ||
from stable_gym.envs.robotics.fetch.fetch_reach_cost.fetch_reach_cost import ( | ||
FetchReachCost, | ||
) |
Oops, something went wrong.