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

Support emitting an event on play/pause/step #306

Merged
merged 15 commits into from Nov 5, 2021

Conversation

adlarkin
Copy link
Contributor

@adlarkin adlarkin commented Oct 14, 2021

Signed-off-by: Ashton Larkin ashton@openrobotics.org

🎉 New feature

Part of gazebosim/gz-sim#1106

Requires gazebosim/gz-msgs#190

Summary

If the GUI's ECM is modified directly while simulation is paused, the GUI needs to tell the server how the ECM changed. The approach taken is to have the WorldControl service called in ign-gazebo's GuiRunner instead of ign-gui's WorldControl plugin. When play/pause/step is pressed in the GUI, an event is emitted that contains the WorldControl information. This event is processed by ign-gazebo's GuiRunner. The GuiRunner will then take the information from this event, combine it with the GUI's ECM state, and call the WorldControl service that was being called in ign-gui before this PR. ign-gui's WorldControl will listen to the world's stats topic for confirmation that the emitted WorldControl event was processed by the server.

It's also worth noting that the client/server communication that exists before this PR (direct service call) is still supported - see the Test It section below.

Test it

note: this PR needs to be tested with gazebosim/gz-sim#1109

Run a gazebo world and try to play/pause/step from the GUI. You should see proper update behavior. You can also try playing/pausing from the command line to verify that those updates work properly as well.

To play from the command line with the original service (make sure you update /world/shapes/control to the service name that matches your world):

ign service -s /world/shapes/control  --reqtype  ignition.msgs.WorldControl --reptype ignition.msgs.Boolean --timeout 2000 --req 'pause: false'

To pause from the command line with the original service (make sure you update /world/shapes/control to the service name that matches your world):

ign service -s /world/shapes/control  --reqtype  ignition.msgs.WorldControl --reptype ignition.msgs.Boolean --timeout 2000 --req 'pause: true'

To play from the command line with the new service that's called by the emitted event (make sure you update /world/shapes/control/state to the service name that matches your world):

ign service -s /world/shapes/control/state  --reqtype  ignition.msgs.WorldControlState --reptype ignition.msgs.Boolean --timeout 2000 --req 'world_control: {pause: false}'

To pause from the command line with the new service that's called by the emitted event (make sure you update /world/shapes/control/state to the service name that matches your world):

ign service -s /world/shapes/control/state  --reqtype  ignition.msgs.WorldControlState --reptype ignition.msgs.Boolean --timeout 2000 --req 'world_control: {pause: true}'

Testing server/client communication through either the new event approach or traditional service approach can be toggled by adding the following to the WorldControl plugin's XML (true for event, false for service - see an example here):

<use_event>true</use_event>

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge

Signed-off-by: Ashton Larkin <ashton@openrobotics.org>
@adlarkin adlarkin added the needs upstream release Blocked by a release of an upstream library label Oct 14, 2021
@github-actions github-actions bot added 🌱 garden Ignition Garden 🏯 fortress Ignition Fortress labels Oct 14, 2021
@osrf-triage osrf-triage added this to Inbox in Core development Oct 14, 2021
Signed-off-by: Ashton Larkin <ashton@openrobotics.org>
@adlarkin adlarkin marked this pull request as ready for review October 22, 2021 16:34
@adlarkin
Copy link
Contributor Author

adlarkin commented Oct 22, 2021

This should now be ready for initial review. I have a question for whoever reviews this: #306 (comment)

I also left some notes in the Test It section of this PR about how this can be tested. I'm not too familiar with testing GUI code though, so if someone else has thoughts about a better way of testing, please let me know!

Signed-off-by: Ashton Larkin <ashton@openrobotics.org>
@adlarkin adlarkin force-pushed the adlarkin/share_gui_ecm_changes branch from 0eb1905 to 915a1a6 Compare October 29, 2021 21:26
@adlarkin adlarkin changed the title share updated GUI ECM info with server on play Emit an event on play/pause/step instead of calling a service Oct 29, 2021
@adlarkin
Copy link
Contributor Author

@nkoenig I have updated this PR to reflect the new design that was discussed in gazebosim/gz-sim#1109 (comment).

include/ignition/gui/GuiEvents.hh Outdated Show resolved Hide resolved
src/plugins/world_control/WorldControl.cc Outdated Show resolved Hide resolved
src/plugins/world_control/WorldControl.cc Show resolved Hide resolved
Core development automation moved this from In progress to In review Oct 30, 2021
Signed-off-by: Ashton Larkin <ashton@openrobotics.org>
Signed-off-by: Ashton Larkin <ashton@openrobotics.org>
@adlarkin
Copy link
Contributor Author

adlarkin commented Nov 2, 2021

