in mujoco_worldgen/objs/obj_from_xml.py [0:0]
def add_joints(self, body):
joint_names = []
if 'joint' not in body:
body['joint'] = []
if isinstance(body['joint'], OrderedDict):
body['joint'] = [body['joint']]
for i, slide_axis in enumerate(np.eye(3)):
found = False
for joint in body['joint']:
if not isinstance(joint, OrderedDict):
continue
if joint.get('@type') != 'slide':
continue
if '@axis' not in joint:
continue
axis = joint['@axis']
if np.linalg.norm(slide_axis - axis) < 1e-6:
joint_names.append(joint['@name'])
found = True
break # Found axis
if not found: # add this joint
slide = OrderedDict()
joint_name = self.name + ':slide%d' % i
slide['@name'] = joint_name
slide['@type'] = 'slide'
slide['@axis'] = slide_axis
slide['@damping'] = '0.01'
slide['@pos'] = np.zeros(3)
body['joint'].append(slide)
joint_names.append(joint_name)
return joint_names