Skip to content

Commit 482716e

Browse files
committed
Merge branch 'master' of https://github.com/personalrobotics/prpy into bugfix/cloning_race
2 parents cdde97d + b063607 commit 482716e

File tree

18 files changed

+743
-45
lines changed

18 files changed

+743
-45
lines changed

src/prpy/base/robot.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
from ..planning.mac_smoother import MacSmoother
4040
from ..util import SetTrajectoryTags
4141

42-
logger = logging.getLogger('robot')
42+
logger = logging.getLogger(__name__)
43+
4344

4445
class Robot(openravepy.Robot):
4546
def __init__(self, robot_name=None):
@@ -570,7 +571,7 @@ def defer_trajectory(traj_future, kw_args):
570571
postprocess_trajectory(traj)
571572

572573
# Optionally execute the trajectory.
573-
if kw_args.get('execute', True):
574+
if kw_args.get('execute', False):
574575
# We know defer = True if we're in this function, so we
575576
# don't have to set it explicitly.
576577
traj = yield trollius.From(
@@ -584,7 +585,7 @@ def defer_trajectory(traj_future, kw_args):
584585
postprocess_trajectory(result)
585586

586587
# Optionally execute the trajectory.
587-
if kw_args.get('execute', True):
588+
if kw_args.get('execute', False):
588589
result = self.ExecutePath(result, **kw_args)
589590

590591
return result

src/prpy/bind.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@
3131
import logging
3232
from clone import CloneException
3333

34-
logger = logging.getLogger('bind')
34+
logger = logging.getLogger(__name__)
35+
3536

3637
class NotCloneableException(CloneException):
3738
pass
3839

40+
3941
class InstanceDeduplicator(object):
40-
logger = logging.getLogger('bind')
4142
USERDATA_PREFIX = 0xDEADBEEF
4243
USERDATA_CHILDREN = '__children__'
4344
USERDATA_DESTRUCTOR = '__destructor__'
@@ -209,11 +210,11 @@ def cleanup_callback(owner, flag):
209210
# skipped
210211
while children:
211212
child = children.pop()
212-
InstanceDeduplicator.logger.debug(child)
213+
logger.debug(child)
213214
clear_referrers(child)
214215
# NOTE: this is also an acceptable body for the loop :)
215216
# clear_referrers(children[0])
216-
InstanceDeduplicator.logger.debug(owner)
217+
logger.debug(owner)
217218
if canonical_instance != None:
218219
clear_referrers(canonical_instance)
219220

@@ -233,7 +234,7 @@ def get_storage_methods(cls, target):
233234
handle = env.RegisterBodyCallback(InstanceDeduplicator.cleanup_callback)
234235
user_data[cls.USERDATA_DESTRUCTOR] = handle
235236
else:
236-
cls.logger.warning(
237+
logger.warning(
237238
'Your version of OpenRAVE does not supply Python bindings'
238239
' for Environment.RegisterBodyCallback. PrPy will leak'
239240
' unless you call prpy.bind.InstanceDeduplicator.remove_storage'

src/prpy/exceptions.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,30 @@ class SynchronizationException(PrPyException):
1717
"""
1818
Controller synchronization failed.
1919
"""
20+
21+
class SerializationException(PrPyException):
22+
"""
23+
Serialization failed.
24+
"""
25+
26+
class UnsupportedTypeSerializationException(SerializationException):
27+
"""
28+
Serialization failed due to an unknown type.
29+
"""
30+
def __init__(self, value):
31+
self.value = value
32+
self.type = type(self.value)
33+
34+
super(UnsupportedTypeSerializationException, self).__init__(
35+
'Serializing type "{:s}.{:s}" is not supported.'.format(
36+
self.type.__module__, self.type.__name__))
37+
38+
class UnsupportedTypeDeserializationException(SerializationException):
39+
"""
40+
Deserialization failed due to an unknown type.
41+
"""
42+
def __init__(self, type_name):
43+
self.type_name = type_name
44+
45+
super(UnsupportedTypeDeserializationException, self).__init__(
46+
'Deserializing type "{:s}" is not supported.'.format(type_name))

src/prpy/planning/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
from ..util import CopyTrajectory, GetTrajectoryTags, SetTrajectoryTags
3838
from .exceptions import PlanningError, UnsupportedPlanningError
3939

40-
logger = logging.getLogger('planning')
40+
logger = logging.getLogger(__name__)
4141

4242

4343
class Tags(object):
@@ -49,6 +49,7 @@ class Tags(object):
4949
POSTPROCESS_TIME = 'postprocess_time'
5050
EXECUTION_TIME = 'execution_time'
5151

52+
5253
class MetaPlanningError(PlanningError):
5354
def __init__(self, message, errors):
5455
PlanningError.__init__(self, message)

src/prpy/planning/chomp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
PlanningMethod, Tags)
3939
import prpy.tsr
4040

41-
logger = logging.getLogger('prpy.planning.chomp')
41+
logger = logging.getLogger(__name__)
4242

4343
DistanceFieldKey = collections.namedtuple('DistanceFieldKey',
4444
[ 'kinematics_hash', 'enabled_mask', 'dof_values', 'dof_indices' ])

src/prpy/planning/ik.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
PlanningError,
3636
PlanningMethod)
3737

38-
logger = logging.getLogger('prpy.planning.ik')
38+
logger = logging.getLogger(__name__)
3939

4040

4141
class IKPlanner(BasePlanner):

src/prpy/planning/mk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from base import (BasePlanner, PlanningError, UnsupportedPlanningError,
3434
PlanningMethod, Tags)
3535

36-
logger = logging.getLogger('planning')
36+
logger = logging.getLogger(__name__)
3737

3838
def DoNothing(robot):
3939
return numpy.zeros(robot.GetActiveDOF())

src/prpy/planning/ompl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
from ..util import CopyTrajectory, SetTrajectoryTags
3333
from base import (BasePlanner, PlanningError, UnsupportedPlanningError,
3434
PlanningMethod, Tags)
35-
from openravepy import PlannerStatus
35+
from openravepy import PlannerStatus
3636

37-
logger = logging.getLogger('pypy.planning.ompl')
37+
logger = logging.getLogger(__name__)
3838

3939

4040
class OMPLPlanner(BasePlanner):

src/prpy/planning/retimer.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@
3131
import logging, numpy, openravepy, os, tempfile
3232
from ..util import CopyTrajectory, SimplifyTrajectory, HasAffineDOFs
3333
from base import BasePlanner, PlanningError, PlanningMethod, UnsupportedPlanningError
34-
from openravepy import PlannerStatus
34+
from openravepy import PlannerStatus
35+
36+
logger = logging.getLogger(__name__)
3537

36-
logger = logging.getLogger('retimer')
3738

3839
class OpenRAVERetimer(BasePlanner):
3940
def __init__(self, algorithm, default_options=None):
@@ -141,7 +142,7 @@ def __init__(self, **kwargs):
141142

142143
class HauserParabolicSmoother(OpenRAVERetimer):
143144
def __init__(self, do_blend=True, do_shortcut=True, blend_radius=0.5,
144-
blend_iterations=4, **kwargs):
145+
blend_iterations=0, timelimit=3., **kwargs):
145146
super(HauserParabolicSmoother, self).__init__(
146147
'HauserParabolicSmoother', **kwargs)
147148

