Skip to content

Commit 8478bd2

Browse files
committed
Removing need for ExecuteBasePath. Instead base planning now uses ExecutePath.
1 parent 7c19f04 commit 8478bd2

File tree

3 files changed

+42
-54
lines changed

3 files changed

+42
-54
lines changed

src/prpy/base/mobilebase.py

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import copy, functools, numpy, openravepy
3232
from .. import bind
3333
from prpy.clone import Clone
34-
from ..planning.retimer import OpenRAVEAffineRetimer
3534

3635
def create_affine_trajectory(robot, poses):
3736
doft = openravepy.DOFAffine.X | openravepy.DOFAffine.Y | openravepy.DOFAffine.RotationAxis
@@ -51,8 +50,6 @@ def __init__(self, sim, robot):
5150
self.simulated = sim
5251
self.robot = robot
5352

54-
self.retimer = OpenRAVEAffineRetimer()
55-
5653
def __dir__(self):
5754
# Add planning methods to the tab-completion list.
5855
method_names = set(self.__dict__.keys())
@@ -95,9 +92,9 @@ def Forward(self, meters, execute=True, direction=None, **kw_args):
9592
offset_pose[0:3, 3] = meters * direction
9693
goal_pose = numpy.dot(start_pose, offset_pose)
9794

98-
traj = create_affine_trajectory(self.robot, [ start_pose, goal_pose ])
95+
path = create_affine_trajectory(self.robot, [ start_pose, goal_pose ])
9996
if execute:
100-
return self.ExecuteBasePath(traj, **kw_args)
97+
return self.robot.ExecutePath(path, **kw_args)
10198
else:
10299
return traj
103100
else:
@@ -116,9 +113,9 @@ def Rotate(self, angle_rad, execute=True, **kw_args):
116113
relative_pose = openravepy.matrixFromAxisAngle([ 0., 0., angle_rad ])
117114
goal_pose = numpy.dot(start_pose, relative_pose)
118115

119-
traj = create_affine_trajectory(self.robot, [ start_pose, goal_pose ])
116+
path = create_affine_trajectory(self.robot, [ start_pose, goal_pose ])
120117
if execute:
121-
return self.ExecuteBasePath(traj, **kw_args)
118+
return self.robot.ExecutePath(path, **kw_args)
122119
else:
123120
return traj
124121
else:
@@ -147,6 +144,7 @@ def DriveStraightUntilForce(self, direction, velocity=0.1, force_threshold=3.0,
147144
raise NotImplementedError('DriveStraightUntilForce is not implemented')
148145

149146
def _BasePlanWrapper(self, planning_method, args, kw_args):
147+
150148
robot = self.robot
151149
with Clone(robot.GetEnv()) as cloned_env:
152150
cloned_robot = cloned_env.Cloned(robot)
@@ -169,41 +167,7 @@ def _BasePlanWrapper(self, planning_method, args, kw_args):
169167

170168
# Optionally execute the trajectory.
171169
if 'execute' not in kw_args or kw_args['execute']:
172-
return self.ExecuteBasePath(traj, **kw_args)
170+
return self.robot.ExecutePath(traj, **kw_args)
173171
else:
174172
return traj
175-
176-
def ExecuteBasePath(self, path, defer=False, **kwargs):
177-
178-
def do_execute(path, **kwargs):
179-
robot = self.robot
180-
with Clone(robot.GetEnv()) as cloned_env:
181-
182-
cloned_robot = cloned_env.Cloned(robot)
183-
cloned_robot.SetActiveDOFs(
184-
[],
185-
affine=(openravepy.DOFAffine.X |
186-
openravepy.DOFAffine.Y |
187-
openravepy.DOFAffine.RotationAxis)
188-
)
189-
190-
cloned_timed_traj = self.retimer.RetimeTrajectory(cloned_robot, path, defer=False, **kwargs)
191-
192-
# Copy the trajectory back to the original environment.
193-
from ..util import CopyTrajectory
194-
timed_traj = CopyTrajectory(cloned_timed_traj, env=robot.GetEnv())
195-
196-
return robot.ExecuteTrajectory(timed_traj, defer=False, **kwargs)
197-
198-
if defer:
199-
from trollius.executor import get_default_executor
200-
from trollius.futures import wrap_future
201-
202-
executor = kwargs.get('executor') or get_default_executor()
203-
return wrap_future(
204-
executor.submit(do_execute,
205-
path, **kwargs
206-
)
207-
)
208-
else:
209-
return do_execute(path, **kwargs)
173+

src/prpy/base/robot.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from ..tsr.tsrlibrary import TSRLibrary
3636
from ..planning.base import Sequence
3737
from ..planning.ompl import OMPLSimplifier
38-
from ..planning.retimer import HauserParabolicSmoother, ParabolicRetimer
38+
from ..planning.retimer import HauserParabolicSmoother, OpenRAVEAffineRetimer, ParabolicRetimer
3939
from ..planning.mac_smoother import MacSmoother
4040

4141
logger = logging.getLogger('robot')
@@ -73,6 +73,7 @@ def __init__(self, robot_name=None):
7373
HauserParabolicSmoother(),
7474
self.retimer
7575
)
76+
self.affine_retimer = OpenRAVEAffineRetimer()
7677

