29
29
# POSSIBILITY OF SUCH DAMAGE.
30
30
31
31
import functools , logging , openravepy , numpy
32
- import prpy .util
33
- from .. import bind , named_config , planning , util
32
+ from .. import bind , named_config , exceptions , util
34
33
from ..clone import Clone , Cloned
35
34
from ..tsr .tsrlibrary import TSRLibrary
36
35
from ..planning .base import Sequence , Tags
@@ -281,7 +280,7 @@ def do_postprocess():
281
280
# Extract active DOFs from teh trajectory and set them as active.
282
281
dof_indices , _ = cspec .ExtractUsedIndices (self )
283
282
284
- if prpy . util .HasAffineDOFs (cspec ):
283
+ if util .HasAffineDOFs (cspec ):
285
284
affine_dofs = (DOFAffine .X | DOFAffine .Y | DOFAffine .RotationAxis )
286
285
287
286
# Bug in OpenRAVE ExtractUsedIndices function makes
@@ -422,7 +421,7 @@ def ExecuteTrajectory(self, traj, defer=False, timeout=None, period=0.01, **kwar
422
421
will be raised). If timeout is a float (including timeout = 0), this
423
422
function will return None once the timeout has ellapsed, even if the
424
423
trajectory is still being executed.
425
-
424
+
426
425
NOTE: We suggest that you either use timeout=None or defer=True. If
427
426
trajectory execution times out, there is no way to tell whether
428
427
execution was successful or not. Other values of timeout are only
@@ -438,18 +437,39 @@ def ExecuteTrajectory(self, traj, defer=False, timeout=None, period=0.01, **kwar
438
437
@param period poll rate, in seconds, for checking trajectory status
439
438
@return trajectory executed on the robot
440
439
"""
440
+ # Don't execute trajectories that don't have at least one waypoint.
441
+ if traj .GetNumWaypoints () <= 0 :
442
+ raise ValueError ('Trajectory must contain at least one waypoint.' )
443
+
444
+ # Check that the current configuration of the robot matches the
445
+ # initial configuration specified by the trajectory.
446
+ if not util .IsAtTrajectoryStart (self , traj ):
447
+ raise exceptions .TrajectoryAborted (
448
+ 'Trajectory started from different configuration than robot.' )
449
+
450
+ # If there was only one waypoint, at this point we are done!
451
+ if traj .GetNumWaypoints () == 1 :
452
+ if defer is True :
453
+ import trollius
454
+ future = trollius .Future ()
455
+ future .set_result (traj )
456
+ return future
457
+ else :
458
+ return traj
441
459
442
- # TODO: Verify that the trajectory is timed.
443
- # TODO: Check if this trajectory contains the base.
460
+ # Verify that the trajectory is timed.
461
+ if traj .GetDuration () <= 0.0 :
462
+ raise ValueError ('Attempted to execute untimed trajectory.' )
444
463
464
+ # TODO: Check if this trajectory contains the base.
445
465
needs_base = util .HasAffineDOFs (traj .GetConfigurationSpecification ())
446
466
447
467
self .GetController ().SetPath (traj )
448
468
449
469
active_manipulators = self .GetTrajectoryManipulators (traj )
450
470
active_controllers = [
451
- active_manipulator .controller \
452
- for active_manipulator in active_manipulators \
471
+ active_manipulator .controller
472
+ for active_manipulator in active_manipulators
453
473
if hasattr (active_manipulator , 'controller' )
454
474
]
455
475
@@ -485,8 +505,8 @@ def do_poll():
485
505
util .WaitForControllers (active_controllers , timeout = timeout )
486
506
return traj
487
507
else :
488
- raise ValueError ('Received unexpected value "{:s}" for defer.' . format ( str ( defer )))
489
-
508
+ raise ValueError ('Received unexpected value "{:s}" for defer.'
509
+ . format ( str ( defer )))
490
510
491
511
def ViolatesVelocityLimits (self , traj ):
492
512
"""
0 commit comments