-
Notifications
You must be signed in to change notification settings - Fork 7
Added 4 methods for extracting meshes from links in RobotModel
#25
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
Changes from 4 commits
2742945
f213a96
2a45bf8
0ff399a
3328c4a
b43c1ec
eeb6662
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 | ||
|---|---|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |||
| import itertools | ||||
| import random | ||||
|
|
||||
| from compas import IPY | ||||
| from compas.colors import Color | ||||
| from compas.data import Data | ||||
| from compas.datastructures import Mesh | ||||
|
|
@@ -34,6 +35,13 @@ | |||
| from .link import Link | ||||
| from .link import Visual | ||||
|
|
||||
| if not IPY: | ||||
| from typing import TYPE_CHECKING | ||||
|
|
||||
| if TYPE_CHECKING: | ||||
| from typing import List # noqa: F401 | ||||
| from typing import Optional # noqa: F401 | ||||
|
|
||||
|
|
||||
| class RobotModel(Data): | ||||
| """RobotModel is the root element of the model. | ||||
|
|
@@ -822,6 +830,10 @@ def scale(self, factor, link=None): | |||
|
|
||||
| self._scale_factor = factor | ||||
|
|
||||
| # -------------------------------------------------------------------------- | ||||
| # Methods for computing frames and axes from the Robot Model | ||||
| # -------------------------------------------------------------------------- | ||||
|
|
||||
| def compute_transformations(self, joint_state, link=None, parent_transformation=None): | ||||
| """Recursive function to calculate the transformations of each joint. | ||||
|
|
||||
|
|
@@ -874,7 +886,9 @@ def compute_transformations(self, joint_state, link=None, parent_transformation= | |||
| return transformations | ||||
|
|
||||
| def transformed_frames(self, joint_state): | ||||
| """Returns the transformed frames based on the joint_state. | ||||
| """Returns the transformed Joint frames (relative to the Robot Coordinate Frame) based on the joint_state (:class:`~compas_robots.Configuration`). | ||||
|
|
||||
| The order of the frames is the same as the order returned by :meth:`iter_joints`. | ||||
|
|
||||
| Parameters | ||||
| ---------- | ||||
|
|
@@ -990,6 +1004,181 @@ def _check_link_name(self, name): | |||
| if name in all_link_names: | ||||
| raise ValueError("Link name '%s' already used in chain." % name) | ||||
|
|
||||
| # -------------------------------------------------------------------------- | ||||
| # Methods for accessing the visual and collision geometry | ||||
| # -------------------------------------------------------------------------- | ||||
|
|
||||
| def _extract_link_meshes(self, link_elements, meshes_at_link_origin=True): | ||||
| # type: (List[Visual] | List[Collision], Optional[bool]) -> List[Mesh] | ||||
| """Extracts the list of compas meshes from a link's Visual or Collision elements. | ||||
|
|
||||
| Parameters | ||||
| ---------- | ||||
| link_elements : list of :class:`~compas_robots.model.Visual` or :class:`~compas_robots.model.Collision` | ||||
| The list of Visual or Collision elements of a link. | ||||
| meshes_at_link_origin : bool, optional | ||||
chenkasirer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
| Defaults to True, which means that the meshes will be transformed according to | ||||
| `element.origin`, such that the mesh origin matches with the link's origin frame. | ||||
| If False, the meshes will be extracted as it is loaded from the | ||||
| robot model package. Note that the `.origin` for each element is not necessarily | ||||
| the same. | ||||
|
|
||||
| Returns | ||||
| ------- | ||||
| list of :class:`~compas.datastructures.Mesh` | ||||
| A list of meshes belonging to the link elements. | ||||
|
|
||||
| Notes | ||||
| ----- | ||||
| Only MeshDescriptor in `element.geometry.shape` is supported. Other shapes are ignored. | ||||
|
|
||||
| """ | ||||
| if not link_elements: | ||||
| return None | ||||
yck011522 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
|
|
||||
| meshes = [] | ||||
| # Note: Each Link can have multiple visual nodes | ||||
| for element in link_elements: | ||||
| # Some elements may have a non-identity origin frame | ||||
| origin = element.origin.to_compas_frame() if element.origin else Frame.worldXY() | ||||
| t_origin = Transformation.from_frame(origin) | ||||
yck011522 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
| # If `meshes_at_link_origin` is False, we use an identity transformation | ||||
| t_origin = t_origin if meshes_at_link_origin else Transformation() | ||||
|
|
||||
| shape = element.geometry.shape | ||||
| # Note: the MeshDescriptor.meshes object supports a list of compas meshes. | ||||
| if isinstance(shape, MeshDescriptor): | ||||
| # There can be multiple mesh in a single MeshDescriptor | ||||
| for mesh in shape.meshes: | ||||
|
||||
| meshes = LinkGeometry._get_item_meshes(item) |
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.
Yes, I am aware but I don't like that code path with the coerce to tuple thing.
And I think my code is more extendable if in the future other Descriptors are supported.
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.
the code currently doesn't support primitives (i.e. proxies of Sphere, Box etc).
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.
right, this is a comment right? Or?
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.
To me it would make sense to cover all kinds of link geometries already in this PR, or could you explain why you focus on MeshDescriptor and see all others as future extension?
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, so you mean by using meshes = LinkGeometry._get_item_meshes(item) we can cover the other Descriptors too?
Okay, we can do that too.
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.
Fixed.
Uh oh!
There was an error while loading. Please reload this page.