Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switched from ClonedPlanningMethod To LockedPlanningMethod #360

Merged
merged 7 commits into from
Nov 2, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/prpy/planning/adapters.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy
from openravepy import Environment
from .base import (
ClonedPlanningMethod,
LockedPlanningMethod,
Planner,
)
from ..kin import (
Expand All @@ -27,10 +27,8 @@ def __init__(self, delegate_planner):
super(PlanToEndEffectorOffsetTSRAdapter, self).__init__()

self.delegate_planner = delegate_planner
self.env = Environment()


@ClonedPlanningMethod
@LockedPlanningMethod
def PlanToEndEffectorOffset(self, robot, direction, distance, **kwargs):
""" Plan to a desired end-effector offset with fixed orientation.

Expand Down
2 changes: 1 addition & 1 deletion src/prpy/planning/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __init__(self, func):
self.func = func

def __call__(self, instance, robot, *args, **kw_args):
with robot.GetEnv():
with robot.GetEnv(), robot.CreateRobotStateSaver():
# Perform the actual planning operation.
traj = self.func(instance, robot, *args, **kw_args)

Expand Down
26 changes: 13 additions & 13 deletions src/prpy/planning/cbirrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from .adapters import PlanToEndEffectorOffsetTSRAdapter
from .base import (
BasePlanner,
ClonedPlanningMethod,
LockedPlanningMethod,
PlanningError,
Tags,
UnsupportedPlanningError,
Expand All @@ -56,11 +56,6 @@ def __init__(self, robot_checker_factory=None, timelimit=5.):
if robot_checker_factory is None:
robot_checker_factory = DefaultRobotCollisionCheckerFactory

self.problem = openravepy.RaveCreateProblem(self.env, 'CBiRRT')

if self.problem is None:
raise UnsupportedPlanningError('Unable to create CBiRRT module.')

self.robot_checker_factory = robot_checker_factory
if isinstance(robot_checker_factory, SimpleRobotCollisionCheckerFactory):
self._is_baked = False
Expand All @@ -73,7 +68,7 @@ def __init__(self, robot_checker_factory=None, timelimit=5.):
def __str__(self):
return 'CBiRRT'

@ClonedPlanningMethod
@LockedPlanningMethod
def PlanToConfigurations(self, robot, goals, **kw_args):
"""
Plan to multiple goal configurations with CBiRRT. This adds each goal
Expand All @@ -86,7 +81,7 @@ def PlanToConfigurations(self, robot, goals, **kw_args):
kw_args.setdefault('smoothingitrs', 0)
return self.Plan(robot, jointgoals=goals, **kw_args)

@ClonedPlanningMethod
@LockedPlanningMethod
def PlanToConfiguration(self, robot, goal, **kw_args):
"""
Plan to a single goal configuration with CBiRRT.
Expand All @@ -97,7 +92,7 @@ def PlanToConfiguration(self, robot, goal, **kw_args):
kw_args.setdefault('smoothingitrs', 0)
return self.Plan(robot, jointgoals=[goal], **kw_args)

@ClonedPlanningMethod
@LockedPlanningMethod
def PlanToEndEffectorPose(self, robot, goal_pose, **kw_args):
"""
Plan to a desired end-effector pose.
Expand All @@ -116,7 +111,7 @@ def PlanToEndEffectorPose(self, robot, goal_pose, **kw_args):
return self.Plan(robot, tsr_chains=[tsr_chain], **kw_args)


@ClonedPlanningMethod
@LockedPlanningMethod
def PlanToEndEffectorOffset(self, robot, direction, distance, **kw_args):
"""
Plan to a desired end-effector offset.
Expand All @@ -132,7 +127,7 @@ def PlanToEndEffectorOffset(self, robot, direction, distance, **kw_args):
return self.PlanToTSR(robot, tsr_chains=chains, **kw_args)


@ClonedPlanningMethod
@LockedPlanningMethod
def PlanToTSR(self, robot, tsr_chains, smoothingitrs=100, **kw_args):
"""
Plan to a goal specified as a list of TSR chains. CBiRRT supports an
Expand Down Expand Up @@ -177,14 +172,19 @@ def Plan(self, robot, smoothingitrs=None, timelimit=None, allowlimadj=0,
' non-negative; got {:f}.'.format(timelimit))

env = robot.GetEnv()
problem = openravepy.RaveCreateProblem(env, 'CBiRRT')

if problem is None:
raise UnsupportedPlanningError('Unable to create CBiRRT module.')

is_endpoint_deterministic = True
is_constrained = False

# TODO We may need this work-around because CBiRRT doesn't like it
# when an IK solver other than GeneralIK is loaded (e.g. nlopt_ik).
# self.ClearIkSolver(robot.GetActiveManipulator())

env.LoadProblem(self.problem, robot.GetName())
env.LoadProblem(problem, robot.GetName())

args = ['RunCBiRRT']
args += ['timelimit', str(timelimit)]
Expand Down Expand Up @@ -266,7 +266,7 @@ def Plan(self, robot, smoothingitrs=None, timelimit=None, allowlimadj=0,
collision_checker = self.robot_checker_factory(robot)
options = collision_checker.collision_options
with CollisionOptionsStateSaver(env.GetCollisionChecker(), options):
response = self.problem.SendCommand(args_str, True)
response = problem.SendCommand(args_str, True)
Copy link
Member

@mkoval mkoval Sep 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CBiRRT seems to modify:

  • the robot's active DOF values
  • the robot's DOF limits
  • the robot's transformation
  • the DOF values of any mimic bodies specified in a TSRChain.

This should be wrapped in a RobotStateSaver that preserves the robot's LinkTransformations and a KinBodyStateSaver for each mimic body that preserves its LinkTransformations. I don't see an option in RobotStateSaverto restore DOF position limits, so we will need to do that ourselves.


if not response.strip().startswith('1'):
raise PlanningError('Unknown error: ' + response,
Expand Down
6 changes: 3 additions & 3 deletions src/prpy/planning/ik.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from .. import ik_ranking
from base import (BasePlanner,
PlanningError,
ClonedPlanningMethod)
LockedPlanningMethod)

logger = logging.getLogger(__name__)

Expand All @@ -47,7 +47,7 @@ def __str__(self):
return 'IKPlanner'


@ClonedPlanningMethod
@LockedPlanningMethod
def PlanToIK(self, robot, pose, **kwargs):
"""
Plan to a desired end effector pose with IKPlanner.
Expand All @@ -61,7 +61,7 @@ def PlanToIK(self, robot, pose, **kwargs):
"""
return self._PlanToIK(robot, pose, **kwargs)

@ClonedPlanningMethod
@LockedPlanningMethod
def PlanToEndEffectorPose(self, robot, pose, **kwargs):
"""
Plan to a desired end effector pose with IKPlanner.
Expand Down
4 changes: 2 additions & 2 deletions src/prpy/planning/named.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import logging, numpy, openravepy
from base import BasePlanner, PlanningError, ClonedPlanningMethod
from base import BasePlanner, PlanningError, LockedPlanningMethod

class NamedPlanner(BasePlanner):
def __init__(self, delegate_planner=None):
Expand All @@ -41,7 +41,7 @@ def __init__(self, delegate_planner=None):
def __str__(self):
return 'NamedPlanner'

@ClonedPlanningMethod
@LockedPlanningMethod
def PlanToNamedConfiguration(self, robot, name, **kw_args):
""" Plan to a named configuration.

Expand Down
58 changes: 31 additions & 27 deletions src/prpy/planning/ompl.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
PlannerStatus,
RaveCreatePlanner,
RaveCreateTrajectory,
Robot
)
from ..collision import (
BakedRobotCollisionCheckerFactory,
Expand All @@ -55,7 +56,7 @@
)
from .base import (
BasePlanner,
ClonedPlanningMethod,
LockedPlanningMethod,
PlanningError,
Tags,
UnsupportedPlanningError,
Expand Down Expand Up @@ -109,18 +110,10 @@ def __init__(self, algorithm='RRTConnect', robot_checker_factory=None,
'or_ompl only supports Simple and'
' BakedRobotCollisionCheckerFactory.')

planner_name = 'OMPL_{:s}'.format(algorithm)
self.planner = RaveCreatePlanner(self.env, planner_name)

if self.planner is None:
raise UnsupportedPlanningError(
'Unable to create "{:s}" planner. Is or_ompl installed?'
.format(planner_name))

def __str__(self):
return 'OMPL_{0:s}'.format(self.algorithm)

@ClonedPlanningMethod
@LockedPlanningMethod
def PlanToConfiguration(self, robot, goal, **kw_args):
"""
Plan to a configuration using the robot's active DOFs.
Expand All @@ -133,7 +126,7 @@ def PlanToConfiguration(self, robot, goal, **kw_args):
"""
return self._Plan(robot, goal=goal, **kw_args)

@ClonedPlanningMethod
@LockedPlanningMethod
def PlanToTSR(self, robot, tsrchains, **kw_args):
"""
Plan to one or more goal TSR chains using the robot's active DOFs. This
Expand Down Expand Up @@ -166,6 +159,15 @@ def _Plan(self, robot, goal=None, tsrchains=None, timelimit=None,

extraParams += '<time_limit>{:f}</time_limit>'.format(timelimit)

env = robot.GetEnv()
planner_name = 'OMPL_{:s}'.format(self.algorithm)
planner = RaveCreatePlanner(env, planner_name)

if planner is None:
raise UnsupportedPlanningError(
'Unable to create "{:s}" planner. Is or_ompl installed?'
.format(planner_name))

# Handle other parameters that get passed directly to OMPL.
if ompl_args is None:
ompl_args = dict()
Expand Down Expand Up @@ -217,16 +219,16 @@ def _Plan(self, robot, goal=None, tsrchains=None, timelimit=None,
params.SetExtraParameters(extraParams)

if (not continue_planner) or (not self.setup):
self.planner.InitPlan(robot, params)
self.setup = True
planner.InitPlan(robot, params)
setup = True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The setup flag is no longer used anywhere.


# Bypass the context manager since or_ompl does its own baking.
env = robot.GetEnv()
robot_checker = self.robot_checker_factory(robot)
options = robot_checker.collision_options
with CollisionOptionsStateSaver(env.GetCollisionChecker(), options):
traj = RaveCreateTrajectory(env, 'GenericTrajectory')
status = self.planner.PlanPath(traj, releasegil=True)
status = planner.PlanPath(traj, releasegil=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be wrapped in a RobotStateSaver that saves robot's LinkTransformations.


if status not in [PlannerStatus.HasSolution,
PlannerStatus.InterruptedWithSolution]:
Expand Down Expand Up @@ -327,7 +329,7 @@ def ComputeRange(self, robot):
# a small value to cope with numerical precision issues inside OMPL.
return multiplier * conservative_resolution - epsilon

@ClonedPlanningMethod
@LockedPlanningMethod
def PlanToConfiguration(self, robot, goal, ompl_args=None, **kw_args):
if ompl_args is None:
ompl_args = dict()
Expand All @@ -336,7 +338,7 @@ def PlanToConfiguration(self, robot, goal, ompl_args=None, **kw_args):

return self._Plan(robot, goal=goal, ompl_args=ompl_args, **kw_args)

@ClonedPlanningMethod
@LockedPlanningMethod
def PlanToTSR(self, robot, tsrchains, ompl_args=None, **kw_args):
if ompl_args is None:
ompl_args = dict()
Expand All @@ -359,21 +361,23 @@ class OMPLSimplifier(BasePlanner):
def __init__(self):
super(OMPLSimplifier, self).__init__()

planner_name = 'OMPL_Simplifier'
self.planner = openravepy.RaveCreatePlanner(self.env, planner_name)

if self.planner is None:
raise UnsupportedPlanningError(
'Unable to create OMPL_Simplifier planner.')

def __str__(self):
return 'OMPL Simplifier'

@ClonedPlanningMethod
@LockedPlanningMethod
def ShortcutPath(self, robot, path, timeout=1., **kwargs):
# The planner operates in-place, so we need to copy the input path. We
# also need to copy the trajectory into the planning environment.
output_path = CopyTrajectory(path, env=self.env)

planner_name = 'OMPL_Simplifier'
env = robot.GetEnv()
planner = openravepy.RaveCreatePlanner(env, planner_name)

if planner is None:
raise UnsupportedPlanningError(
'Unable to create OMPL_Simplifier planner.')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Modify this message use planner_name so this message can't get out of sync with the code.


output_path = CopyTrajectory(path, env=env)

extraParams = '<time_limit>{:f}</time_limit>'.format(timeout)

Expand All @@ -384,8 +388,8 @@ def ShortcutPath(self, robot, path, timeout=1., **kwargs):
# TODO: It would be nice to call planningutils.SmoothTrajectory here,
# but we can't because it passes a NULL robot to InitPlan. This is an
# issue that needs to be fixed in or_ompl.
self.planner.InitPlan(robot, params)
status = self.planner.PlanPath(output_path, releasegil=True)
planner.InitPlan(robot, params)
status = planner.PlanPath(output_path, releasegil=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be wrapped in a RobotStateSaver that saves robot's LinkTransformations.

if status not in [PlannerStatus.HasSolution,
PlannerStatus.InterruptedWithSolution]:
raise PlanningError('Simplifier returned with status {0:s}.'
Expand Down
Loading