Skip to content
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

Enhance MeshcatVisualizer to support base frame in load_model method #1229

Merged
merged 6 commits into from
Feb 11, 2025
11 changes: 8 additions & 3 deletions bindings/python/visualize/meshcat_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ def set_primitive_geometry_property(
else:
with self._animation.at_frame(self.viewer, self._current_frame) as frame:
raise NotImplementedError("The set_property method is not implemented for animations.")

def load_model_from_file(
self, model_path: str, considered_joints=None, model_name="iDynTree", color=None
):
Expand Down Expand Up @@ -621,7 +621,7 @@ def load_model_from_file(

self.load_model(model=model_loader.model(), model_name=model_name, color=color)

def load_model(self, model: idyn.Model, model_name="iDynTree", color=None):
def load_model(self, model: idyn.Model, base_frame = None, model_name="iDynTree", color=None):

# check if the model already exist
if self.__model_exists(model_name):
Expand All @@ -633,7 +633,12 @@ def load_model(self, model: idyn.Model, model_name="iDynTree", color=None):
self.traversal[model_name] = idyn.Traversal()
self.link_pos[model_name] = idyn.LinkPositions()

self.model[model_name].computeFullTreeTraversal(self.traversal[model_name])
if base_frame is None:
GiulioRomualdi marked this conversation as resolved.
Show resolved Hide resolved
self.model[model_name].computeFullTreeTraversal(self.traversal[model_name])
else:
base_frame_index = self.model[model_name].getFrameIndex(base_frame)
self.model[model_name].computeFullTreeTraversal(self.traversal[model_name], base_frame_index)
Copy link
Member

@traversaro traversaro Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we handle somehow the case in which base_frame (or base_link, see the other comment) is not a valid name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GiulioRomualdi I may be missing something, but it does not seem that 08b75f2 handles the case in which base_link is not a valid name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My fault : d1d688d

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I got

 if base_link_index == idyn.LINK_INVALID_INDEX:
AttributeError: module 'idyntree.bindings' has no attribute 'LINK_INVALID_INDEX'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering if LINK_INVALID_INDEX is exported in python given: https://github.com/search?q=repo%3Arobotology%2Fidyntree%20LINK_INVALID_INDEX&type=code

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange, it seems exposed at least on MATLAB:

. Anyhow, you can hardcode -1, see
LinkIndex LINK_INVALID_INDEX = -1;
.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or check if it is smaller than 0.


self.link_pos[model_name].resize(self.model[model_name])

self.__add_model_geometry_to_viewer(
Expand Down
Loading