7778
def __dir__(self):
7879
# We have to manually perform a lookup in InstanceDeduplicator because
@@ -259,19 +260,32 @@ def do_postprocess():
259260
# in the trajectory as active.
260261
env = path.GetEnv()
261262
cspec = path.GetConfigurationSpecification()
263+
262264
used_bodies = cspec.ExtractUsedBodies(env)
263265
if self not in used_bodies:
264266
raise ValueError(
265267
'Robot "{:s}" is not in the trajectory.'.format(
266268
self.GetName()))
267269

268-
dof_indices, _ = cspec.ExtractUsedIndices(self)
269-
cloned_robot.SetActiveDOFs(dof_indices)
270-
logger.debug(
271-
'Setting robot "%s" DOFs %s as active for post-processing.',
272-
cloned_robot.GetName(), list(dof_indices))
273-
274-
# TODO: Handle a affine DOF trajectories for the base.
270+
# Check for affine dofs in the path
271+
has_affine_dofs = prpy.util.HasAffineDOFs(cspec)
272+
273+
if has_affine_dofs:
274+
cloned_robot.SetActiveDOFs(
275+
[],
276+
affine=(openravepy.DOFAffine.X |
277+
openravepy.DOFAffine.Y |
278+
openravepy.DOFAffine.RotationAxis)
279+
)
280+
logger.debug(
281+
' Setting robot "%s" affine DOFs as active for post-processing.',
282+
cloned_robot.GetName())
283+
else:
284+
dof_indices, _ = cspec.ExtractUsedIndices(self)
285+
cloned_robot.SetActiveDOFs(dof_indices)
286+
logger.debug(
287+
'Setting robot "%s" DOFs %s as active for post-processing.',
288+
cloned_robot.GetName(), list(dof_indices))
275289

276290
# Directly compute a timing of smooth trajectories.
277291
if smooth:
@@ -286,7 +300,11 @@ def do_postprocess():
286300
if constrained:
287301
logger.debug('Retiming a constrained path. The output'
288302
' trajectory will stop at every waypoint.')
289-
traj = self.retimer.RetimeTrajectory(
303+
if has_affine_dofs:
304+
retimer = self.affine_retimer
305+
else:
306+
retimer = self.retimer
307+
traj = retimer.RetimeTrajectory(
290308
cloned_robot, path, defer=False, **retiming_options)
291309
else:
292310
# The trajectory is not constrained, so we can shortcut it
@@ -301,7 +319,11 @@ def do_postprocess():
301319
shortcut_path = path
302320

303321
logger.debug('Smoothing an unconstrained path.')
304-
traj = self.smoother.RetimeTrajectory(
322+
if has_affine_dofs:
323+
smoother = self.affine_retimer
324+
else:
325+
smoother = self.smoother
326+
traj = smoother.RetimeTrajectory(
305327
cloned_robot, shortcut_path, defer=False,
306328
**smoothing_options)
307329

src/prpy/planning/sbpl.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2929
# POSSIBILITY OF SUCH DAMAGE.
3030

31-
from base import BasePlanner, PlanningError, PlanningMethod, UnsupportedPlanningError
31+
from ..util import SetTrajectoryTags
32+
from base import BasePlanner, PlanningError, PlanningMethod, UnsupportedPlanningError, Tags
3233
import openravepy
3334

3435
class SBPLPlanner(BasePlanner):
@@ -108,5 +109,6 @@ def PlanToBasePose(self, robot, goal_pose, timelimit=60.0, return_first=False, *
108109
if status not in [ PlannerStatus.HasSolution, PlannerStatus.InterruptedWithSolution ]:
109110
raise PlanningError('Planner returned with status {0:s}.'.format(str(status)))
110111

112+
SetTrajectoryTags(traj, {Tags.SMOOTH: True}, append=True)
111113
return traj
112114

0 commit comments

Comments
 (0)