-
Notifications
You must be signed in to change notification settings - Fork 19
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
base: master
Are you sure you want to change the base?
Changes from all commits
f490eff
aff4283
8c71662
50b5902
53d04a1
2bc1b2a
0846444
a704149
fdcf7fa
1bd969a
b167c0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2129,3 +2129,75 @@ def GetPointFrom(focus): | |
raise ValueError('Focus of the point is an unknown object') | ||
|
||
return coord | ||
|
||
def ConcatenateTrajectories(robot, traj_list): | ||
""" | ||
Given a list of trajectories for a single manipulator, | ||
concatenate them into a single trajectory | ||
|
||
@param traj_list List of consective trajectories for a given manipulator | ||
@return base_traj Combined trajectory | ||
""" | ||
from planning.base import Tags | ||
|
||
if len(traj_list) == 0: | ||
raise ValueError('Trajectory list is empty') | ||
|
||
env = robot.GetEnv() | ||
|
||
# Create an empty trajectory to populate | ||
base_traj = openravepy.RaveCreateTrajectory(env, '') | ||
base_cspec = robot.GetActiveConfigurationSpecification('linear') | ||
base_traj.Init(base_cspec) | ||
#base_cspec = base_traj.GetConfigurationSpecification() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this. |
||
|
||
smoothFlag = True | ||
constrainedFlag = False | ||
deterministicTrajectoryFlag = True | ||
deterministicEndPointFlag = False | ||
|
||
offset = 0 | ||
for traj in traj_list: | ||
cspec_i = traj.GetConfigurationSpecification() | ||
if base_cspec != cspec_i: | ||
raise ValueError('The configuration specifications of the trajectory do not match') | ||
|
||
tags = GetTrajectoryTags(traj) | ||
# Only True if all trajectories have this set | ||
if 'smooth' in tags and not tags['smooth']: | ||
smoothFlag = False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be skipped if |
||
|
||
# True if any trajectory has this set | ||
if 'constrained' in tags and tags['constrained']: | ||
constrainedFlag = True | ||
|
||
# Only True if all trajectories have this set | ||
if 'deterministic' in tags and not tags['deterministic']: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question. |
||
deterministcTrajectoryFlag = False | ||
|
||
# Check that trajectory leds from previous, | ||
# or if the first, start the trajectory | ||
epsilon = 0.001 | ||
if offset == 0: | ||
base_traj.Insert(offset, traj.GetWaypoint(0)) | ||
offset += 1 | ||
else: | ||
if sum(numpy.subtract(traj.GetWaypoint(0), base_traj.GetWaypoint(offset-1))) > epsilon: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should use |
||
raise ValueError('The trajectories are not consecutive.') | ||
|
||
# Add trajectory in by inserting each waypoint | ||
for j in xrange(1, traj.GetNumWaypoints()): | ||
waypoint = traj.GetWaypoint(j) | ||
base_traj.Insert(offset, waypoint) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
offset += 1 | ||
|
||
# True if the last trajectory has this set | ||
last_tags = GetTrajectoryTags(traj_list[-1]) | ||
if 'deterministic_endpoint' in last_tags and last_tags['determinstic_endpoint']: | ||
deterministicEndPointFlag = True | ||
|
||
flagSettings = {Tags.SMOOTH: smoothFlag, Tags.CONSTRAINED: constrainedFlag, | ||
Tags.DETERMINISTIC_TRAJECTORY: deterministicTrajectoryFlag, | ||
Tags.DETERMINISTIC_ENDPOINT: deterministicEndPointFlag} | ||
SetTrajectoryTags(base_traj, flagSettings, append=True) | ||
return base_traj |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1088,6 +1088,26 @@ def test_GetMinDistanceBetweenTransformAndWorkspaceTraj(self): | |
numpy.testing.assert_array_almost_equal(T_loc, expected_T_loc, decimal=7, \ | ||
err_msg=error, verbose=True) | ||
|
||
def test_ConcatenateTrajectories(self): | ||
q0 = self.robot.GetDOFValues(self.active_dof_indices).tolist() | ||
q1 = [0.02, 0.01, 0.02, 0.01, 0.01, 0.01, 0.0] | ||
q2 = [0.50, 0.30, 0.02, 0.01, 0.01, 0.01, 0.0] | ||
traj1 = self.CreateTrajectory(q0, q1) | ||
traj2 = self.CreateTrajectory(q1, q2) | ||
combined_traj = prpy.util.ConcatenateTrajectories(self.robot, [traj1, traj2]) | ||
|
||
combined_waypoints = numpy.zeros((combined_traj.GetNumWaypoints(), 7)) | ||
for j in xrange(combined_traj.GetNumWaypoints()): | ||
combined_waypoints[j] = combined_traj.GetWaypoint(j) | ||
all_waypoints = [q0, q1, q2] | ||
|
||
error = 'The waypoints on the trajectory do not match the individual waypoints' | ||
numpy.testing.assert_array_almost_equal(combined_waypoints, | ||
all_waypoints, | ||
decimal=4, | ||
err_msg=error, | ||
verbose=True) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add tests for checking tags? E.g. when one of the tags along the trajectory is not smooth, etc. |
||
|
||
class Test_GetPointFrom(unittest.TestCase): | ||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this to be linear? Also, why are we requiring that the trajectories have to be on the current active dofs? Shouldn't it just be the spec of the first trajectory?