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

Fix Gazebo freezing if YARP_CLOCK is set #537

Merged
merged 4 commits into from
Feb 15, 2021
Merged

Fix Gazebo freezing if YARP_CLOCK is set #537

merged 4 commits into from
Feb 15, 2021

Conversation

traversaro
Copy link
Member

@traversaro traversaro commented Feb 11, 2021

Fix #526 .

TL;DR: From gazebo-yarp-plugins 3.6.0, you can again set YARP_CLOCK for the Gazebo simulation, meaning that all the threads of YARP Network Wrapper Servers will be executed with the frequency correctly synchronized with the Gazebo simulation. This also means that if you like you can also set YARP_CLOCK directly in your .bashrc or setup.sh script.

With respect to the solution discussed in #526, i.e. :

A possible solution is to switch to use the system clock after yarp::os::Network was initialized, and switch back to use the default clock once /clock has been created by calling yarp::os::NetworkBase::yarpClockInit(YARP_CLOCK_DEFAULT). This should work fine unless another Gazebo plugin called one of those methods to perturb the process-global YARP clock, but I think that is ok.

in this PR there are two modifications.

First of all, the delayed initialization of the Clock is only done if the yarp::os::Network is not initialized, and this is checked by the yarp::os::NetworkBase::isNetworkInitialized() method. Secondly, calling yarp::os::Network::useNetworkClock does not only need the /clock port to exists, but also wait until something is published on that port and the NetworkClock becomes valid (see useNetworkClock). For this reason, calling useNetworkClock in the Gazebo Physics thread is going to deadlock, as the Gazebo physics thread is also the one that is publish the new time on the clock. To avoid this, the yarp::os::Network::useNetworkClock is called as part of new std::thread that is just created for this.

The PR also contains a regression test for the issue, that was failing before the fix. As the issue was quite related to the inner working of YARP, it was not use NetworkBase::setLocalMode as in the robotinterface and controlboard tests, but rather yarpserver is actually launched before the tests by using tiny-process-library.

Fix #526

Add also regression test for the issue
@traversaro traversaro requested a review from xEnVrE February 11, 2021 18:39
Copy link
Contributor

@xEnVrE xEnVrE left a comment

Choose a reason for hiding this comment

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

LGTM 👍

I only added few comments regarding a typo and a potential missing sentence in the code comments

m_network = new yarp::os::Network();
// To avoid deadlock during initialation if YARP_CLOCK is set,
// if the YARP network is not initialized we always initialize
// it with system clock, and then we
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that here the sentence in the comment is truncated.

@@ -68,7 +68,20 @@ namespace gazebo

void GazeboYarpClock::Load(int _argc, char **_argv)
{
m_network = new yarp::os::Network();
// To avoid deadlock during initialation if YARP_CLOCK is set,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change:
initialation -> initialization

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, feel free to do this suggestions with GitHub's integrated system!

@traversaro
Copy link
Member Author

LGTM 👍

I only added few comments regarding a typo and a potential missing sentence in the code comments

I think I have addressed them. The tests are failing for the same reason mentioned in #536, so as the tests will be suppressed in #532 I think we can merge if you agree.

@xEnVrE
Copy link
Contributor

xEnVrE commented Feb 12, 2021

I think we can merge if you agree.

Fine with 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.

Gazebo freezes when YARP_CLOCK is set
2 participants