Skip to content

Commit

Permalink
Remove the dependency from icub-models package
Browse files Browse the repository at this point in the history
  • Loading branch information
GiulioRomualdi committed Oct 5, 2023
1 parent 7e44e06 commit 7c4ddb6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion AppImageBuilder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ script:
- cp robot_log_visualizer/ui/misc/icon.png AppDir/usr/share/icons/hicolor/1024x1024/apps/robot-log-visualizer-icon.png

# Install application dependencies
- python3 -m pip install --ignore-installed --prefix=/usr --root=AppDir icub-models pyngrok pyqtconsole idyntree meshcat matplotlib h5py
- python3 -m pip install --ignore-installed --prefix=/usr --root=AppDir pyngrok pyqtconsole idyntree meshcat matplotlib h5py


AppDir:
Expand Down
21 changes: 16 additions & 5 deletions robot_log_visualizer/robot_visualizer/meshcat_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

from PyQt5.QtCore import QThread, QMutex, QMutexLocker

import icub_models

import os
import re
from pathlib import Path
Expand All @@ -28,6 +26,7 @@ def __init__(self, signal_provider, period):

self._period = period
self.meshcat_visualizer = MeshcatVisualizer()
self._is_model_loaded = False
self._signal_provider = signal_provider

self.custom_model_path = ""
Expand All @@ -49,16 +48,21 @@ def load_model(self, considered_joints, model_name):
def get_model_path_from_envs(env_list):
return [
Path(f) if (env != "AMENT_PREFIX_PATH") else Path(f) / "share"
for env in env_list if os.getenv(env) is not None
for env in env_list
if os.getenv(env) is not None
for f in os.getenv(env).split(os.pathsep)
]

def check_if_model_exist(folder_path, model):
path = folder_path / Path(model)
return path.is_dir()

self._is_model_loaded = False

# Load the model
model_loader = idyn.ModelLoader()

# In this case the user specify the model path
if self.custom_model_path:
model_loader.loadReducedModelFromFile(
self.custom_model_path,
Expand All @@ -67,7 +71,10 @@ def check_if_model_exist(folder_path, model):
[self.custom_package_dir],
)
else:
# Attempt to find the model in the envs folders
model_found_in_env_folders = False

# Check if the model is in one of the folders specified in the envs
for folder in get_model_path_from_envs(self.env_list):
if check_if_model_exist(folder, model_name):
folder_model_path = folder / Path(model_name)
Expand All @@ -82,8 +89,9 @@ def check_if_model_exist(folder_path, model):
self.custom_model_path = str(model_filenames[0])
break

# If the model is not found we exit
if not model_found_in_env_folders:
self.custom_model_path = str(icub_models.get_model_file(model_name))
return False

model_loader.loadReducedModelFromFile(
self.custom_model_path, considered_joints
Expand All @@ -95,6 +103,9 @@ def check_if_model_exist(folder_path, model):
self.meshcat_visualizer.load_model(
model_loader.model(), model_name="robot", color=0.8
)

self._is_model_loaded = True

return True

def run(self):
Expand All @@ -104,7 +115,7 @@ def run(self):
while True:
start = time.time()

if self.state == PeriodicThreadState.running:
if self.state == PeriodicThreadState.running and self._is_model_loaded:
# These are the robot measured joint positions in radians
joints = self._signal_provider.data[self._signal_provider.root_name][
"joints_state"
Expand Down

0 comments on commit 7c4ddb6

Please sign in to comment.