@chapulina the tests for the WorldControl plugin use the service approach instead of the new event approach (see de55398). Do tests need to be added for the event approach as well? If so, I'm not sure how this would be tested since the receiving end of the service is in gazebosim/gz-sim#1109.

…ior by default

Signed-off-by: Nate Koenig <nate@openrobotics.org>
@nkoenig
Copy link
Contributor

nkoenig commented Nov 2, 2021

I think the step button on the GUI now toggles the Play button.

@adlarkin
Copy link
Contributor Author

adlarkin commented Nov 2, 2021

I think the step button on the GUI now toggles the Play button.

Are you referring to what I'm seeing in gazebosim/gz-sim#1109 (comment)?

Signed-off-by: Ashton Larkin <ashton@openrobotics.org>
@adlarkin
Copy link
Contributor Author

adlarkin commented Nov 2, 2021

I think the step button on the GUI now toggles the Play button.

Are you referring to what I'm seeing in ignitionrobotics/ign-gazebo#1109 (comment)?

This should be fixed now - see gazebosim/gz-sim#1109 (comment)

Copy link
Contributor

@chapulina chapulina left a comment

Choose a reason for hiding this comment

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

Do tests need to be added for the event approach as well?

That would be ideal

If so, I'm not sure how this would be tested since the receiving end of the service is in gazebosim/gz-sim#1109.

How about listening to the event on the test and check that it is called? Maybe you can create a simple class that installs a filter 🤔

src/plugins/world_control/WorldControl.cc Outdated Show resolved Hide resolved
Signed-off-by: Ashton Larkin <ashton@openrobotics.org>
Signed-off-by: Ashton Larkin <ashton@openrobotics.org>
@adlarkin
Copy link
Contributor Author

adlarkin commented Nov 3, 2021

How about listening to the event on the test and check that it is called? Maybe you can create a simple class that installs a filter thinking

I've added a test for the event approach in 84887d0 and 4148b9a.

@adlarkin adlarkin changed the title Emit an event on play/pause/step instead of calling a service Support emitting an event on play/pause/step Nov 3, 2021
adlarkin and others added 2 commits November 3, 2021 11:19
Copy link
Contributor

@nkoenig nkoenig left a comment

Choose a reason for hiding this comment

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

Works for me. I'd like to switch out the header stepping flag in Garden. Here is the start: gazebosim/gz-msgs#199.

@nkoenig
Copy link
Contributor

nkoenig commented Nov 4, 2021

@adlarkin , @chapulina would it be possible to get this in today so that I can make a release and unblock gazebosim/gz-sim#1157?

@adlarkin
Copy link
Contributor Author

adlarkin commented Nov 4, 2021

would it be possible to get this in today

That's okay with me - once @chapulina takes a look and no more changes are requested, feel free to merge.

I am seeing a new issue in Windows CI though that's related to the tests I added:

[703.453s] C:\Jenkins\workspace\ign_gui-pr-win\ws\build\ignition-gui6\src\plugins\world_control\moc_WorldControlEventListener.cpp(66,99): error C2491: 'ignition::gui::WorldControlEventListener::staticMetaObject': definition of dllimport static data member not allowed [C:\Jenkins\workspace\ign_gui-pr-win\ws\build\ignition-gui6\src\plugins\world_control\WorldControl.vcxproj]

Does anyone know how to fix this?

Signed-off-by: Nate Koenig <nate@openrobotics.org>
@nkoenig
Copy link
Contributor

nkoenig commented Nov 4, 2021

[703.453s] C:\Jenkins\workspace\ign_gui-pr-win\ws\build\ignition-gui6\src\plugins\world_control\moc_WorldControlEventListener.cpp(66,99): error C2491: 'ignition::gui::WorldControlEventListener::staticMetaObject': definition of dllimport static data member not allowed [C:\Jenkins\workspace\ign_gui-pr-win\ws\build\ignition-gui6\src\plugins\world_control\WorldControl.vcxproj]

Does anyone know how to fix this?

All of your tests were set to run only on linux, so I disable their compilation on windows in 80a64f4.

@nkoenig
Copy link
Contributor

nkoenig commented Nov 4, 2021

Alright, CI is green-enough. There is a flaky test that has failed on Focal, but has passed in other iterations.

@nkoenig nkoenig removed the needs upstream release Blocked by a release of an upstream library label Nov 4, 2021
@nkoenig
Copy link
Contributor

nkoenig commented Nov 5, 2021

@chapulina , I'm going to merge this by 10am today unless you stop me.

Copy link
Contributor

@chapulina chapulina left a comment

Choose a reason for hiding this comment

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

I just have minor comments, no blockers

