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

Feature/concatenate trajs #354

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Concatenating trajectory, check all flags and match cspecs
Rachel committed Sep 14, 2016
commit 2bc1b2adcd8246a92670d3fb6ee2f16256a82b0c
41 changes: 26 additions & 15 deletions src/prpy/util.py
Original file line number Diff line number Diff line change
@@ -2130,7 +2130,7 @@ def GetPointFrom(focus):

return coord

def concatenateTrajectories(traj_list):
def ConcatenateTrajectories(traj_list):
"""
Given a list of trajectories for a single manipulator,
concatenate them into a single trajectory
@@ -2145,34 +2145,45 @@ def concatenateTrajectories(traj_list):

base_traj = traj_list[0]
base_cspec = base_traj.GetConfigurationSpecification()
base_robot = base_cspec.ExtractUsedBodies(base_traj.GetEnv())[0]
traj_indices = GetTrajectoryIndices(base_traj)

smoothFlag = True
constrainedFlag = False
deterministicTrajectoryFlag = True
deterministicEndPointFlag = False

offset = base_traj.GetNumWaypoints()
for i in xrange(1, len(traj_list)):
traj_i = traj_list[i]
cspec_i = traj_i.GetConfigurationSpecification()
robot_i = cspec_i.ExtractUsedBodies(traj_i.GetEnv())[0]
if robot_i != base_robot:
raise ValueError('Trajectories are not on the same robot')

sub = numpy.subtract(GetTrajectoryIndices(traj_i), traj_indices)
if sub.sum() != 0:
raise ValueError('Trajectories are not on the same manipulator.')
cspec_i = traj_i.GetConfigurationSpecification()
if base_cspec != cspec_i:
raise ValueError('The configuration specifications of the trajectory do not match')

tags_i = GetTrajectoryTags(traj_i)
# If one segment is not smooth, the entire trajectory is not (?)
# Only True if all trajectories have this set
if 'smooth' in tags_i and not tags_i['smooth']:
SetTrajectoryTags(base_traj, {TAGS.SMOOTH: True}, append=True)
smoothFlag = False
Copy link
Contributor

Choose a reason for hiding this comment

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

This would be skipped if smooth is not in tags. Is smooth by default true?


# The entire trajectory gets tagged as constrained if one of
# the segments is constrained.
# True if any trajectory has this set
if 'constrained' in tags_i and tags_i['constrained']:
SetTrajectoryTags(base_traj, {TAGS.CONSTRAINED: True}, append=True)
constrainedFlag = True

# Only True if all trajectories have this set
if 'deterministic' in tags_i and not tags_i['deterministic']:
deterministcTrajectoryFlag = False

# True if the last trajectory has this set
if i == len(traj_list)-1 and 'deterministic_endpoint' in tags_i and tags_i['determinstic_endpoint']:
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be cleaner to do this outside of the loop?

deterministicEndPointFlag = True

# Add trajectory in by inserting each waypoint
for j in xrange(traj_i.GetNumWaypoints()):
waypoint = traj_i.GetWaypoint(j)
base_traj.Insert(offset, waypoint)
Copy link
Member

Choose a reason for hiding this comment

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

For example, this would break if the trajectories did not already have the same ConfigurationSpecification.

offset += 1

flagSettings = {TAGS.SMOOTH: smoothFlag, TAGS.CONSTRAINED: constrainedFlag,
TAGS.DETERMINISTIC_TRAJECTORY: deterministicTrajectoryFlag,
TAGS.DETERMINISTIC_ENDPOINT: deterministicEndPointFlag}
SetTrajectoryTags(base_traj, flagSettings, append=True)
return base_traj