@@ -150,6 +151,7 @@ def __init__(self, do_blend=True, do_shortcut=True, blend_radius=0.5,
150151
'do_shortcut': int(do_shortcut),
151152
'blend_radius': float(blend_radius),
152153
'blend_iterations': int(blend_iterations),
154+
'time_limit': float(timelimit),
153155
})
154156

155157

src/prpy/planning/snap.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#
77
# Redistribution and use in source and binary forms, with or without
88
# modification, are permitted provided that the following conditions are met:
9-
#
9+
#
1010
# - Redistributions of source code must retain the above copyright notice, this
1111
# list of conditions and the following disclaimer.
1212
# - Redistributions in binary form must reproduce the above copyright notice,
@@ -15,7 +15,7 @@
1515
# - Neither the name of Carnegie Mellon University nor the names of its
1616
# contributors may be used to endorse or promote products derived from this
1717
# software without specific prior written permission.
18-
#
18+
#
1919
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2020
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2121
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -32,6 +32,7 @@
3232
from ..util import SetTrajectoryTags
3333
from base import BasePlanner, PlanningError, PlanningMethod, Tags
3434

35+
3536
class SnapPlanner(BasePlanner):
3637
"""Planner that checks the straight-line trajectory to the goal.
3738
@@ -40,15 +41,15 @@ class SnapPlanner(BasePlanner):
4041
due to an environment or self collision, the planner immediately returns
4142
failure by raising a PlanningError. Collision checking is performed using
4243
the standard CheckPathAllConstraints method.
43-
44+
4445
SnapPlanner is intended to be used only as a "short circuit" to speed up
4546
planning between nearby configurations. This planner is most commonly used
4647
as the first item in a Sequence meta-planner to avoid calling a motion
4748
planner when the trivial solution is valid.
4849
"""
4950
def __init__(self):
5051
super(SnapPlanner, self).__init__()
51-
52+
5253
def __str__(self):
5354
return 'SnapPlanner'
5455