@@ -27,6 +27,7 @@
#include <ignition/common/MouseEvent.hh>
#include <ignition/math/Vector2.hh>
#include <ignition/math/Vector3.hh>
#include <ignition/msgs.hh>
Copy link
Contributor

Choose a reason for hiding this comment

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

It's preferable to include just the message that's needed, this helps with compile times.

Copy link
Contributor

Choose a reason for hiding this comment

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

Done in 8e7cb8f

this->dataPtr->pause = false;
this->dataPtr->node.Request(this->dataPtr->controlService, req, cb);
if (this->dataPtr->useEvent)
Copy link
Contributor

Choose a reason for hiding this comment

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

This block from 280 to 294 is repeated 3 times in different functions, consider moving it to a separate function to reduce duplication

Copy link
Contributor

Choose a reason for hiding this comment

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

Done in 8e7cb8f

/// \brief Helper class for testing listening to events emitted by the
/// WorldControl plugin. This is used for testing the event behavior of
/// the WorldControl plugin.
class IGNITION_GUI_VISIBLE WorldControlEventListener : public QObject
Copy link
Contributor

Choose a reason for hiding this comment

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

Great work putting the tests together! Ideally we wouldn't include this as part of the plugin itself, since it's only used for testing. But I think this can be addressed later.

Copy link
Contributor

Choose a reason for hiding this comment

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

Done in 8e7cb8f

WorldControl_TEST.cc
)

if (NOT MSVC)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, why did you need to separate Windows here? We're already disabling the test on Windows in the test's body.

Copy link
Contributor

Choose a reason for hiding this comment

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

Because Windows would still compile the testing framework and produce compile time errors.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. It was compiling before. Not sure what causes the compiler error here, but I think it's ok to address this later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As a follow-up, yes,the tests themselves ignore windows. For example: https://github.com/ignitionrobotics/ign-gui/blob/ignition-gui6_6.0.0/src/plugins/world_control/WorldControl_TEST.cc#L66

However, the new helper test class that was added for checking events (#306 (comment)) has to be added as a QT header, or else there will be linking errors. So, it seemed like this new QT header is what was causing issues on windows, and @nkoenig made a patch in #306 (comment) to prevent compiling the helper test class header on windows. I'm not sure if there's a better way to handle this or not, but hopefully that provides some more context/insights about this change.

Copy link
Contributor

Choose a reason for hiding this comment

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

I tried a few different options to make the header compile on windows, and gave up.

chapulina and others added 2 commits November 5, 2021 09:10
@nkoenig nkoenig merged commit 5898716 into ign-gui6 Nov 5, 2021
Core development automation moved this from In review to Done Nov 5, 2021
@nkoenig nkoenig deleted the adlarkin/share_gui_ecm_changes branch November 5, 2021 17:19
@chapulina chapulina moved this from Done to Highlights in Core development Nov 8, 2021
srmainwaring pushed a commit to srmainwaring/gz-gui that referenced this pull request Nov 19, 2021
* share updated GUI ECM info with server on play

Signed-off-by: Ashton Larkin <ashton@openrobotics.org>

* clarify docs and fix service request type

Signed-off-by: Ashton Larkin <ashton@openrobotics.org>

* send event on play/pause/step

Signed-off-by: Ashton Larkin <ashton@openrobotics.org>

* support service and event

Signed-off-by: Ashton Larkin <ashton@openrobotics.org>

* fix tests

Signed-off-by: Ashton Larkin <ashton@openrobotics.org>

* Flip the default settng of usEvent in order to maintain current behavior by default

Signed-off-by: Nate Koenig <nate@openrobotics.org>

* ignore stats msgs triggered by a step

Signed-off-by: Ashton Larkin <ashton@openrobotics.org>

* explicit constructor for new gui event

Signed-off-by: Ashton Larkin <ashton@openrobotics.org>

* remove deprecation notes (support both event and service)

Signed-off-by: Ashton Larkin <ashton@openrobotics.org>

* test event behavior

Signed-off-by: Ashton Larkin <ashton@openrobotics.org>

* add missing helper test class

Signed-off-by: Ashton Larkin <ashton@openrobotics.org>

* Disable tests on windows

Signed-off-by: Nate Koenig <nate@openrobotics.org>

* Address PR feedback

Signed-off-by: Nate Koenig <nate@openrobotics.org>

Co-authored-by: Nate Koenig <nate@openrobotics.org>
Co-authored-by: Louise Poubel <louise@openrobotics.org>
@j-rivero j-rivero removed this from Highlights in Core development May 6, 2022
@scpeters scpeters mentioned this pull request Apr 8, 2023
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏯 fortress Ignition Fortress 🌱 garden Ignition Garden
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants