-
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/mimic traj #361
Open
rachelholladay
wants to merge
6
commits into
master
Choose a base branch
from
feature/mimic_traj
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature/mimic traj #361
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
11c71ee
Initial mimic traj support, broken
32e24d0
Merge branch 'master' into feature/mimic_traj
jeking04 df38aa6
Updating cbirrt to work with contrained trajectories. Fixed TSR seria…
jeking04 8cd1fee
Merge remote-tracking branch 'origin/master' into feature/mimic_traj
eb399c9
Clean up some comments
1b62201
Comment regarding checking joint goals
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ def __init__(self, robot_checker_factory=None, timelimit=5.): | |
super(CBiRRTPlanner, self).__init__() | ||
|
||
self.timelimit = timelimit | ||
self.mimic_trajectories = {} | ||
|
||
if robot_checker_factory is None: | ||
robot_checker_factory = DefaultRobotCollisionCheckerFactory | ||
|
@@ -163,7 +164,7 @@ def PlanToTSR(self, robot, tsr_chains, smoothingitrs=100, **kw_args): | |
|
||
def Plan(self, robot, smoothingitrs=None, timelimit=None, allowlimadj=0, | ||
jointstarts=None, jointgoals=None, psample=None, tsr_chains=None, | ||
extra_args=None, **kw_args): | ||
extra_args=None, save_mimic_trajectories=False, **kw_args): | ||
""" | ||
@param allowlimadj If True, adjust the joint limits to include | ||
the robot's start configuration | ||
|
@@ -195,11 +196,6 @@ def Plan(self, robot, smoothingitrs=None, timelimit=None, allowlimadj=0, | |
args = ['RunCBiRRT'] | ||
args += ['timelimit', str(timelimit)] | ||
|
||
# By default, CBiRRT interprets the DOF resolutions as an | ||
# L-infinity norm; this flag turns on the L-2 norm instead. | ||
args += ['bdofresl2norm', '1'] | ||
args += ['steplength', '0.05999'] | ||
|
||
if self._is_baked: | ||
args += ['bbakedcheckers', '1'] | ||
|
||
|
@@ -234,25 +230,35 @@ def Plan(self, robot, smoothingitrs=None, timelimit=None, allowlimadj=0, | |
robot.GetActiveDOF(), len(start_config) | ||
) | ||
) | ||
|
||
args += (['jointstarts'] + | ||
self.serialize_dof_values(start_config)) | ||
|
||
|
||
#TODO need to change robot.GetActiveDOF() to something else | ||
# That can take into account another robot | ||
|
||
#FIXME Ordinally we perform this check. However it assumes that | ||
# we are only planning for the robot, which is not true | ||
# if we are planning a constrained task with an object | ||
# (ie opening a door). I'm unsure how to modify this check | ||
# to account for that. | ||
if jointgoals is not None: | ||
for goal_config in jointgoals: | ||
''' | ||
if len(goal_config) != robot.GetActiveDOF(): | ||
raise ValueError( | ||
'Incorrect number of DOFs in goal configuration;' | ||
' expected {:d}, got {:d}'.format( | ||
robot.GetActiveDOF(), len(goal_config) | ||
) | ||
) | ||
|
||
''' | ||
args += ['jointgoals'] + self.serialize_dof_values(goal_config) | ||
|
||
|
||
if len(jointgoals) > 1: | ||
is_endpoint_deterministic = False | ||
|
||
raw_input("Continue?") | ||
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 needs to be removed. |
||
if tsr_chains is not None: | ||
for tsr_chain in tsr_chains: | ||
args += ['TSRChain', SerializeTSRChain(tsr_chain)] | ||
|
@@ -262,6 +268,11 @@ def Plan(self, robot, smoothingitrs=None, timelimit=None, allowlimadj=0, | |
if tsr_chain.constrain: | ||
is_constrained = True | ||
|
||
# By default, CBiRRT interprets the DOF resolutions as an | ||
# L-infinity norm; this flag turns on the L-2 norm instead. | ||
args += ['bdofresl2norm', '1'] | ||
args += ['steplength', '0.05999'] | ||
|
||
# FIXME: Why can't we write to anything other than cmovetraj.txt or | ||
# /tmp/cmovetraj.txt with CBiRRT? | ||
traj_path = 'cmovetraj.txt' | ||
|
@@ -287,6 +298,8 @@ def Plan(self, robot, smoothingitrs=None, timelimit=None, allowlimadj=0, | |
contextlib.nested(*mimicbody_savers), save_dof_limits(robot): | ||
response = problem.SendCommand(args_str, True) | ||
|
||
with CollisionOptionsStateSaver(env.GetCollisionChecker(), options): | ||
response = problem.SendCommand(args_str, 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. This block is redundant. See line 299. |
||
|
||
if not response.strip().startswith('1'): | ||
raise PlanningError('Unknown error: ' + response, | ||
|
@@ -298,6 +311,28 @@ def Plan(self, robot, smoothingitrs=None, timelimit=None, allowlimadj=0, | |
traj = openravepy.RaveCreateTrajectory(env, '') | ||
traj.deserialize(traj_xml) | ||
|
||
# Mimic traj processing if requested | ||
if save_mimic_trajectories: | ||
from prpy.util import CopyTrajectory | ||
|
||
cspec = traj.GetConfigurationSpecification() | ||
traj_bodies = cspec.ExtractUsedBodies(robot.GetEnv()) | ||
|
||
# Extract non-robot trajecotry | ||
self.mimic_trajectories = {} | ||
for body in traj_bodies: | ||
if body.GetName() == robot.GetName(): | ||
continue | ||
|
||
|
||
object_cspec = body.GetActiveConfigurationSpecification('GenericTrajectory') | ||
with open(traj_path, 'rb') as traj_file: | ||
traj_xml = traj_file.read() | ||
object_traj = openravepy.RaveCreateTrajectory(env, '') | ||
object_traj.deserialize(traj_xml) | ||
openravepy.planningutils.ConvertTrajectorySpecification(object_traj, object_cspec) | ||
self.mimic_trajectories[body.GetName()] = object_traj | ||
|
||
# Tag the trajectory as non-determistic since CBiRRT is a randomized | ||
# planner. Additionally tag the goal as non-deterministic if CBiRRT | ||
# chose from a set of more than one goal configuration. | ||
|
@@ -314,6 +349,13 @@ def Plan(self, robot, smoothingitrs=None, timelimit=None, allowlimadj=0, | |
|
||
return traj | ||
|
||
def GetMimicPath(self, body_name, env=None): | ||
traj = self.mimic_trajectories.get(body_name, None) | ||
if traj is not None and env is not None: | ||
from prpy.util import CopyTrajectory | ||
traj = CopyTrajectory(traj, env=env) | ||
return traj | ||
|
||
def ClearIkSolver(self, manip): | ||
manip.SetIkSolver(None) | ||
manip.SetLocalToolTransform(manip.GetLocalToolTransform()) | ||
|
@@ -397,4 +439,5 @@ def SerializeTSRChain(self): | |
if len(self.mimicbodyjoints) > 0: | ||
outstring += ' %d %s' % (len(self.mimicbodyjoints), | ||
SerializeArray(self.mimicbodyjoints)) | ||
# outstring += ' %s' % SerializeArray(self.mimicbodyjoints) | ||
return outstring |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Add docstring for save_mimic_trajectories
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.
Couldn't this also take a dict as an argument and just save the trajectory in there, i.e. a user-supplied out-arg? Then the user could do what they want with the trajectory.