Skip to content

Commit 5514d2c

Browse files
committed
Merge pull request #140 from personalrobotics/bugfix/cloning_race
Added a check for a cloning race condition.
2 parents a10c245 + 6b7f55c commit 5514d2c

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/prpy/planning/base.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import abc
3232
import functools
3333
import logging
34+
import numpy
3435
import openravepy
3536
from ..clone import Clone
3637
from ..util import CopyTrajectory, GetTrajectoryTags, SetTrajectoryTags
@@ -97,10 +98,35 @@ def __call__(self, instance, robot, *args, **kw_args):
9798
env = robot.GetEnv()
9899
defer = kw_args.get('defer')
99100

101+
# Store the original joint values and indices.
102+
joint_indices = [robot.GetActiveDOFIndices(), None]
103+
joint_values = [robot.GetActiveDOFValues(), None]
104+
100105
with Clone(env, clone_env=instance.env,
101106
lock=True, unlock=False) as cloned_env:
102107
cloned_robot = cloned_env.Cloned(robot)
103108

109+
# Store the cloned joint values and indices.
110+
joint_indices[1] = cloned_robot.GetActiveDOFIndices()
111+
joint_values[1] = cloned_robot.GetActiveDOFValues()
112+
113+
# Check for mismatches in the cloning and hackily reset them.
114+
# (This is due to a possible bug in OpenRAVE environment cloning where in
115+
# certain situations, the Active DOF ordering and values do not match the
116+
# parent environment. It seems to be exacerbated by multirotation joints,
117+
# but the exact cause and repeatability is unclear at this point.)
118+
if not numpy.array_equal(joint_indices[0], joint_indices[1]):
119+
logger.warning("Cloned Active DOF index mismatch: %s != %s",
120+
str(joint_indices[0]),
121+
str(joint_indices[1]))
122+
cloned_robot.SetActiveDOFs(joint_indices[0])
123+
124+
if not numpy.allclose(joint_values[0], joint_values[1]):
125+
logger.warning("Cloned Active DOF value mismatch: %s != %s",
126+
str(joint_values[0]),
127+
str(joint_values[1]))
128+
cloned_robot.SetActiveDOFValues(joint_values[0])
129+
104130
def call_planner():
105131
try:
106132
planner_traj = self.func(instance, cloned_robot,

0 commit comments

Comments
 (0)