@@ -86,7 +87,6 @@ def PlanToEndEffectorPose(self, robot, goal_pose, **kw_args):
8687
# close to the configuration of the arm, so we don't need to do any
8788
# custom IK ranking.
8889
manipulator = robot.GetActiveManipulator()
89-
current_config = robot.GetDOFValues(manipulator.GetArmIndices())
9090
ik_param = openravepy.IkParameterization(goal_pose, ikp.Transform6D)
9191
ik_solution = manipulator.FindIKSolution(
9292
ik_param, ikfo.CheckEnvCollisions,
@@ -101,7 +101,7 @@ def PlanToEndEffectorPose(self, robot, goal_pose, **kw_args):
101101
def _Snap(self, robot, goal, **kw_args):
102102
Closed = openravepy.Interval.Closed
103103

104-
curr = robot.GetActiveDOFValues()
104+
start = robot.GetActiveDOFValues()
105105
active_indices = robot.GetActiveDOFIndices()
106106

107107
# Use the CheckPathAllConstraints helper function to collision check
@@ -110,28 +110,32 @@ def _Snap(self, robot, goal, **kw_args):
110110
params = openravepy.Planner.PlannerParameters()
111111
params.SetRobotActiveJoints(robot)
112112
params.SetGoalConfig(goal)
113-
check = params.CheckPathAllConstraints(curr, goal, [], [], 0., Closed)
113+
check = params.CheckPathAllConstraints(start, goal, [], [], 0., Closed)
114114

115115
# The function returns a bitmask of ConstraintFilterOptions flags,
116116
# indicating which constraints are violated. We'll abort if any
117117
# constraints are violated.
118118
if check != 0:
119119
raise PlanningError('Straight line trajectory is not valid.')
120120

121-
# Create a two-point trajectory that starts at our current
122-
# configuration and takes us to the goal.
123-
traj = openravepy.RaveCreateTrajectory(self.env, '')
121+
# Create a trajectory that starts at our current configuration.
124122
cspec = robot.GetActiveConfigurationSpecification()
125-
active_indices = robot.GetActiveDOFIndices()
123+
traj = openravepy.RaveCreateTrajectory(self.env, '')
124+
traj.Init(cspec)
126125

127-
waypoints = numpy.zeros((2, cspec.GetDOF()))
128-
cspec.InsertJointValues(waypoints[0, :], curr, robot,
129-
active_indices, False)
130-
cspec.InsertJointValues(waypoints[1, :], goal, robot,
126+
start_waypoint = numpy.zeros(cspec.GetDOF())
127+
cspec.InsertJointValues(start_waypoint, start, robot,
131128
active_indices, False)
129+
traj.Insert(0, start_waypoint.ravel())
132130

133-
traj.Init(cspec)
134-
traj.Insert(0, waypoints.ravel())
131+
# Make the trajectory end at the goal configuration, as long as it
132+
# was not identical to the start configuration.
133+
if not numpy.allclose(start, goal):
134+
goal_waypoint = numpy.zeros(cspec.GetDOF())
135+
cspec.InsertJointValues(goal_waypoint, goal, robot,
136+
active_indices, False)
137+
traj.Insert(1, goal_waypoint.ravel())
135138

139+
# Tag the return trajectory as smooth (in joint space) and return it.
136140
SetTrajectoryTags(traj, {Tags.SMOOTH: True}, append=True)
137141
return traj

0 commit comments

Comments
 (0)