Domain Randomization

In this tutorial, we will show how to use the domain randomization feature. This feature is useful to train a robot to be robust to changes in the environment, such as joint friction, mass, or inertia. Before starting, make sure to get familiar with the Randomization Handler, where you find a detailed documentation.

Consider the following domain randomization file for the Talos robot:

# here a default randomization can be set for all joints.
Default:
  # these joints will not be included during domain randomization.
  exclude: ["pelvis_tx", "pelvis_ty", "pelvis_tz", "pelvis_tilt", "pelvis_list", "pelvis_rotation"]
  Joints:
    damping:
      sigma: 0.0
    stiffness:
      sigma: 0.0
    frictionloss:
      sigma: 0.0

# here joint specific configurations can be made
Joints:
  # set either a sigma for sampling from a normal distribution, or set a range or delta-range for uniform sampling.
  back_bkz:
    damping:
      uniform_range: [4.0, 6.0]
    stiffness:
      sigma: 0.0
    armature:
      sigma: 0.0
    frictionloss:
      sigma: 0.0
  back_bkx:
    damping:
      uniform_range: [4.0, 6.0]
    stiffness:
      sigma: 0.0
    armature:
      sigma: 0.0
    frictionloss:
      sigma: 0.0

Inertial:
  leg_right_6_link:
    mass:
      uniform_range_delta: 0.5
    diaginertia:
      uniform_range_delta: 0.001
  leg_right_5_link:
    fullinertia:
        uniform_range_delta: 0.001

Once a configuration file is created, we can pass it to the environment and start training as usual. Here is an example of how to use the domain randomization feature with the Talos robot:

import numpy as np
from loco_mujoco import LocoEnv


env = LocoEnv.make("Talos.walk", domain_randomization_config="./domain_randomization_talos.yaml")

action_dim = env.info.action_space.shape[0]

env.reset()
env.render()
absorbing = False
i = 0

while True:
    if i == 1000 or absorbing:
        env.reset()
        i = 0
    action = np.random.randn(action_dim)
    nstate, _, absorbing, _ = env.step(action)

    env.render()
    i += 1

Note

We provide more examples in respective directory in the main LocoMuJoCo repository.