Skip to content

Commit e439e96

Browse files
authored
Merge pull request #183 from ARISE-Initiative/update_docs
Update robosuite documentations
2 parents a44e7d8 + d83a4f1 commit e439e96

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1268
-455
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
-------
88
## Latest Updates
9+
[02/17/2021] **v1.2.0**: Added observable sensor models :eyes: and dynamics randomization :game_die:
10+
911
[12/17/2020] **v1.1.0**: Refactored infrastructure and standardized model classes for much easier environment prototyping :wrench:
1012

1113
-------

docs/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ BUILDDIR = _build
1212
help:
1313
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
1414

15+
apidoc:
16+
@sphinx-apidoc -T --force ../robosuite -o source
17+
1518
.PHONY: help Makefile
1619

1720
# Catch-all target: route all unknown targets to Sphinx using the new

docs/algorithms/demonstrations.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Collecting Human Demonstrations
44

5-
We provide teleoperation utilities that allow users to control the robots with input devices, such as the keyboard and the [SpaceMouse](https://www.3dconnexion.com/spacemouse_compact/en/). Such functionality allows us to collect a dataset of human demonstrations for learning. We provide an example script to illustrate how to collect demonstrations. Our [collect_human_demonstrations](robosuite/scripts/collect_human_demonstrations.py) script takes the following arguments:
5+
We provide teleoperation utilities that allow users to control the robots with input devices, such as the keyboard and the [SpaceMouse](https://www.3dconnexion.com/spacemouse_compact/en/). Such functionality allows us to collect a dataset of human demonstrations for learning. We provide an example script to illustrate how to collect demonstrations. Our [collect_human_demonstrations](https://github.com/ARISE-Initiative/robosuite/blob/master/robosuite/scripts/collect_human_demonstrations.py) script takes the following arguments:
66

77
- `directory:` path to a folder for where to store the pickle file of collected demonstrations
88
- `environment:` name of the environment you would like to collect the demonstrations for
@@ -38,14 +38,14 @@ Note that the rendering window must be active for these commands to work.
3838

3939
## Replaying Human Demonstrations
4040

41-
We have included an example script that illustrates how demonstrations can be loaded and played back. Our [playback_demonstrations_from_hdf5](robosuite/scripts/playback_demonstrations_from_hdf5.py) script selects demonstration episodes at random from a demonstration pickle file and replays them.
41+
We have included an example script that illustrates how demonstrations can be loaded and played back. Our [playback_demonstrations_from_hdf5](https://github.com/ARISE-Initiative/robosuite/blob/master/robosuite/scripts/playback_demonstrations_from_hdf5.py) script selects demonstration episodes at random from a demonstration pickle file and replays them.
4242

4343

4444
## Existing Datasets
4545

4646
We have included some sample demonstrations for each task at `models/assets/demonstrations`.
4747

48-
Our twin project [RoboTurk](http://roboturk.stanford.edu) has also collected pilot datasets of more than a thousand demonstrations for two tasks in our suite via crowdsourcing. You can find detailed information about the RoboTurk datasets [here](docs/demonstrations.md#roboturk-dataset).
48+
Our twin project [RoboTurk](http://roboturk.stanford.edu) has also collected pilot datasets of more than a thousand demonstrations for two tasks in our suite via crowdsourcing. You can find detailed information about the RoboTurk datasets [here](roboturk).
4949

5050

5151
## Structure of collected demonstrations
@@ -81,4 +81,9 @@ The reason for storing mujoco states instead of raw observations is to make it e
8181

8282
## Using Demonstrations for Learning
8383

84-
[Several](https://arxiv.org/abs/1802.09564) [prior](https://arxiv.org/abs/1807.06919) [works](https://arxiv.org/abs/1804.02717) have demonstrated the effectiveness of altering the start state distribution of training episodes for learning RL policies. We provide a generic utility for setting various types of learning curriculums which dictate how to sample from demonstration episodes when doing an environment reset. For more information see the `DemoSamplerWrapper` class. We have provided an example of how to use this wrapper along with a demonstration pickle file in the [demo_learning_curriculum](robosuite/scripts/demo_learning_curriculum.py) script.
84+
[Several](https://arxiv.org/abs/1802.09564) [prior](https://arxiv.org/abs/1807.06919) [works](https://arxiv.org/abs/1804.02717) have demonstrated the effectiveness of altering the start state distribution of training episodes for learning RL policies. We provide a generic utility for setting various types of learning curriculums which dictate how to sample from demonstration episodes when doing an environment reset. For more information see the `DemoSamplerWrapper` class.
85+
86+
## Warnings
87+
We have verified that deterministic action playback works specifically when playing back demonstrations on the *same machine* that the demonstrations were originally collected upon. However, this means that deterministic action playback is NOT guaranteed (in fact, very unlikely) to work across platforms or even across different machines using the same OS.
88+
89+
While action playback trajectories are quite similar even if not completely identical to the original collected state trajectories, they do tend to drift over time, and should not be relied upon to accurately replicate demonstrations. Instead, we recommend directly setting states to reproduce the collected trajectories, as shown in [playback_demonstrations_from_hdf5](https://github.com/ARISE-Initiative/robosuite/blob/master/robosuite/scripts/playback_demonstrations_from_hdf5.py).

docs/algorithms/roboturk.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
[RoboTurk](https://roboturk.stanford.edu/) is a crowdsourcing platform developed in order to enabled collecting large-scale manipulation datasets. Below, we describe RoboTurk datasets that are compatible with robosuite.
44

5-
## Updated Datasets compatible with v1.0
5+
## Updated Datasets compatible with v1.0+
66

7-
We are currently in the process of reformatting the demonstrations. These datasets will be made available soon.
7+
We are currently in the process of organizing a standardized dataset for our benchmarking tasks, which will be made available soon and compatible with v1.2.0+. In the meantime, we have provided a [small-scale dataset](https://drive.google.com/drive/folders/1LLkuFnRdqQ6xn1cYzkbJUs_DreaAvN7i?usp=sharing) of expert demonstrations on two of our tasks.
88

99
## Original Datasets compatible with v0.3
1010

docs/algorithms/sim2real.md

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# Sim-to-Real Transfer
2+
This page covers the randomization techniques to narrow the reality gap of our robotics simulation. These techniques, which concerns about [visual observations](#visuals), [system dynamics](#dynamics), and [sensors](#sensors), are employed to improve the efficacy of transferring our simulation-trained models to the real world.
3+
4+
5+
## Visuals
6+
7+
It is well shown that randomizing the visuals in simulation can play an important role in sim2real applications. **robosuite** provides various `Modder` classes to control different aspects of the visual environment. This includes:
8+
9+
- `CameraModder`: Modder for controlling camera parameters, including FOV and pose
10+
- `TextureModder`: Modder for controlling visual objects' appearances, including texture and material properties
11+
- `LightingModder`: Modder for controlling lighting parameters, including light source properties and pose
12+
13+
Each of these Modders can be used by the user to directly override default simulation settings, or to randomize their respective properties mid-sim. We provide [demo_domain_randomization.py](../demos.html#domain-randomization) to showcase all of these modders being applied to randomize an environment during every sim step.
14+
15+
16+
## Dynamics
17+
18+
In order to achieve reasonable runtime speeds, many physics simulation platforms often must simplify the underlying physics model. Mujoco is no different, and as a result, many parameters such as friction, damping, and contact constraints do not fully capture real-world dynamics.
19+
20+
To better compensate for this, **robosuite** provides the `DynamicsModder` class, which can control individual dynamics parameters for each model within an environment. Theses parameters are sorted by element group, and briefly described below (for more information, please see [Mujoco XML Reference](http://www.mujoco.org/book/XMLreference.html)):
21+
22+
#### Opt (Global) Parameters
23+
- `density`: Density of the medium (i.e.: air)
24+
- `viscosity`: Viscosity of the medium (i.e.: air)
25+
26+
#### Body Parameters
27+
- `position`: (x, y, z) Position of the body relative to its parent body
28+
- `quaternion`: (qw, qx, qy, qz) Quaternion of the body relative to its parent body
29+
- `inertia`: (ixx, iyy, izz) diagonal components of the inertia matrix associated with this body
30+
- `mass`: mass of the body
31+
32+
#### Geom Parameters
33+
- `friction`: (sliding, torsional, rolling) friction values for this geom
34+
- `solref`: (timeconst, dampratio) contact solver values for this geom
35+
- `solimp`: (dmin, dmax, width, midpoint, power) contact solver impedance values for this geom
36+
37+
#### Joint parameters
38+
- `stiffness`: Stiffness for this joint
39+
- `frictionloss`: Friction loss associated with this joint
40+
- `damping`: Damping value for this joint
41+
- `armature`: Gear inertia for this joint
42+
43+
This `DynamicsModder` follows the same basic API as the other `Modder` classes, and allows per-parameter and per-group randomization enabling. Apart from randomization, this modder can also be instantiated to selectively modify values at runtime. A brief example is given below:
44+
45+
```python
46+
import robosuite as suite
47+
from robosuite.utils.mjmod import DynamicsModder
48+
import numpy as np
49+
50+
# Create environment and modder
51+
env = suite.make("Lift", robots="Panda")
52+
modder = DynamicsModder(sim=env.sim, random_state=np.random.RandomState(5))
53+
54+
# Define function for easy printing
55+
cube_body_id = env.sim.model.body_name2id(env.cube.root_body)
56+
cube_geom_ids = [env.sim.model.geom_name2id(geom) for geom in env.cube.contact_geoms]
57+
58+
def print_params():
59+
print(f"cube mass: {env.sim.model.body_mass[cube_body_id]}")
60+
print(f"cube frictions: {env.sim.model.geom_friction[cube_geom_ids]}")
61+
print()
62+
63+
# Print out initial parameter values
64+
print("INITIAL VALUES")
65+
print_params()
66+
67+
# Modify the cube's properties
68+
modder.mod(env.cube.root_body, "mass", 5.0) # make the cube really heavy
69+
for geom_name in env.cube.contact_geoms:
70+
modder.mod(geom_name, "friction", [2.0, 0.2, 0.04]) # greatly increase the friction
71+
modder.update() # make sure the changes propagate in sim
72+
73+
# Print out modified parameter values
74+
print("MODIFIED VALUES")
75+
print_params()
76+
77+
# We can also restore defaults (original values) at any time
78+
modder.restore_defaults()
79+
80+
# Print out restored initial parameter values
81+
print("RESTORED VALUES")
82+
print_params()
83+
```
84+
85+
Running [demo_domain_randomization.py](../demos.html#domain-randomization) is another method for demo'ing (albeit an extreme example of) this functionality.
86+
87+
Note that the modder already has some sanity checks in place to prevent presumably undesired / non-sensical behavior, such as adding damping / frictionloss to a free joint or setting a non-zero stiffness value to a joint that is normally non-stiff to begin with.
88+
89+
90+
## Sensors
91+
92+
By default, Mujoco sensors are deterministic and delay-free, which is often an unrealistic assumption to make in the real world. To better close this domain gap, **robosuite** provides a realistic, customizable interface via the [Observable](../source/robosuite.utils.html#module-robosuite.utils.observables) class API. Observables model realistic sensor sampling, in which ground truth data is sampled (`sensor`), passed through a corrupting function (`corrupter`), and then finally passed through a filtering function (`filter`). Moreover, each observable has its own `sampling_rate` and `delayer` function which simulates sensor delay. While default values are used to instantiate each observable during environment creation, each of these components can be modified by the user at runtime using `env.modify_observable(...)` . Moreover, each observable is assigned a modality, and are grouped together in the returned observation dictionary during the `env.step()` call. For example, if an environment consists of camera observations and a single robot's proprioceptive observations, the observation dict structure might look as follows:
93+
94+
```python
95+
{
96+
"frontview_image": np.array(...), # this has modality "image"
97+
"frontview_depth": np.array(...), # this has modality "image"
98+
"robot0_joint_pos": np.array(...), # this has modality "robot0_proprio"
99+
"robot0_gripper_pos": np.array(...), # this has modality "robot0_proprio"
100+
"image-state": np.array(...), # this is a concatenation of all image observations
101+
"robot0_proprio-state": np.array(...), # this is a concatenation of all robot0_proprio observations
102+
}
103+
```
104+
105+
Note that for memory efficiency the `image-state` is not returned by default (this can be toggled in `robosuite/utils/macros.py`).
106+
107+
We showcase how the `Observable` functionality can be used to model sensor corruption and delay via [demo_sensor_corruption.py](../demos.html#sensor-realism). We also highlight that each of the `sensor`, `corrupter`, and `filter` functions can be arbitrarily specified to suit the end-user's usage. For example, a common use case for these observables is to keep track of sampled values from a sensor operating at a higher frequency than the environment step (control) frequency. In this case, the `filter` function can be leveraged to keep track of the real-time sensor values as they're being sampled. We provide a minimal script showcasing this ability below:
108+
109+
```python
110+
import robosuite as suite
111+
import numpy as np
112+
from robosuite.utils.buffers import RingBuffer
113+
114+
# Create env instance
115+
control_freq = 10
116+
env = suite.make("Lift", robots="Panda", has_offscreen_renderer=False, use_camera_obs=False, control_freq=control_freq)
117+
118+
# Define a ringbuffer to store joint position values
119+
buffer = RingBuffer(dim=env.robots[0].robot_model.dof, length=10)
120+
121+
# Create a function that we'll use as the "filter" for the joint position Observable
122+
# This is a pass-through operation, but we record the value every time it gets called
123+
# As per the Observables API, this should take in an arbitrary numeric and return the same type / shape
124+
def filter_fcn(corrupted_value):
125+
# Record the inputted value
126+
buffer.push(corrupted_value)
127+
# Return this value (no-op performed)
128+
return corrupted_value
129+
130+
# Now, let's enable the joint position Observable with this filter function
131+
env.modify_observable(
132+
observable_name="robot0_joint_pos",
133+
attribute="filter",
134+
modifier=filter_fcn,
135+
)
136+
137+
# Let's also increase the sampling rate to showcase the Observable's ability to update multiple times per env step
138+
obs_sampling_freq = control_freq * 4
139+
env.modify_observable(
140+
observable_name="robot0_joint_pos",
141+
attribute="sampling_rate",
142+
modifier=obs_sampling_freq,
143+
)
144+
145+
# Take a single environment step with positive joint velocity actions
146+
arm_action = np.ones(env.robots[0].robot_model.dof) * 1.0
147+
gripper_action = [1]
148+
action = np.concatenate([arm_action, gripper_action])
149+
env.step(action)
150+
151+
# Now we can analyze what values were recorded
152+
np.set_printoptions(precision=2)
153+
print(f"\nPolicy Frequency: {control_freq}, Observable Sampling Frequency: {obs_sampling_freq}")
154+
print(f"Number of recorded samples after 1 policy step: {buffer._size}\n")
155+
for i in range(buffer._size):
156+
print(f"Recorded value {i}: {buffer.buf[i]}")
157+
```

docs/demos.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ The `demo_domain_randomization.py` script showcases our domain randomization fun
4646

4747
![collection of grippers](images/domain_randomization.png)
4848

49+
50+
### Sensor Realism
51+
The `demo_sensor_corruption.py` script shows how the [Observable](modules/sensors) functionality can be used to model sensor corruption and delay. The [Observable](modules/sensors) class provides easy-to-use interface for simulating real-world sensor noises, variable sensor delays, and sampling frequencies of realistic sensors. These techniques are useful for improving the generalization and robustness of the policies trained on robosuite, facilitating sim2real transfer to the real hardware. For example, see Appendix B of [Zhu et al. RSS'2018](https://arxiv.org/abs/1802.09564) and Section V of [Tan et al. RSS'2018](https://arxiv.org/abs/1804.10332).
52+
53+
4954
### Gripper Selection
5055
The `demo_gripper_selection.py` script shows you how to select gripper for an environment. This is controlled by `gripper_type` keyword argument. The set of all grippers is defined by the global variable `robosuite.ALL_GRIPPERS`.
5156

docs/images/module_overview.png

7.39 KB
Loading

docs/images/robot_module.png

-126 KB
Loading

docs/index.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Welcome to robosuite's documentation!
2626
modules/environments
2727
modules/sensors
2828
modules/devices
29+
modules/renderers
2930

3031
.. toctree::
3132
:maxdepth: 1
@@ -40,8 +41,8 @@ Welcome to robosuite's documentation!
4041
:maxdepth: 1
4142
:caption: Modeling API
4243

44+
modeling/mujoco_model
4345
modeling/robot_model
44-
modeling/gripper_model
4546
modeling/object_model
4647
modeling/arena
4748
modeling/task
@@ -58,6 +59,7 @@ Welcome to robosuite's documentation!
5859

5960
algorithms/benchmarking
6061
algorithms/demonstrations
62+
algorithms/sim2real
6163
algorithms/roboturk
6264

6365
.. toctree::

docs/modeling/arena.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
Arena
22
=====
33

4+
The ``Arena`` class serves as a base model for building the simulation environment.
5+
By default, this includes a ground plane and visual walls, and child classes extend this
6+
to additionally include other objects, e.g., a table or bins.
7+
48
Base Arena
59
----------
610

711
.. autoclass:: robosuite.models.arenas.arena.Arena
812

913
.. automethod:: __init__
1014
.. automethod:: set_origin
11-
.. automethod:: add_pos_indicator
15+
.. automethod:: set_camera

0 commit comments

Comments
 (0)