in robogym/wrappers/randomizations.py [0:0]
def _set_field(self, sim):
limit_widths = self._orig_value[:, 1] - self._orig_value[:, 0]
stds = limit_widths * self._relative_std
stds_reshaped = np.repeat(stds, 2).reshape(
len(self._joint_names), 2
) * self._random_noises(len(self._joint_names))
new_jnt_limits = self._orig_value.copy()
for idx, jnt_id in enumerate(self._joint_ids):
min_width = limit_widths[idx] * 0.001
# Let's go through the joint limit range one by one to handle special case,
# i.e., if the lower bound is 0.0, we should not lower it to be negative
low, high = new_jnt_limits[idx]
if low == 0.0 and high > 0:
low = max(0.0, low + stds_reshaped[idx][0])
high = max(low + min_width, high + stds_reshaped[idx][1])
elif low < 0 and high == 0.0:
high = min(0.0, high + stds_reshaped[idx][1])
low = min(high - min_width, low + stds_reshaped[idx][0])
else:
low += stds_reshaped[idx][0]
high = max(low + min_width, high + stds_reshaped[idx][1])
new_jnt_limits[idx][0] = low
new_jnt_limits[idx][1] = high
# Apply the new joint limit to the joint range and actuator control range.
sim.model.jnt_range[self._joint_ids] = new_jnt_limits.copy()
for jnt_id, jnt_name in zip(self._joint_ids, self._joint_names):
actuator_name = jnt_name.replace(":", ":A_")
if actuator_name not in sim.model.actuator_names:
continue
actuator_id = sim.model.actuator_name2id(actuator_name)
if actuator_name[-3:] == "FJ1":
# This actuator should control the unactuated "*FJ0' joint as well.
other_jnt_name = jnt_name.replace("FJ1", "FJ0")
other_jnt_id = sim.model.joint_name2id(other_jnt_name)
fj0_range = sim.model.jnt_range[other_jnt_id]
fj1_range = sim.model.jnt_range[jnt_id]
sim.model.actuator_ctrlrange[actuator_id] = np.array(
[min(fj0_range[0], fj1_range[0]), fj0_range[1] + fj1_range[1]]
)
else:
sim.model.actuator_ctrlrange[actuator_id] = sim.model.jnt_range[jnt_id]
return OrderedDict([("joint_limit", new_jnt_limits)])