-
Notifications
You must be signed in to change notification settings - Fork 18
Add experimental NeuralPlanner for learned waypoint pass through #321
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
Open
yangchen73
wants to merge
3
commits into
main
Choose a base branch
from
yc/neural-planner
base: main
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.
+1,172
−7
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Some comments aren't visible on the classic Files Changed page.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # NeuralPlanner | ||
|
|
||
| ````{admonition} Experimental | ||
| :class: warning | ||
|
|
||
| `NeuralPlanner` is an **experimental** feature. The API, checkpoint format, | ||
| and default parameters may change without a deprecation cycle. It is currently | ||
| only validated on the **Franka Panda** robot. | ||
| ```` | ||
|
|
||
| `NeuralPlanner` is a learning-based EEF waypoint planner. It rolls out a | ||
| trained APG checkpoint through `MotionGenerator` to reach Cartesian targets. | ||
|
|
||
| ## Configuration | ||
|
|
||
| Pre-trained checkpoints are hosted on HuggingFace and can be downloaded with | ||
| `download_neural_planner_checkpoint()` (requires `HF_TOKEN` environment variable). | ||
|
|
||
| ```python | ||
| from embodichain.data.assets.planner_assets import download_neural_planner_checkpoint | ||
| from embodichain.lab.sim.planners import ( | ||
| MotionGenCfg, | ||
| MotionGenOptions, | ||
| MotionGenerator, | ||
| MoveType, | ||
| NeuralPlannerCfg, | ||
| PlanState, | ||
| ) | ||
| from embodichain.lab.sim.planners.neural_planner import NeuralPlanOptions | ||
|
|
||
| checkpoint_path = download_neural_planner_checkpoint() | ||
|
|
||
| motion_generator = MotionGenerator( | ||
| cfg=MotionGenCfg( | ||
| planner_cfg=NeuralPlannerCfg( | ||
| robot_uid=robot.uid, | ||
| checkpoint_path=checkpoint_path, | ||
| control_part="main_arm", | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| result = motion_generator.generate( | ||
| target_states=[ | ||
| PlanState(move_type=MoveType.EEF_MOVE, xpos=waypoint) | ||
| for waypoint in waypoints | ||
| ], | ||
| options=MotionGenOptions( | ||
| plan_opts=NeuralPlanOptions( | ||
| control_part="main_arm", | ||
| start_qpos=start_qpos, | ||
| ), | ||
| ), | ||
| ) | ||
| ``` | ||
|
|
||
| ## Example | ||
|
|
||
| ```bash | ||
| python examples/sim/planners/neural_planner.py --headless --device cuda | ||
| ``` | ||
|
|
||
| The example downloads the checkpoint automatically on first run. | ||
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 |
|---|---|---|
|
|
@@ -21,3 +21,5 @@ | |
| from .eef_assets import * | ||
| from .robot_assets import * | ||
| from .scene_assets import * | ||
| from .solver_assets import * | ||
|
Contributor
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. Move solver as well |
||
| from .planner_assets import * | ||
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,91 @@ | ||
| # ---------------------------------------------------------------------------- | ||
|
Contributor
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. Rename to nmg_weights would be better. and place to a weights folder |
||
| # Copyright (c) 2021-2026 DexForce Technology Co., Ltd. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # ---------------------------------------------------------------------------- | ||
| from __future__ import annotations | ||
|
|
||
| import os | ||
|
|
||
| from huggingface_hub import hf_hub_download | ||
|
|
||
| # HuggingFace endpoint. Mirrors (e.g. hf-mirror.com) often redirect to the | ||
| # real hub without forwarding the required commit-hash response headers, so we | ||
| # default to the canonical endpoint and rely on the system proxy when needed. | ||
| _HF_ENDPOINT = "https://huggingface.co" | ||
|
|
||
| __all__ = ["download_neural_planner_checkpoint"] | ||
|
|
||
|
|
||
| def download_neural_planner_checkpoint( | ||
| repo_id: str = "dexforce/neural_motion_generator", | ||
| filename: str = "franka/franka.pt", | ||
| token: str | None = None, | ||
| endpoint: str = _HF_ENDPOINT, | ||
| ) -> str: | ||
| """Download a neural planner checkpoint from HuggingFace. | ||
|
|
||
| The repository is gated. Either set the ``HF_TOKEN`` environment variable or | ||
| run ``huggingface-cli login`` before calling this function. | ||
|
|
||
| If your network requires an HTTP proxy, set ``HTTPS_PROXY`` or | ||
| ``https_proxy`` in the environment before launching Python. | ||
|
|
||
| Args: | ||
| repo_id: HuggingFace repository ID. | ||
| filename: Checkpoint path in the repo, e.g. ``franka/franka.pt``. | ||
| token: HuggingFace API token. Falls back to the ``HF_TOKEN`` | ||
| environment variable or the cached token from | ||
| ``huggingface-cli login``. | ||
| endpoint: HuggingFace-compatible endpoint URL. Defaults to | ||
| ``https://huggingface.co``. Mirrors that merely redirect to the | ||
| real hub are not supported. | ||
|
|
||
| Returns: | ||
| str: Local path to the downloaded checkpoint file. | ||
|
|
||
| Raises: | ||
| RuntimeError: If the download fails, with authentication instructions. | ||
| """ | ||
| # Normalize proxy env vars: the ``requests`` library on Linux requires the | ||
| # lowercase form (``https_proxy``), but users typically export the uppercase | ||
| # form (``HTTPS_PROXY``). | ||
| https_proxy = os.environ.get("HTTPS_PROXY") or os.environ.get("https_proxy") | ||
| if https_proxy: | ||
| os.environ.setdefault("https_proxy", https_proxy) | ||
| os.environ.setdefault("HTTPS_PROXY", https_proxy) | ||
|
|
||
| # Allow callers to pass the token explicitly; otherwise fall back to | ||
| # HF_TOKEN (huggingface_hub also reads this automatically, but being | ||
| # explicit makes the fallback order transparent). | ||
| if token is None: | ||
| token = os.environ.get("HF_TOKEN") or None | ||
|
|
||
| try: | ||
| return hf_hub_download( | ||
| repo_id=repo_id, | ||
| filename=filename, | ||
| token=token, | ||
| endpoint=endpoint, | ||
| ) | ||
| except Exception as exc: | ||
| raise RuntimeError( | ||
| f"Failed to download '{filename}' from '{repo_id}'.\n" | ||
| "The repository is gated and requires an authenticated HuggingFace account.\n" | ||
| "To fix this:\n" | ||
| " 1. Accept the model license at https://huggingface.co/dexforce/neural_motion_generator\n" | ||
| " 2. Create an access token at https://huggingface.co/settings/tokens\n" | ||
| " 3. Export the token: export HF_TOKEN=<your_token>\n" | ||
| " or run: huggingface-cli login\n" | ||
| f"Original error: {exc}" | ||
| ) from exc | ||
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.
Mention that the policy of Neural Planner is specified for a robot.