-
Notifications
You must be signed in to change notification settings - Fork 35
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
Refactor the from_urdf
function from RobotLibrary to Robot
#437
Draft
yck011522
wants to merge
3
commits into
main
Choose a base branch
from
refactor/robot_from_urdf
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.
Draft
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
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
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 | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3,6 +3,7 @@ | |||||||||||||||||||
from __future__ import print_function | ||||||||||||||||||||
|
||||||||||||||||||||
import random | ||||||||||||||||||||
import compas_fab | ||||||||||||||||||||
|
||||||||||||||||||||
from compas.data import Data | ||||||||||||||||||||
from compas.geometry import Frame | ||||||||||||||||||||
|
@@ -11,6 +12,7 @@ | |||||||||||||||||||
from compas_robots import Configuration | ||||||||||||||||||||
from compas_robots import RobotModel | ||||||||||||||||||||
from compas_robots.model import Joint | ||||||||||||||||||||
from compas_robots.resources import LocalPackageMeshLoader | ||||||||||||||||||||
|
||||||||||||||||||||
from compas_fab.robots.constraints import Constraint | ||||||||||||||||||||
|
||||||||||||||||||||
|
@@ -110,6 +112,49 @@ def __from_data__(cls, data): | |||||||||||||||||||
robot.attributes = attributes | ||||||||||||||||||||
return robot | ||||||||||||||||||||
|
||||||||||||||||||||
@classmethod | ||||||||||||||||||||
def from_urdf(cls, urdf_filename, srdf_filename=None, local_package_mesh_folder=None, client=None): | ||||||||||||||||||||
# type: (str, Optional[str], Optional[str], Optional[ClientInterface]) -> Robot | ||||||||||||||||||||
"""Create a robot from URDF. | ||||||||||||||||||||
Optionally, SRDF can be provided to load semantics and a local package mesh folder to load mesh geometry. | ||||||||||||||||||||
|
||||||||||||||||||||
Parameters | ||||||||||||||||||||
---------- | ||||||||||||||||||||
urdf_filename : :obj:`str` | ||||||||||||||||||||
Path to the URDF file. | ||||||||||||||||||||
srdf_filename : :obj:`str`, optional | ||||||||||||||||||||
Path to the SRDF file to load semantics. Default is `None`. | ||||||||||||||||||||
local_package_mesh_folder : :obj:`str`, optional | ||||||||||||||||||||
Path to the local package mesh folder. | ||||||||||||||||||||
If the path is provided, the geometry of the robot is loaded from this folder. | ||||||||||||||||||||
Default is `None`, which means that the geometry is not loaded. | ||||||||||||||||||||
client : :class:`compas_fab.backends.interfaces.ClientInterface`, optional | ||||||||||||||||||||
Backend client provided for the . Default is `None`. | ||||||||||||||||||||
|
||||||||||||||||||||
Returns | ||||||||||||||||||||
------- | ||||||||||||||||||||
:class:`compas_fab.robots.Robot` | ||||||||||||||||||||
Newly created instance of the robot. | ||||||||||||||||||||
|
||||||||||||||||||||
""" | ||||||||||||||||||||
# NOTE: This import is here to avoid circular imports | ||||||||||||||||||||
from compas_fab.robots import RobotSemantics | ||||||||||||||||||||
|
||||||||||||||||||||
model = RobotModel.from_urdf_file(urdf_filename) | ||||||||||||||||||||
|
||||||||||||||||||||
if srdf_filename: | ||||||||||||||||||||
semantics = RobotSemantics.from_srdf_file(srdf_filename, model) | ||||||||||||||||||||
else: | ||||||||||||||||||||
semantics = None | ||||||||||||||||||||
Comment on lines
+144
to
+148
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. Maybe this is a bit neater?
Suggested change
|
||||||||||||||||||||
|
||||||||||||||||||||
if local_package_mesh_folder: | ||||||||||||||||||||
loader = LocalPackageMeshLoader(compas_fab.get(local_package_mesh_folder), "") | ||||||||||||||||||||
model.load_geometry(loader) | ||||||||||||||||||||
|
||||||||||||||||||||
robot = cls(model, semantics=semantics, client=client) | ||||||||||||||||||||
|
||||||||||||||||||||
return robot | ||||||||||||||||||||
|
||||||||||||||||||||
@property | ||||||||||||||||||||
def scene_object(self): | ||||||||||||||||||||
"""Scene object used to visualize robot model.""" | ||||||||||||||||||||
|
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
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.
ClientInterface
is not imported, is it? Does this work? Can you do a fully-qualified type here (ie.compas_fab.backends.interfaces.ClientInterface
) to avoid importing only for the purpose of type checking?