@@ -295,6 +295,92 @@ def CopyTrajectory(traj, env=None):
295
295
return copy_traj
296
296
297
297
298
+ def GetTrajectoryHead (trajectory , t_split ):
299
+ """
300
+ Split the given trajectory at the given time and return the head.
301
+
302
+ The head trajectory is a partial copy of the original.
303
+
304
+ @param trajectory the trajectory that will be split
305
+ @param t_split the time at which to split the trajectory
306
+ @return a trajectory that goes from t=0 to t=split
307
+ """
308
+ if not IsTimedTrajectory (trajectory ):
309
+ raise ValueError ("Cannot split untimed trajectory at a time." )
310
+
311
+ if not (0. <= t_split <= trajectory .GetDuration ()):
312
+ raise ValueError ("Cannot split trajectory of duration {:f} at t={:f}."
313
+ .format (trajectory .GetDuration (), t_split ))
314
+
315
+ # Find the intermediate point and index of the split time.
316
+ split_waypoint = trajectory .Sample (t_split )
317
+ split_idx = trajectory .GetFirstWaypointIndexAfterTime (t_split )
318
+
319
+ # Create a trajectory from the beginning to the split.
320
+ head = openravepy .RaveCreateTrajectory (trajectory .GetEnv (),
321
+ trajectory .GetXMLId ())
322
+ head .Init (trajectory .GetConfigurationSpecification ())
323
+ head .Insert (0 , trajectory .GetWaypoints (0 , split_idx ))
324
+ head .Insert (head .GetNumWaypoints (), split_waypoint )
325
+ return head
326
+
327
+
328
+ def GetTrajectoryTail (trajectory , t_split ):
329
+ """
330
+ Split the given trajectory at the given time and returns the tail.
331
+
332
+ The tail trajectory is a partial copy of the original.
333
+
334
+ @param trajectory the trajectory that will be split
335
+ @param t_split the time at which to split the trajectory
336
+ @return a trajectory that goes from t=split to t=end
337
+ """
338
+ if not IsTimedTrajectory (trajectory ):
339
+ raise ValueError ("Cannot split untimed trajectory at a time." )
340
+
341
+ if not (0. <= t_split <= trajectory .GetDuration ()):
342
+ raise ValueError ("Cannot split trajectory of duration {:f} at t={:f}."
343
+ .format (trajectory .GetDuration (), t_split ))
344
+
345
+ # Find the intermediate point and index of the split time.
346
+ split_waypoint = trajectory .Sample (t_split )
347
+ split_idx = trajectory .GetFirstWaypointIndexAfterTime (t_split )
348
+
349
+ # Correct for the delta-time offset of the split waypoint.
350
+ cspec = trajectory .GetConfigurationSpecification ()
351
+ split_delta = cspec .ExtractDeltaTime (split_waypoint )
352
+ cspec .InsertDeltaTime (split_waypoint , 0. )
353
+
354
+ # Create a trajectory from the split to the end.
355
+ tail = openravepy .RaveCreateTrajectory (trajectory .GetEnv (),
356
+ trajectory .GetXMLId ())
357
+ tail .Init (trajectory .GetConfigurationSpecification ())
358
+ tail .Insert (0 , split_waypoint )
359
+ tail .Insert (1 , trajectory .GetWaypoints (split_idx ,
360
+ trajectory .GetNumWaypoints ()))
361
+
362
+ # Correct the delta-time of the first waypoint in the tail.
363
+ waypoint = tail .GetWaypoint (1 )
364
+ waypoint_delta = cspec .ExtractDeltaTime (waypoint )
365
+ cspec .InsertDeltaTime (waypoint , waypoint_delta - split_delta )
366
+ tail .Insert (1 , waypoint , True )
367
+ return tail
368
+
369
+
370
+ def SplitTrajectory (trajectory , t_split ):
371
+ """
372
+ Split the given trajectory at the given time and returns the head and tail.
373
+
374
+ The head and tail trajectories are copies of the original.
375
+
376
+ @param trajectory the trajectory that will be split
377
+ @param t_split the time at which to split the trajectory
378
+ @return a trajectory tuple of (head, tail)
379
+ """
380
+ return (GetTrajectoryHead (trajectory , t_split ),
381
+ GetTrajectoryTail (trajectory , t_split ))
382
+
383
+
298
384
def GetTrajectoryTags (traj ):
299
385
""" Read key/value pairs from a trajectory.
300
386
@@ -1137,6 +1223,7 @@ def ComputeEnabledAABB(kinbody):
1137
1223
half_extents = (max_corner - min_corner ) / 2.
1138
1224
return AABB (center , half_extents )
1139
1225
1226
+
1140
1227
def UntimeTrajectory (trajectory , env = None ):
1141
1228
"""
1142
1229
Returns an untimed copy of the provided trajectory.
@@ -1617,7 +1704,7 @@ def GetLinearCollisionCheckPts(robot, traj, norm_order=2, sampling_func=None):
1617
1704
inf ==> The L_infinity norm
1618
1705
@param generator sampling_func A function that returns a sequence of
1619
1706
sample times.
1620
- e.g. SampleTimeGenerator()
1707
+ e.g. SampleTimeGenerator()
1621
1708
or
1622
1709
VanDerCorputSampleGenerator()
1623
1710
@@ -1684,7 +1771,7 @@ def GetLinearCollisionCheckPts(robot, traj, norm_order=2, sampling_func=None):
1684
1771
q1 = traj_cspec .ExtractJointValues (waypoint , robot , dof_indices )
1685
1772
dq = numpy .abs (q1 - q0 )
1686
1773
max_diff_float = numpy .max ( numpy .abs (q1 - q0 ) / q_resolutions )
1687
-
1774
+
1688
1775
# Get the number of steps (as a float) required for
1689
1776
# each joint at DOF resolution
1690
1777
num_steps = dq / q_resolutions
@@ -1717,7 +1804,7 @@ def GetLinearCollisionCheckPts(robot, traj, norm_order=2, sampling_func=None):
1717
1804
1718
1805
# Sample the trajectory using the specified sample generator
1719
1806
seq = None
1720
- if sampling_func == None :
1807
+ if sampling_func is None :
1721
1808
# (default) Linear sequence, from start to end
1722
1809
seq = SampleTimeGenerator (0 , traj_duration , step = 2 )
1723
1810
else :
0 commit comments