Skip to content

Commit

Permalink
add docs, fix style and minor bugs
Browse files Browse the repository at this point in the history
Signed-off-by: You Liang Tan <tan_you_liang@hotmail.com>
  • Loading branch information
youliangtan committed Oct 29, 2024
1 parent 407a907 commit 7f6468d
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 42 deletions.
2 changes: 1 addition & 1 deletion docs/demos.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
We provide a collection of [demo scripts](https://github.com/ARISE-Initiative/robosuite/tree/master/robosuite/demos) to showcase the functionalities in **robosuite**.

### Environment Configuration
The `demo_random_action.py` sciprt is the starter demo script that you should try first. It highlights the modular design of our simulated environments. It enables users to create new simulation instances by choosing one [environment](modules/environments), one or more [robots](modules/robots), and their [controllers](modules/controllers) from the command line. The script creates an environment instance and controls the robots with uniform random actions drawn from the controller-specific action space. The list of all environments, robots, controllers, and gripper types supported in the current version of **robosuite** are defined by `suite.ALL_ENVIRONMENTS`, `suite.ALL_ROBOTS`, `suite. ALL_PART_CONTROLLERS`, and `suite.ALL_GRIPPERS` respectively.
The `demo_random_action.py` script is the starter demo script that you should try first. It highlights the modular design of our simulated environments. It enables users to create new simulation instances by choosing one [environment](modules/environments), one or more [robots](modules/robots), and their [controllers](modules/controllers) from the command line. The script creates an environment instance and controls the robots with uniform random actions drawn from the controller-specific action space. The list of all environments, robots, controllers, and gripper types supported in the current version of **robosuite** are defined by `suite.ALL_ENVIRONMENTS`, `suite.ALL_ROBOTS`, `suite. ALL_PART_CONTROLLERS`, and `suite.ALL_GRIPPERS` respectively.


### Controller Test
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Installation
**robosuite** officially supports macOS and Linux on Python 3. It can be run with an on-screen display for visualization or in a headless mode for model training, with or without a GPU.

The base installation requires the MuJoCo physics engine (with [mujoco](https://github.com/deepmind/mujoco), refer to link for troubleshooting the installation and further instructions) and [numpy](http://www.numpy.org/). To avoid interfering with system packages, it is recommended to install it under a virtual environment by first running `virtualenv -p python3 . && source bin/activate` or setting up a Conda environment by installing [Anaconda](https://www.anaconda.com/) and running `conda create -n robosuite python=3.8`.
The base installation requires the MuJoCo physics engine (with [mujoco](https://github.com/deepmind/mujoco), refer to link for troubleshooting the installation and further instructions) and [numpy](http://www.numpy.org/). To avoid interfering with system packages, it is recommended to install it under a virtual environment by first running `virtualenv -p python3 . && source bin/activate` or setting up a Conda environment by installing [Anaconda](https://www.anaconda.com/) and running `conda create -n robosuite python=3.10`.

### Install from pip

Expand Down
9 changes: 9 additions & 0 deletions docs/modules/robots.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,12 @@ At any given time, each robot has a set of `properties` whose real-time values c
#### Baxter
![baxter_robot](../images/models/robot_model_Baxter.png)
[Baxter](http://collabrobots.com/about-baxter-robot/) is an older but classic bimanual robot originally produced by Rethink Robotics but now owned by CoThink Robotics, and is equipped with two 7-DoF arms as well as an addition joint for controlling its swiveling display screen (inactive and disabled by default in **robosuite**). Each arm can be controlled independently in, and is the single multi-armed model currently supported in **robosuite**. Each arm is equipped with a `RethinkGripper` by default.

## Robot Bases

We provide a set of robot bases that can be added to the `RobotModel` via the `add_base(base: RobotBaseModel)` method. These bases can be static (e.g. `MountModel`) or movable (e.g. `MobileBaseModel` or `LegBaseModel`). This enables composability of robots with different bases, such as a mobile manipulator robot or a quadruped robot. Examples are shown in the [compositional.py](robosuite/models/robots/compositional.py).


## Robosuite Models

Other than the core robot models, we also provide more models for the `robosuite` ecosystem. Checkout this [robosuite_models](https://github.com/ARISE-Initiative/robosuite_models) repository for more details. This can also be installed via `pip install robosuite-models`.
6 changes: 4 additions & 2 deletions robosuite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
try:
import robosuite_models
except:
ROBOSUITE_DEFAULT_LOGGER.warn(
"Could not import robosuite_models. Some robots may not be available. If you want to use these robots, please install robosuite_models from source (https://github.com/ARISE-Initiative/robosuite_models) or through pip install."
ROBOSUITE_DEFAULT_LOGGER.warning(
"Could not import robosuite_models. Some robots may not be available. "
"If you want to use these robots, please install robosuite_models from "
"source (https://github.com/ARISE-Initiative/robosuite_models) or through pip install."
)

__version__ = "1.5.0"
Expand Down
28 changes: 17 additions & 11 deletions robosuite/devices/mjgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,18 @@ def input2action(self) -> Dict[str, np.ndarray]:
target_pos_world, target_ori_mat_world = get_mocap_pose(self.env.sim, f"{target_name_prefix}_eef_target")

if isinstance(self.env.robots[0].composite_controller, WholeBodyIK):
assert self.env.robots[0].composite_controller.composite_controller_specific_config.get(
"ik_input_ref_frame", "world"
) == "world", "Only support world frame for MJGui teleop for now. " \
"Please modify the controller configs."
assert self.env.robots[0].composite_controller.composite_controller_specific_config.get(
"ik_input_type", "absolute"
) == "absolute", "Only support absolute actions for MJGui teleop for now. " \
"Please modify the controller configs."
assert (
self.env.robots[0].composite_controller.composite_controller_specific_config.get(
"ik_input_ref_frame", "world"
)
== "world"
), ("Only support world frame for MJGui teleop for now. " "Please modify the controller configs.")
assert (
self.env.robots[0].composite_controller.composite_controller_specific_config.get(
"ik_input_type", "absolute"
)
== "absolute"
), ("Only support absolute actions for MJGui teleop for now. " "Please modify the controller configs.")
# check if need to update frames
if isinstance(self.env.robots[0].composite_controller, WholeBody):
# TODO: should be more general
Expand All @@ -166,9 +170,11 @@ def input2action(self) -> Dict[str, np.ndarray]:
assert (
self.env.robots[0].part_controllers[self.active_end_effector].input_ref_frame == "world"
and self.env.robots[0].part_controllers[self.active_end_effector].input_type == "absolute"
), "Only support world frame and absolute actions for now. You can modify the controller configs " \
"being used, e.g. in robosuite/controllers/config/robots/{robot_name}.json, " \
"robosuite/controllers/config/default/composite/{}.json to enable other options."
), (
"Only support world frame and absolute actions for now. You can modify the controller configs "
"being used, e.g. in robosuite/controllers/config/robots/{robot_name}.json, "
"robosuite/controllers/config/default/composite/{}.json to enable other options."
)
target_pos, target_ori_mat = target_pos_world, target_ori_mat_world

# convert ori mat to axis angle
Expand Down
6 changes: 4 additions & 2 deletions robosuite/robots/legged_robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ def _load_leg_controllers(self):
if len(self._ref_actuators_indexes_dict[self.legs]) == 0:
return None

assert self.legs is not None, "Legs must be defined for legged robots in part_controller_config. " \
"Please specify legs in controller configs."
assert self.legs is not None, (
"Legs must be defined for legged robots in part_controller_config. "
"Please specify legs in controller configs."
)
assert (
type(self.part_controller_config[self.legs]) == dict
), "Inputted controller config must be a dict! Instead, got type: {}".format(
Expand Down
2 changes: 2 additions & 0 deletions robosuite/scripts/playback_demonstrations_from_hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
parser.add_argument(
"--folder",
type=str,
required=True,
help="Path to your demonstration folder that contains the demo.hdf5 file, e.g.: "
"'path_to_assets_dir/demonstrations/YOUR_DEMONSTRATION'",
),
Expand All @@ -39,6 +40,7 @@

demo_path = args.folder
hdf5_path = os.path.join(demo_path, "demo.hdf5")

f = h5py.File(hdf5_path, "r")
env_name = f["data"].attrs["env"]
env_info = json.loads(f["data"].attrs["env_info"])
Expand Down
28 changes: 8 additions & 20 deletions robosuite/scripts/render_dataset_with_omniverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,9 @@
help="(optional) enable online rendering, will not save the usd file in this mode",
)

parser.add_argument(
"--skip_frames",
type=int,
default=1,
help="(optional) render every nth frame. Defaults to 1"
)
parser.add_argument("--skip_frames", type=int, default=1, help="(optional) render every nth frame. Defaults to 1")

parser.add_argument(
"--hide_sites",
action="store_true",
default=False,
help="(optional) hide all sites in the scene"
)
parser.add_argument("--hide_sites", action="store_true", default=False, help="(optional) hide all sites in the scene")

parser.add_argument(
"--reload_model",
Expand All @@ -81,11 +71,7 @@
)

parser.add_argument(
"--keep_models",
type=str,
nargs='+',
default=[],
help="(optional) keep the model from the Mujoco XML file"
"--keep_models", type=str, nargs="+", default=[], help="(optional) keep the model from the Mujoco XML file"
)

# Add arguments for launch
Expand Down Expand Up @@ -257,7 +243,9 @@ class RobosuiteEnvInterface:
Env wrapper to load a robosuite demonstration
"""

def __init__(self, dataset, episode, output_directory, cameras="agentview", reload_model=False, keep_models=[]) -> None:
def __init__(
self, dataset, episode, output_directory, cameras="agentview", reload_model=False, keep_models=[]
) -> None:
self.dataset = dataset
self.episode = episode
self.output_directory = output_directory
Expand Down Expand Up @@ -321,7 +309,7 @@ def get_states(self):
if body_model is not None and body_env is not None:
for attr_name, attr_value in body_model.attrib.items():
body_env.set(attr_name, attr_value)
env_xml = ET.tostring(root_env, encoding='unicode')
env_xml = ET.tostring(root_env, encoding="unicode")
model_xml = env_xml

if args.hide_sites:
Expand Down Expand Up @@ -640,7 +628,7 @@ def main():
output_directory=output_directory,
cameras=args.cameras,
reload_model=args.reload_model,
keep_models=args.keep_models
keep_models=args.keep_models,
)
if not args.online:
# generate the usd first, and close the env to save the usd
Expand Down
9 changes: 6 additions & 3 deletions robosuite/utils/ik_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,12 @@ def get_targets(self):
target_ori[right_index] = self.history["right_eef_quat_wxyz"][int(self.pkl_t)]
self.full_model_data.mocap_pos[self.mocap_ids[left_index]] = self.history["left_eef_pos"][int(self.pkl_t)]
self.full_model_data.mocap_pos[self.mocap_ids[right_index]] = self.history["right_eef_pos"][int(self.pkl_t)]
self.full_model_data.mocap_quat[self.mocap_ids[left_index]] = self.history["left_eef_quat_wxyz"][int(self.pkl_t)]
self.full_model_data.mocap_quat[self.mocap_ids[right_index]] = self.history["right_eef_quat_wxyz"][int(self.pkl_t)]
self.full_model_data.mocap_quat[self.mocap_ids[left_index]] = self.history["left_eef_quat_wxyz"][
int(self.pkl_t)
]
self.full_model_data.mocap_quat[self.mocap_ids[right_index]] = self.history["right_eef_quat_wxyz"][
int(self.pkl_t)
]
else:
raise ValueError(f"Invalid input type {self.input_type}")

Expand All @@ -169,7 +173,6 @@ def forward_kinematics(self, qpos: np.ndarray) -> Dict[str, np.ndarray]:
mujoco.mj_kinematics(self.full_model, data)
return {name: data.site(site_id).xpos for name, site_id in zip(self.site_names, self.site_ids)}


def transform_pose(
self, src_frame_pose: np.ndarray, src_frame: Literal["world", "base"], dst_frame: Literal["world", "base"]
) -> np.ndarray:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_renderers/test_all_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_mujoco_renderer():
env.render()


def test_default_renderer():
def test_mjviewer_renderer():
env = suite.make(
env_name="Lift",
robots="Panda",
Expand All @@ -42,7 +42,7 @@ def test_default_renderer():
ignore_done=True,
use_camera_obs=False,
control_freq=20,
renderer="default",
renderer="mjviewer",
)

env.reset()
Expand Down

0 comments on commit 7f6468d

Please sign in to comment.