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

Remove the dependency of icub-models #64

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ following command
python -m pip install git+https://github.com/ami-iit/robot-log-visualizer.git
```

## 🏃 Example
## 🏃 Usage

Once you have installed the `robot-log-visualizer` you can run it from the terminal

Expand All @@ -69,6 +69,28 @@ Once you have installed the `robot-log-visualizer` you can run it from the termi
You can navigate the dataset thanks to the slider or by pressing `Ctrl-f` and `Ctrl-b` to move
forward and backward.

### 💡 Environment variables
`robot-log-visualizer` looks for the model in the folders pointed by one of the following environment variables:
`GAZEBO_MODEL_PATH`, `ROS_PACKAGE_PATH`, `AMENT_PREFIX_PATH` Please remember to add your model folder to one of these
environment variables.
For instance, if you have a model in the folder `~/my-models` you can add it to the `GAZEBO_MODEL_PATH` with the
following command
```console
export GAZEBO_MODEL_PATH=${GAZEBO_MODEL_PATH}:~/my-models
```
Where `~/my-models` is the path to your models folder that is structured as follows
```console
tree ~/my-models
~/my-models
├── model1
│   ├── model.config
│   └── model.urdf
└── model2
├── model.config
└── model.urdf
```
And the name of the robot stored in the `mat` file is `model1` or `model2`.

## 🐛 Bug reports and support
All types of [issues](https://github.com/ami-iit/robot-log-visualizer/issues/new) are welcome.

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