robotology / icub-models

Official URDF and SDF models of the iCub humanoid robot.
Creative Commons Attribution Share Alike 4.0 International
33 stars 34 forks source link

Implement a machinery to easily access model locations on C++ and Python #130

Closed GiulioRomualdi closed 2 years ago

GiulioRomualdi commented 2 years ago

With this PR I want to propose a solution for the https://github.com/robotology/icub-models/issues/91. In 3c869f1c0d02bfa99d5a49b5c02a6e4cbb57ae25, I implemented a C++ library that will allow us to easily access the location of a model installed in by icub-models repo. The location of the files is automatically generated by a cmake machine that is in charge to set the path accordingly to the installation folder.

I also implemented the python bindings (with pybind11) 8d7efc78a4e9f9048546481c4a2fe2a1339d3ef6. In theory, it would be possible to use swig to support more language. However, since I've never used it I've preferred to start with something simpler.

This is an python script where I used the module. I replicated the API suggested by @traversaro in https://github.com/robotology/icub-models/issues/91#issue-912245566

>>> import icub_models
>>> print(f"Models have been installed in: {icub_models.get_models_path()}")
Models have been installed in: /home/gromualdi/robot-code/robotology-superbuild/build/install/share/iCub/robots
>>> print(f"Available robots: {icub_models.get_robot_names()}")
Available robots: {'iCubErzelli02', 'iCubGazeboV3', 'iCubGenova09', 'iCubNancy01', 'iCubParis01', 'iCubLisboa01', 'iCubParis02', 'iCubGazeboV2_5_visuomanip', 'iCubGenova04_plus', 'iCubGazeboV2_5_plus', 'iCubGazeboV2_5', 'iCubGenova02', 'left_wrist_mk2', 'iCubDarmstadt01', 'iCubGenova04', 'iCubGazeboV2_6', 'iCubGenova03', 'iCubGenova01', 'iCubGazeboV2_7', 'left_hand_mk3'}
>>> for robot_name in icub_models.get_robot_names():
...     print(f"{robot_name}: {icub_models.get_model_file(robot_name)}")
... 
iCubErzelli02: /home/gromualdi/robot-code/robotology-superbuild/build/install/share/iCub/robots/iCubErzelli02/model.urdf
iCubGazeboV3: /home/gromualdi/robot-code/robotology-superbuild/build/install/share/iCub/robots/iCubGazeboV3/model.urdf
iCubGenova09: /home/gromualdi/robot-code/robotology-superbuild/build/install/share/iCub/robots/iCubGenova09/model.urdf
iCubNancy01: /home/gromualdi/robot-code/robotology-superbuild/build/install/share/iCub/robots/iCubNancy01/model.urdf
iCubParis01: /home/gromualdi/robot-code/robotology-superbuild/build/install/share/iCub/robots/iCubParis01/model.urdf
iCubLisboa01: /home/gromualdi/robot-code/robotology-superbuild/build/install/share/iCub/robots/iCubLisboa01/model.urdf
iCubParis02: /home/gromualdi/robot-code/robotology-superbuild/build/install/share/iCub/robots/iCubParis02/model.urdf
iCubGazeboV2_5_visuomanip: /home/gromualdi/robot-code/robotology-superbuild/build/install/share/iCub/robots/iCubGazeboV2_5_visuomanip/model.urdf
iCubGenova04_plus: /home/gromualdi/robot-code/robotology-superbuild/build/install/share/iCub/robots/iCubGenova04_plus/model.urdf
iCubGazeboV2_5_plus: /home/gromualdi/robot-code/robotology-superbuild/build/install/share/iCub/robots/iCubGazeboV2_5_plus/model.urdf
iCubGazeboV2_5: /home/gromualdi/robot-code/robotology-superbuild/build/install/share/iCub/robots/iCubGazeboV2_5/model.urdf
iCubGenova02: /home/gromualdi/robot-code/robotology-superbuild/build/install/share/iCub/robots/iCubGenova02/model.urdf
left_wrist_mk2: /home/gromualdi/robot-code/robotology-superbuild/build/install/share/iCub/robots/left_wrist_mk2/model.urdf
iCubDarmstadt01: /home/gromualdi/robot-code/robotology-superbuild/build/install/share/iCub/robots/iCubDarmstadt01/model.urdf
iCubGenova04: /home/gromualdi/robot-code/robotology-superbuild/build/install/share/iCub/robots/iCubGenova04/model.urdf
iCubGazeboV2_6: /home/gromualdi/robot-code/robotology-superbuild/build/install/share/iCub/robots/iCubGazeboV2_6/model.urdf
iCubGenova03: /home/gromualdi/robot-code/robotology-superbuild/build/install/share/iCub/robots/iCubGenova03/model.urdf
iCubGenova01: /home/gromualdi/robot-code/robotology-superbuild/build/install/share/iCub/robots/iCubGenova01/model.urdf
iCubGazeboV2_7: /home/gromualdi/robot-code/robotology-superbuild/build/install/share/iCub/robots/iCubGazeboV2_7/model.urdf
left_hand_mk3: /home/gromualdi/robot-code/robotology-superbuild/build/install/share/iCub/robots/left_hand_mk3/model.urdf
GiulioRomualdi commented 2 years ago

cc @traversaro @Nicogene

GiulioRomualdi commented 2 years ago

Hi @traversaro, I applied the suggestions you proposed. Before merging the PR I would like to highlight:

  1. I set the project version in the CMake file. The version is the same of the latest release
  2. I opened the PR on devel. I don't know if it is fine or I should change the base branch to master
  3. I should write something in the readme
traversaro commented 2 years ago

I opened the PR on devel. I don't know if it is fine or I should change the base branch to master

Devel is fine.

I should write something in the readme

Yes, that would great otherwise people will never know of the feature! The README probably would need a revamp in general (see https://github.com/robotology/icub-models/issues/90), but I think that for this feature I think it is ok to just add two sections after https://github.com/robotology/icub-models#use-the-models-with-gazebo, something like:

GiulioRomualdi commented 2 years ago

@traversaro I updated the README in https://github.com/robotology/icub-models/pull/130/commits/6da40e2f84aee8c7888fa133854ff40ae0388ba1

traversaro commented 2 years ago

For me it is ok! Can you add a note in the CHANGELOG.md ? Thanks!

traversaro commented 2 years ago

Thanks!