MCPcopy Create free account
hub / github.com/google-deepmind/dm_control / _make_model

Function _make_model

dm_control/suite/cartpole.py:105–127  ·  view source on GitHub ↗

Generates an xml string defining a cart with `n_poles` bodies.

(n_poles)

Source from the content-addressed store, hash-verified

103
104
105def _make_model(n_poles):
106 """Generates an xml string defining a cart with `n_poles` bodies."""
107 xml_string = common.read_model('cartpole.xml')
108 if n_poles == 1:
109 return xml_string
110 mjcf = etree.fromstring(xml_string)
111 parent = mjcf.find('./worldbody/body/body') # Find first pole.
112 # Make chain of poles.
113 for pole_index in range(2, n_poles+1):
114 child = etree.Element('body', name='pole_{}'.format(pole_index),
115 pos='0 0 1', childclass='pole')
116 etree.SubElement(child, 'joint', name='hinge_{}'.format(pole_index))
117 etree.SubElement(child, 'geom', name='pole_{}'.format(pole_index))
118 parent.append(child)
119 parent = child
120 # Move plane down.
121 floor = mjcf.find('./worldbody/geom')
122 floor.set('pos', '0 0 {}'.format(1 - n_poles - .05))
123 # Move cameras back.
124 cameras = mjcf.findall('./worldbody/camera')
125 cameras[0].set('pos', '0 {} 1'.format(-1 - 2*n_poles))
126 cameras[1].set('pos', '0 {} 2'.format(-2*n_poles))
127 return etree.tostring(mjcf, pretty_print=True)
128
129
130class Physics(mujoco.Physics):

Callers 1

get_model_and_assetsFunction · 0.70

Calls 2

setMethod · 0.80
findMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…