-
Notifications
You must be signed in to change notification settings - Fork 52
Add path shortening utils and consolidate examples #33
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
2b1a1a4
Add functions for path shortening
eholum c0932ed
Start adding unit tests for path shortcutting
eholum f1337ba
Update roboplan/src/core/path_utils.cpp
eholum 2d07f7a
Eigen, right.
eholum 3863ce7
Make path shortening actually work
eholum 546c0bb
Seed path shortcutting
eholum c1f9410
Never shortcut the start
eholum 2a2a23a
Add python bindings
eholum ac46894
Weird timeouts when connecting through ssh in the vizer viz
eholum 530abc1
Add path shortcutting example
eholum c6fe78d
Update bindings/src/roboplan/viser_visualizer.py
eholum e36d4e1
Tweak RRT params for path shortening
eholum aebffd9
Merge branch 'main' into path-shortening
eholum 5f7d2e5
Separate tree and path rendering
eholum d9116e1
Add path shortcutting to existing RRT demos
eholum 2ecd997
0 is a valid seed
eholum ed53e17
Minor viz tweaks
eholum 562a806
Add tyro as a dep and install in containers
eholum 3a6082e
Consolidate RRT examples with tyro
eholum 86d29d1
Generalize the IK example
eholum 8bf6e97
Add comment
eholum 795f377
Unused params
eholum 0742a16
pin typing_extensions
eholum fef1552
Install tyro with the other bindings deps
eholum 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| from pathlib import Path | ||
| import time | ||
|
|
||
| import numpy as np | ||
| import pinocchio as pin | ||
| from roboplan import ( | ||
| computeFramePath, | ||
| get_package_share_dir, | ||
| shortcutPath, | ||
| JointConfiguration, | ||
| JointPath, | ||
| Scene, | ||
| RRTOptions, | ||
| RRT, | ||
| ) | ||
| from roboplan.viser_visualizer import ViserVisualizer | ||
|
|
||
|
|
||
| def visualizePath( | ||
| viz: ViserVisualizer, | ||
| scene: Scene, | ||
| path: JointPath, | ||
| frame_name: str, | ||
| max_step_size: float, | ||
| colors: tuple, | ||
| path_name: str, | ||
| ) -> None: | ||
|
|
||
| path_segments = [] | ||
| for idx in range(len(path.positions) - 1): | ||
| q_start = path.positions[idx] | ||
| q_end = path.positions[idx + 1] | ||
| frame_path = computeFramePath(scene, q_start, q_end, frame_name, max_step_size) | ||
| for idx in range(len(frame_path) - 1): | ||
| path_segments.append([frame_path[idx][:3, 3], frame_path[idx + 1][:3, 3]]) | ||
|
|
||
| viz.viewer.scene.add_line_segments( | ||
| path_name, | ||
| points=np.array(path_segments), | ||
| colors=colors, | ||
| line_width=3.0, | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
|
|
||
| roboplan_examples_dir = Path(get_package_share_dir()) | ||
| urdf_path = roboplan_examples_dir / "ur_robot_model" / "ur5_gripper.urdf" | ||
| srdf_path = roboplan_examples_dir / "ur_robot_model" / "ur5_gripper.srdf" | ||
| package_paths = [roboplan_examples_dir] | ||
|
|
||
| scene = Scene("test_scene", urdf_path, srdf_path, package_paths) | ||
|
|
||
| # Create a redundant Pinocchio model just for visualization. | ||
| # When Pinocchio 4.x releases nanobind bindings, we should be able to directly grab the model from the scene instead. | ||
| model, collision_model, visual_model = pin.buildModelsFromUrdf( | ||
| urdf_path, package_dirs=package_paths | ||
| ) | ||
| viz = ViserVisualizer(model, collision_model, visual_model) | ||
| viz.initViewer(open=True, loadModel=True) | ||
|
|
||
| # Set up an RRT with a very small connection distance to demonstrate path shortening. | ||
| options = RRTOptions() | ||
| options.max_connection_distance = 1.0 | ||
| options.collision_check_step_size = 0.01 | ||
| options.max_planning_time = 5.0 | ||
| options.rrt_connect = True | ||
| rrt = RRT(scene, options) | ||
|
|
||
| start = JointConfiguration() | ||
| start.positions = scene.randomCollisionFreePositions() | ||
| assert start.positions is not None | ||
|
|
||
| goal = JointConfiguration() | ||
| goal.positions = scene.randomCollisionFreePositions() | ||
| assert goal.positions is not None | ||
|
|
||
| path = rrt.plan(start, goal) | ||
| assert path is not None | ||
| print("Original path (in red):") | ||
| print(path) | ||
|
|
||
| # After planning attempt to shorten the path | ||
| shortcut_path = shortcutPath(scene, path, options.collision_check_step_size, 1000) | ||
| print("Shortcutted path (in green):") | ||
| print(shortcut_path) | ||
|
|
||
| # Visualize the tree, path, and shortcutted path | ||
| viz.display(start.positions) | ||
| visualizePath(viz, scene, path, "tool0", 0.05, (100, 0, 0), "/rrt/path") | ||
| visualizePath( | ||
| viz, scene, shortcut_path, "tool0", 0.05, (0, 100, 0), "/rrt/shortcut_path" | ||
| ) | ||
|
|
||
| while True: | ||
| time.sleep(10.0) | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
So once the Franka PR lands, I think this is what we'll need:
visualizePathto two separate functions,visualizeRRTandvisualizePath, which accepts the name of the thing to visualize as an input arg.visualizeRRTonce, andvisualizePathtwice (for the raw and shortcutted paths)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.
Follow-up: Maybe we instead just want to modify the existing RRT examples and add a flag for whether we want shortcutting or not?
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.
Done and done.
I'm assuming it's preferable just to have all of the configurable parameters directly in code rather than adding arguments or something to these example scripts to do more code consolidation?
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.
Either/or. Viser uses this other package named
tyrowhich makes command line args pretty nice, if you wanna check it out. The viser examples are a good reference.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.
Oh that is need. Do you want to tackle that here? I would probably merge the ik and rrt examples together and make everything an argument, including the robot models. Thoughts?
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.
That sounds great -- up to you if you wanna split it off or club it all together.