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

Add gazebo_yarp_robotinterface plugin #532

Merged
merged 18 commits into from
Feb 18, 2021
Merged

Add gazebo_yarp_robotinterface plugin #532

merged 18 commits into from
Feb 18, 2021

Conversation

traversaro
Copy link
Member

@traversaro traversaro commented Jan 25, 2021

This PR implements a gazebo_yarp_robotinterface plugin as it was originally described in #391 . You can find an explanation of the capability of this plugin in the documentation added in https://github.com/robotology/gazebo-yarp-plugins/blob/2a4bdf123d1c87b84a9f79cf2978f61bc100503c/plugins/robotinterface/README.md .

This plugin can be helpful in the following use cases:

While the implementation of the plugin is complete and contained in this PR, for fully exploit this plugin it may be necessary to do further modification to other plugins as described in #534 and #535 . However, this improvements can be done in future PRs, as they are independent from the implementation of the gazebo_yarp_robotinterface .

If you want to test this branch with yarp-3.5, you can check the branch https://github.com/robotology/gazebo-yarp-plugins/tree/add-robotinterface-yarp-3.5 .

@randaz81
Copy link
Member

randaz81 commented Feb 1, 2021

I have the following question: what is the purpose of this piece of code, extracted from LaserSensor.cc ?

if(!driver_properties.check("deviceId"))
{
yError()<<"GazeboYarpLaserSensor Plugin failed: cannot find deviceId parameter in ini file.";
return;
}
std::string deviceId = driver_properties.find("deviceId").asString();
if(!GazeboYarpPlugins::Handler::getHandler()->setDevice(deviceId, &m_laserDriver))
{
yError()<<"GazeboYarpLaserSensor: failed setting deviceId(=" << deviceId << ")";
return;
}

I was able to attach the robotinterface wrapper by using the name specified by this deviceId parameter.
But then I noticed that this is the only plugin the implements such a parameter. For example, the depthCamera plugin does not perform any getHandler()->setDevice(). Thus, if my interpretation is correct and this is the correct way to perform the attach, then the other plugins such as depthCamera are incomplete and need to implement the same piece of code. What do you think?

@randaz81
Copy link
Member

randaz81 commented Feb 1, 2021

Additionally, in file ControlBoard.cc, I found the following:

GazeboYarpPlugins::Handler::getHandler()->setDevice(scopedDeviceName, newPoly.poly);

The variable scopedDeviceName seems to answer to your point:

Cleanup handling of devices names. At the moment they are prefixed with the Gazebo Model name, and that is not ideal if we want to re-use XML files in both the gazebo_yarp_robotinterface plugin, and an externally instantiated yarprobotinterface .

So it seems that in the controlboard plugin, the device name is not taken from an external parameter, but it is generated internally.

@traversaro
Copy link
Member Author

I have the following question: what is the purpose of this piece of code, extracted from LaserSensor.cc ?

This was implemented in #419, I guess to support a similar user case of device created in one gazebo plugin and attached to a network server wrapper created in another gazebo plugin.

@traversaro
Copy link
Member Author

However, I thought a bit about the naming aspect and I think a good solution could be:

  • All Gazebo plugins take in input a variable yarpDeviceName that specifies the string that will be used then to attach to that device in the robotinterface XML file. The name of this parameter is chosen to mirror the similarly named element in the robotinterface XML elements, for example <device name="additional_controlboard_nws" type="controlboardwrapper2">. Some plugins will have this parameter or have a special case parameter (yarpDeviceNames as a list?) if they can instantiate multiple yarp devices from a single gazebo plugin. Plugins that currently do not register their device in the singleton need to be modified to read from yarpDeviceName and register their device.
  • To avoid collisions, the device name are registered in the singleton with a scopedName that is constructed by concatenating the Gazebo model scoped name and the yarpDeviceName (see as done in
    std::string scopedDeviceName = m_robotName + "::" + m_controlBoards[n]->key.c_str();
    ).
  • As we want to pass the device name without any scope in the attach parameters, i.e. in :
      <action phase="startup" level="5" type="attach">
        <paramlist name="networks">
          <elem name="key_of_the_list">  yarp_device_name_used_to_found_the_device_in_the_list_of_devices </elem>
        </paramlist>
      </action>

