(walker_fn, arena, name='walker', ghost=False, visible=True,
               position=(0, 0, 0))
return walker
Create a walker.
Create a walker.
Create a walker .
def add_walker(walker_fn, arena, name='walker', ghost=False, visible=True,
               position=(0, 0, 0)):
  """Create a walker."""
  walker = walker_fn(name=name)

  if ghost:
    # if the walker has a built-in tracking light remove it.
    light = walker.mjcf_model.find('light', 'tracking_light')
    if light:
      light.remove()

    # Remove the contacts.
    for geom in walker.mjcf_model.find_all('geom'):
      # alpha=0.999 ensures grey ghost reference.
      # for alpha=1.0 there is no visible difference between real walker and
      # ghost reference.
      alpha = 0.999
      if geom.rgba is not None and geom.rgba[3] < alpha:
        alpha = geom.rgba[3]

      geom.set_attributes(
          contype=0,
          conaffinity=0,
          rgba=(0.5, 0.5, 0.5, alpha if visible else 0.0))

    # We don't want ghost actuators to be controllable, so remove them.
    model = walker.mjcf_model

    elems = model.find_all('actuator')
    sensors = [x for x in model.find_all('sensor') if 'actuator' in x.tag]
    elems += sensors

    for elem in elems:
      elem.remove()

    skin = walker.mjcf_model.find('skin', 'skin')
    if skin:
      if visible:
        skin.set_attributes(rgba=(0.5, 0.5, 0.5, 0.999))
      else:
        skin.set_attributes(rgba=(0.5, 0.5, 0.5, 0.))

  if position == (0, 0, 0):
    walker.create_root_joints(arena.attach(walker))
  else:
    spawn_site = arena.mjcf_model.worldbody.add('site', pos=position)
    walker.create_root_joints(arena.attach(walker, spawn_site))
    spawn_site.remove()

  return walker
def add_walker ( walker_fn , arena , name = 'walker' , ghost = False , visible = True , position = ( 0 , 0 , 0 ) ) : walker = walker_fn ( name = name ) if ghost : # if the walker has a built-in tracking light remove it. light = walker . mjcf_model . find ( 'light' , 'tracking_light' ) if light : light . remove ( ) # Remove the contacts. for geom in walker . mjcf_model . find_all ( 'geom' ) : # alpha=0.999 ensures grey ghost reference. # for alpha=1.0 there is no visible difference between real walker and # ghost reference. alpha = 0.999 if geom . rgba is not None and geom . rgba [ 3 ] < alpha : alpha = geom . rgba [ 3 ] geom . set_attributes ( contype = 0 , conaffinity = 0 , rgba = ( 0.5 , 0.5 , 0.5 , alpha if visible else 0.0 ) ) # We don't want ghost actuators to be controllable, so remove them. model = walker . mjcf_model elems = model . find_all ( 'actuator' ) sensors = [ x for x in model . find_all ( 'sensor' ) if 'actuator' in x . tag ] elems += sensors for elem in elems : elem . remove ( ) skin = walker . mjcf_model . find ( 'skin' , 'skin' ) if skin : if visible : skin . set_attributes ( rgba = ( 0.5 , 0.5 , 0.5 , 0.999 ) ) else : skin . set_attributes ( rgba = ( 0.5 , 0.5 , 0.5 , 0. ) ) if position == ( 0 , 0 , 0 ) : walker . create_root_joints ( arena . attach ( walker ) ) else : spawn_site = arena . mjcf_model . worldbody . add ( 'site' , pos = position ) walker . create_root_joints ( arena . attach ( walker , spawn_site ) ) spawn_site . remove ( ) return walker