Skip to content

Commit

Permalink
add task customization instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
Vittorio-Caggiano committed Mar 25, 2024
1 parent ea5921d commit df971d2
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions docs/source/tutorials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,83 @@ Load MyoReflex Baseline

To load and execute the MyoReflex controller with baseline parameters.
Run the MyoReflex tutorial `here <https://github.com/facebookresearch/myosuite/tree/main/docs/source/tutorials/4b_reflex>`__



Customizing Tasks
=================

In order to create a new customized task, there are two places where you need to act:

1. Set up a new environment class for the new task

2. Register the new task

Set up a new environment
+++++++++++++++++++++++++

Environment classes are developed according to the OpenAI Gym definition
and contain all the information specific for a task,
to interact with the environment, to observe it and to
act on it. In addition, each environment class contains
a reward function which converts the observation into a
number that establishes how good the observation is with
respect to the task objectives. In order to create a new
task, a new environment class needs to be generated eg.
reach2_v0.py (see for example how `reach_v0.py <https://github.com/MyoHub/myosuite/blob/main/myosuite/envs/myo/myobase/reach_v0.py>`__ is structured).
In this file, it is possible to specify the type of observation (eg. joint angles, velocities, forces), actions (e.g. muscle, motors), goal, and reward.


.. code-block:: python
from myosuite.envs.myo.base_v0 import BaseV0
import deprl

This comment has been minimized.

Copy link
@vikashplus

vikashplus Mar 25, 2024

Collaborator

Not sure if this is needed.

# Class extends Basev0
class NewReachEnvV0(BaseV0):
....
# defines the observation
def get_obs_dict(self, sim):
....
# defines the rewards
def get_reward_dict(self, obs_dict):
...
#reset condition that
def reset(self):
...
# step the simulation forward by acting on the environment
def step(self, a, **kwargs):

This comment has been minimized.

Copy link
@vikashplus

vikashplus Mar 25, 2024

Collaborator

Step is not needed. Its almost always better to use the step of the base class.

...
return observation, reward, task_terminated, environment_information
.. _setup_base_class:


Register the new environment
++++++++++++++++++++++++++++++

Once defined the task `reach2_v0.py`, the new environment needs to be registered to be
visible when importing `myosuite`. This is achieved by introducing the new environment in
the `__init__.py` (called when the library is imported) where the registration routine happens.
The registration of the new enviornment is obtained adding:

.. code-block:: python
register_env_with_variants(id='newReachTask-v0',

This comment has been minimized.

Copy link
@vikashplus

vikashplus Mar 25, 2024

Collaborator

Its better to directly call the register function.

entry_point='myosuite.envs.myo.myobase.reach_v0:NewReachEnvV0', # where to find the new Environment Class
max_episode_steps=200, # duration of the episode
kwargs={
'model_path': curr_dir+'/../assets/hand/myohand_pose.xml', # where the xml file of the environment is located
'target_reach_range': {'IFtip': ((0.1, 0.05, 0.20), (0.2, 0.05, 0.20)),}, # this is used in the setup to define the goal e.g. rando position of the team between 0.1 and 0.2 in the x coordinates
'normalize_act': True, # if to use normalized actions using a sigmoid function.
'frame_skip': 5, # collect a sample every 5 iteration step
}
)

This comment has been minimized.

Copy link
@vikashplus

vikashplus Mar 25, 2024

Collaborator

Add a link to the gymnasium website for references to the API

.. _register_new_environment:

0 comments on commit df971d2

Please sign in to comment.