Teleoperation and Learning Policies with Robosuite

Robosuite is a simulation framework powered by the MuJoCo physics engine for robot learning. It also offers a suite of benchmark environments for reproducible research. MagiClaw provides simple and intuitive operation, real-time output of 6D pose and gripper angle status information, making it very suitable as a remote control device for Robosite. This page will introduce how to teleoperate robots using MagiClaw, collect data and train policies in robosuite.

Install RoboSuite

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, refer to link for troubleshooting the installation and further instructions) and numpy. To avoid interfering with system packages, it is recommended to install it in a virtual environment by first running virtualenv -p python3 . && source bin/activate or setting up a Conda environment by installing Anaconda and running conda create -n robosuite python=3.10.

Step 1. Clone the latest repository modified with MagiClaw:

git clone https://github.com/asMagiClaw/magiclaw-robosuite.git
cd magiclaw-robosuite

Step 2. Install the base requirements:

pip install -r requirements.txt

Step 3. Test the installation:

python robosuite/demos/demo_random_action.py

WARNING

Teleoperation with MagiClaw

The in-hand MagiClaw works as an I/O device in robosuite, providing the TCP pose and gripper angle to the robot controllers.

Step 1. Start the MagiClaw via the app, CLI or dashboard.

Step 2. To start controlling a robot in robosuite using the data streamed from the MagiClaw, run:

python robosuite/demos/demo_device_control.py --host <host>

where <host> refers to the IP address of the MagiClaw control box.

And an OpenCV window created by the mujoco renderer.

Step 3. Use MagiClaw to control the robot in robosuite, and the control command is shown below.

Control
Command

Move MagiClaw laterally

mover arm horizontally in x-y plane

Mover MagiClaw vertically

move arm vertically

Twist MagiClaw about an axis

rotate arm about a corresponding axis

Press/release MagiClaw trigger

open/close gripper

Ctrl+C

quit

Ctrl+Q

reset simulation

B

toggle arm/base mode (if applicable)

S

switch active arm (if multi-armed robot)

=

switch active robot (if multi-robot environment)

In robosuite/demos/demo_device_control.py, we defined a PandaWithMagiClaw class and registered as a FixedBaseRobot:

@register_robot_class("FixedBaseRobot")
class PandaWithMagiClaw(Panda):
    """
    Panda robot with MagiClaw gripper.
    """

    @property
    def default_gripper(self):
        return {"right": "MagiClaw"}
    
    @property
    def init_qpos(self):
        return np.array([0.00, 0.00, 0.00, -np.pi / 2.0, 0.00, np.pi / 2.0, np.pi / 4])

This is a Franka Panda mounted with a MagiClaw (on-robot type). If you want to change to another robot, just create another class, modify the default_gripper and init_qpos properties, and add @register_robot_class.

Collecting Human Demonstrations

Robosuite provides teleoperation utilities that allow users to control the robots with input devices. Such functionality allows us to collect a dataset of human demonstrations for learning. We provide an example script to illustrate how to collect demonstrations. The collect_human_demonstrations script has the following arguments:

  • directory: path to a folder for where to store the pickle file of collected demonstrations

  • environment: name of the environment you would like to collect the demonstrations for

  • device: “keyboard” or “magiclaw”

  • renderer: Mujoco’s builtin interactive viewer (mjviewer) or OpenCV viewer (mujoco)

  • camera: Pass multiple camera names to enable multiple views. Note that the “mujoco” renderer must be enabled when using multiple views, while “mjviewer” is not supported.

Replaying Human Demonstrations

We have included an example script that illustrates how demonstrations can be loaded and played back. Our playback_demonstrations_from_hdf5 script selects demonstration episodes at random from a demonstration pickle file and replays them.

Structure of collected demonstrations

Every set of demonstrations is collected as a demo.hdf5 file. The demo.hdf5 file is structured as follows.

  • data (group)

    • date (attribute) - date of collection

    • time (attribute) - time of collection

    • repository_version (attribute) - repository version used during collection

    • env (attribute) - environment name on which demos were collected

    • demo1 (group) - group for the first demonstration (every demonstration has a group)

      • model_file (attribute) - the xml string corresponding to the MJCF mujoco model

      • states (dataset) - flattened mujoco states, ordered by time

      • actions (dataset) - environment actions, ordered by time

    • demo2 (group) - group for the second demonstration

      (and so on)

The reason for storing mujoco states instead of raw observations is to make it easy to retrieve different kinds of observations in a postprocessing step. This also saves disk space (image datasets are much larger).

Using Demonstrations for Learning

The robomimic framework makes it easy to train policies using your own datasets collected with robosuite. The framework also contains many useful examples for how to integrate hdf5 datasets into your own learning pipeline.

The robosuite repository also has some utilities for using the demonstrations to alter the start state distribution of training episodes for learning RL policies - this has proved effective in several prior works. For more information see the DemoSamplerWrapper class.

Last updated