the Handler::getDevicesAsPolyDriverList method (see https://github.com/robotology/gazebo-yarp-plugins/pull/532/files#diff-51f84011401d52ad0a51e43aa1a8d5b1d32ced0fdbb644993860b70444b3de4dR231) needs to be modified to only return only the device spawned by the model that it contains the robotinterface plugin and its submodels, and to remove the model-specific prefix to just obtain the yarp device name. If there is any naming conflict (i.e. two devices that have the same unscoped name) will result in an error.

The last point probably prevents some corner case uses (such as the use of robotinterface plugin in the parent model that contains two iCub models, for example) but until we have a concrete use case I would focus on implementing our main use case (i.e. a single iCub that runs custom devices in its "yarprobotinterface") easily and in a clean way.

@traversaro
Copy link
Member Author

cc @PeterBowman I do not know if you may be interested in this (as you recently started using the gazebo-yarp-plugins and I think you are also implementing a motor interface for a robot using the yarprobotinterface), if you are and you like feel free to provide some feedback!

@PeterBowman
Copy link
Member

Thank you, @traversaro! That is one interesting tool we once decided to set aside due to lack of documentation among others (empty doxy, roboticslab-uc3m/yarp-devices#237), but it's still on our radar now that we are exploring further integration with your codebase.

@traversaro
Copy link
Member Author

Cleanup handling of devices names. At the moment they are prefixed with the Gazebo Model name, and that is not ideal if we want to re-use XML files in both the gazebo_yarp_robotinterface plugin, and an externally instantiated yarprobotinterface .

This point was fixed by c30b6ab . @randaz81 I also incorporated your other commits, and I prepare a yarp 3.5-compatible version of the branch in https://github.com/robotology/gazebo-yarp-plugins/tree/add-robotinterface-yarp-3.5 .

@traversaro traversaro changed the title [WIP] [DO NOT MERGE] First draft of gazebo_yarp_robotinterface plugin Add gazebo_yarp_robotinterface plugin Feb 10, 2021
@traversaro
Copy link
Member Author

The PR is now ready for review, the tests were failing due to fact that the device usage needs to be manually tracked as the plugins in Gazebo are not destructed/unloaded in reverse order, and that was fixed in 2a4bdf1 .

@traversaro
Copy link
Member Author

As you can see by the linked issues, this plugin is an important piece of software that could be used to enable several convenient workflows. For this reason, I will tag a few people that may be affected by this or one of the related issues, and even if I do not list them as a reviewer, feel free to review the PR if you like: @drdanz @randaz81 @gabrielenava @Giulero @lrapetti @HosameldinMohamed @S-Dafarra @GiulioRomualdi @prashanthr05 @Nicogene @elandini84 @diegoferigo @nunoguedelha @Yeshasvitvs .

@traversaro traversaro mentioned this pull request Feb 11, 2021
@traversaro
Copy link
Member Author

Great, now that I fixed the newly added test, the already existing ControlBoardControlTest started failing, probably some timing-related bug that was already present.

@traversaro
Copy link
Member Author

Great, now that I fixed the newly added test, the already existing ControlBoardControlTest started failing, probably some timing-related bug that was already present.

The test failures seems flaky and unrelated (see #536). Suppressing the test for now.

Copy link
Contributor

@prashanthr05 prashanthr05 left a comment

Choose a reason for hiding this comment

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

Minor comments mainly regarding debug prints and documentation plus,

  • Should we address the commented stray lines in DoubleLaser and LaserSensor source files?

libraries/singleton/include/GazeboYarpPlugins/Handler.hh Outdated Show resolved Hide resolved
libraries/singleton/include/GazeboYarpPlugins/Handler.hh Outdated Show resolved Hide resolved
libraries/singleton/include/GazeboYarpPlugins/Handler.hh Outdated Show resolved Hide resolved
libraries/singleton/src/Handler.cc Show resolved Hide resolved

if(GAZEBO_YARP_PLUGINS_HAS_YARP_ROBOTINTERFACE)
add_subdirectory(robotinterface)
endif()
Copy link
Contributor

Choose a reason for hiding this comment

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

new line ;D

plugins/robotinterface/README.md Outdated Show resolved Hide resolved
plugins/robotinterface/README.md Outdated Show resolved Hide resolved
plugins/robotinterface/README.md Outdated Show resolved Hide resolved
tests/robotinterface/RobotInterfaceTest.xml Show resolved Hide resolved
plugins/robotinterface/src/GazeboYarpRobotInterface.cc Outdated Show resolved Hide resolved
Co-authored-by: Prashanth Ramadoss <prashanthramadoss@gmail.com>
tests/CMakeLists.txt Outdated Show resolved Hide resolved
plugins/CMakeLists.txt Outdated Show resolved Hide resolved
traversaro and others added 6 commits February 15, 2021 18:02
Co-authored-by: Prashanth Ramadoss <prashanthramadoss@gmail.com>
Co-authored-by: Prashanth Ramadoss <prashanthramadoss@gmail.com>
Co-authored-by: Prashanth Ramadoss <prashanthramadoss@gmail.com>
@traversaro
Copy link
Member Author

I should have addressed all the comments @prashanthr05 .

Copy link
Contributor

@prashanthr05 prashanthr05 left a comment

Choose a reason for hiding this comment

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

Thank you @traversaro. I have not personally tested the plugin, but overall it looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants