robotology / whole-body-estimators

YARP devices that implement estimators for humanoid robots.
26 stars 12 forks source link

Alternative way of specifying the model file without relying on YARP_ROBOT_NAME #147

Open traversaro opened 2 years ago

traversaro commented 2 years ago

Problem

In the wholebodydynamics device we currently have a modelFile parameter for specifying the model filename, that by default is model.urdf (https://github.com/robotology/whole-body-estimators/tree/1d310fe342922ddd1095cdbeb6dbd4555dc01ce5/devices/wholeBodyDynamics#wholebodydynamicsdevice). This string is processed by this snippet of code to obtain the actual absolute filename (from this part of the code):

    std::string modelFileName = "model.urdf";
    if( config.check("modelFile") && config.find("modelFile").isString() )
    {
        modelFileName = config.find("modelFile").asString();
    }
    std::string modelFileFullPath = rf.findFileByName(modelFileName);

The ResourceFinder::findFileByName method then return any absolute path without changing it, but then searches for a filename without path using the YARP's way of searching for files (documented in https://www.yarp.it/latest//yarp_resource_finder_tutorials.html). In practice in most cases that file is located using the value of the YARP_ROBOT_NAME environment variable. This practice work fine if on a given system we only need to load configuration files for one given robot.

However, when we start embedding devices such as wholebodydynamics in simulated robots via the gazebo_yarp_robotinterface plugin, it may happen that you load different robots in the same machine. For example, with the stickBot simulation a common failure that I encountered in the last days is that the simulation did not started correctly because I forgot to set YARP_ROBOT_NAME=stickBot. Even worse, in the future somebody could forget to set correctly YARP_ROBOT_NAME, leading to silently corrupting the simulation results.

Proposed Solution

A quick solution for this is to support also for wholebodydynamics to load files using the ROS's style package:// or Gazebo's model:// URIs. Most of the logic for supporting those URIs is in iDynTree, so we would just need to expose it (see https://github.com/robotology/idyntree/issues/942). Once that logic is exposed and used in wholebodydynamics, we could use it as:

<param name="modelFile">model://iCub/conf_stickBot/estimators/wbd_icub3_sim.xml</param>

coherently with how we specify the other configuration files in SDF, for example in the yarpRobotInterfaceConfigurationFile element, child of plugin for plugins of gazebo-yarp-plugins:

<yarpRobotInterfaceConfigurationFile>model://iCub/conf_stickBot/icub.xml</yarpRobotInterfaceConfigurationFile>
traversaro commented 2 years ago

Tagging ergocub-gazebo-simulations mantainers as currently I experienced this problem mainly with that model: @GrmanRodriguez @AlexAntn @Nicogene .

traversaro commented 2 years ago

We could even think of submitting this functionality in YARP directly, so that any code that used rf.findFileByName could start supporting package:///model:// URIs in input.

traversaro commented 1 year ago

We could even think of submitting this functionality in YARP directly, so that any code that used rf.findFileByName could start supporting package:///model:// URIs in input.

At the python level, I implemted this in a standalone package at https://github.com/ami-iit/resolve-robotics-uri-py , probably we can just do the same for C++ and use it where it is necessary.