Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Domain Randomization Help #5

Open
ava6969 opened this issue Apr 7, 2022 · 2 comments
Open

Domain Randomization Help #5

ava6969 opened this issue Apr 7, 2022 · 2 comments

Comments

@ava6969
Copy link

ava6969 commented Apr 7, 2022

Hi I am trying to implement domain randomization.

  1. Between scene_initialization and domain initialization where will be the best place to initialize the physics, mass as mentioined in the paper.

  2. How does one really initialize the friction, Can you please examine my code.

  3. How does one implement action delay, are the rewards and observations delayed too

@dataclasses.dataclass
class DomainRandomizer:
def init(self, basket, props, robot):

    self.props = props
    self.basket = basket
    self.arm = robot.arm
    self.gripper = robot.gripper

    self.gripper_friction = Uniform([0.3, 0.1, 0.05], [0.6, 0.1, 0.005])

    friction, mass, low, hi = np.array([1, 0.005, 0.0001], float), 0.201, 0.9, 1.1
    self.object_rand = dict(friction=Uniform(friction * low, friction * hi),
                            mass=Uniform(mass * low, mass * hi))

    friction = np.array([0.1, 0.1, 0.0001], float)
    self.arm_rand = dict(friction=Uniform(friction * low, friction * hi),
                         damping=Uniform(0.1 * low, 0.1 * hi),
                         armature=Uniform(low, hi),
                         friction_loss=Uniform(0.3 * low, 0.3 * hi))

    friction = np.array([1, 0.005, 0.0001], float)
    self.hand_rand = dict(friction=Uniform(friction * low, friction * hi),
                          driver_damping=Uniform(0.2 * low, 0.2 * hi),
                          armature=Uniform(0.1 * low, 0.1 * hi),
                          spring_link_damping=Uniform(0.00125 * low, 0.00125 * hi))

    friction = np.array([1.0, 0.001, 0.001], float)
    self.basket_friction = Uniform(friction * low, friction * hi)

    gear_ratio = np.array([1, 0, 0, 0, 0, 0], float)
    self.actuator_gear = Uniform(gear_ratio * low, gear_ratio * hi)


def __call__(self, random_state: np.random.RandomState) -> bool:
    for p in self.props:
        collision_geom = p.mjcf_model.find_all('geom')[1]
        collision_geom.friction = self.object_rand['friction'].sample()

    basket_geoms = self.basket.mjcf_model.find_all('geom')
    for b in basket_geoms:
        b.friction = self.basket_friction.sample()

    hand_driver = self.gripper.mjcf_model.find('default', 'driver')
    hand_spring_link = self.gripper.mjcf_model.find('default', 'spring_link')
    hand = self.gripper.mjcf_model.find('default', 'reinforced_fingertip')

    hand.geom.friction = self.hand_rand['friction'].sample()
    hand_driver.joint.armature = self.hand_rand['armature'].sample()
    hand_driver.joint.damping = self.hand_rand['driver_damping'].sample()
    hand_spring_link.joint.damping = self.hand_rand['spring_link_damping'].sample()

    for joint in self.arm.joints:
        joint.armature = self.arm_rand['armature'].sample()
        joint.damping = self.arm_rand['damping'].sample()
        joint.frictionloss = self.arm_rand['friction_loss'].sample()

    for actuator in self.arm.actuators:
        actuator.gear = self.actuator_gear.sample()

    geoms = self.arm.mjcf_model.find_all('geom')
    for g in geoms:
        g.friction = self.arm_rand['friction'].sample()

    return True
@alaurens
Copy link
Collaborator

alaurens commented Apr 8, 2022

Hello!

We did reply to the other message you've posted on dm-robotics. Here is a copy past of the message, if this does not work please feel free to ask more questions!

My understanding is that the friction parameters you are setting are not having any effect in the simulation. The reason for this is that you are using doing this in the episode_initialiser where you should be doing it in the scene_initialiser (https://github.com/deepmind/dm_robotics/blob/main/py/moma/base_task.py#L58).

The reasoning is the following, there is the physics model and the physics data. The model compiled from an mjcf and you cannot modify the model parameters after compilation. The friction being part of the model this explains why you are not seeing any changes.
You need to modify the friction in the mjcf directly before the model is compiled. You do this using the scene initialiser mentioned above.

class MySceneInitializer:
  def __init__(self, arm):
    self._joints = arm.joints

  def __call__(rand_state: np.random.RandState) -> None:
    for joint in self._joints:
      joint.armature = self.arm_rand['armature'].sample()
      joint.damping = self.arm_rand['damping'].sample()
      joint.frictionloss = self.arm_rand['friction_loss'].sample()

@ava6969
Copy link
Author

ava6969 commented Apr 8, 2022

@alaurens so i want to be certain , if my code for initializing friction is correct. Thanks for the sceneinit code too. do i need to set the friction on all geoms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants