Skip to content

Commit a835bd9

Browse files
dm_control: Import of refs/pull/366/head
PiperOrigin-RevId: 507444578 Change-Id: I6b553ec182e1cade0dca89b1f0d322164eb047c7
2 parents 885e8f7 + 0b11adb commit a835bd9

8 files changed

Lines changed: 874 additions & 650 deletions

File tree

dm_control/locomotion/walkers/assets/dog_v2/add_torque_actuators.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ def add_motors(physics, model, lumbar_joints, cervical_joints, caudal_joints):
2727
lumbar_joints: a list of joints objects.
2828
cervical_joints: a list of joints objects.
2929
caudal_joints: a list of joints objects.
30+
31+
Returns:
32+
A list of actuated joints.
3033
"""
3134
# Fixed Tendons:
3235
spinal_joints = collections.OrderedDict()
@@ -37,31 +40,32 @@ def add_motors(physics, model, lumbar_joints, cervical_joints, caudal_joints):
3740
for region in spinal_joints.keys():
3841
for direction in ['extend', 'bend', 'twist']:
3942
joints = [
40-
joint for joint in spinal_joints[region] if direction in joint.name
43+
joint for joint in spinal_joints[region] if direction in joint.name
4144
]
4245
if joints:
4346
tendon = model.tendon.add(
44-
'fixed', name=region + direction, dclass=joints[0].dclass)
47+
'fixed', name=region + direction, dclass=joints[0].dclass
48+
)
4549
tendons.append(tendon)
4650
joint_inertia = physics.bind(joints).M0
47-
coefs = joint_inertia ** .25
51+
coefs = joint_inertia**0.25
4852
coefs /= coefs.sum()
4953
coefs *= len(joints)
5054
for i, joint in enumerate(joints):
5155
tendon.add('joint', joint=joint, coef=coefs[i])
5256

5357
# Actuators:
54-
all_spinal_joints = [
55-
joint for region in spinal_joints.values() for joint in region
56-
# pylint: disable=g-complex-comprehension
57-
]
58+
all_spinal_joints = []
59+
for region in spinal_joints.values():
60+
all_spinal_joints.extend(region)
5861
root_joint = model.find('joint', 'root')
5962
actuated_joints = [
60-
joint for joint in model.find_all('joint')
61-
if joint not in all_spinal_joints and joint is not root_joint
63+
joint
64+
for joint in model.find_all('joint')
65+
if joint not in all_spinal_joints and joint is not root_joint
6266
]
6367
for tendon in tendons:
64-
gain = 0.
68+
gain = 0.0
6569
for joint in tendon.joint:
6670
# joint.joint.user = physics.bind(joint.joint).damping
6771
def_joint = model.default.find('default', joint.joint.dclass)
@@ -70,10 +74,12 @@ def add_motors(physics, model, lumbar_joints, cervical_joints, caudal_joints):
7074
gain /= len(tendon.joint)
7175

7276
model.actuator.add(
73-
'general', tendon=tendon, name=tendon.name, dclass=tendon.dclass)
77+
'general', tendon=tendon, name=tendon.name, dclass=tendon.dclass
78+
)
7479

7580
for joint in actuated_joints:
7681
model.actuator.add(
77-
'general', joint=joint, name=joint.name, dclass=joint.dclass)
82+
'general', joint=joint, name=joint.name, dclass=joint.dclass
83+
)
7884

7985
return actuated_joints

0 commit comments

Comments
 (0)