robotology / gz-sim-yarp-plugins

YARP plugins for Modern Gazebo (gz-sim).
BSD 3-Clause "New" or "Revised" License
8 stars 0 forks source link

Add clock plugin with basic functionality #70

Closed xela-95 closed 5 months ago

xela-95 commented 5 months ago

This PR adds to the gz-sim-yarp-plugins a clock plugin, with the only basic functionality of writing the current simulation time on the yarp /clock port.

Closes #60 , #73

codecov[bot] commented 5 months ago

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (dab8a73) 83.19% compared to head (404f77b) 83.36%.

:exclamation: Current head 404f77b differs from pull request most recent head c619175. Consider uploading reports for the commit c619175 to get more accurate results

Files Patch % Lines
plugins/clock/Clock.cc 80.76% 5 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #70 +/- ## ========================================== + Coverage 83.19% 83.36% +0.17% ========================================== Files 14 16 +2 Lines 964 1004 +40 ========================================== + Hits 802 837 +35 - Misses 162 167 +5 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

xela-95 commented 5 months ago

@traversaro I tried to develop a first basic unit test for the clock plugin, here:

https://github.com/robotology/gz-sim-yarp-plugins/blob/4a06b08fa297f69f3959402f0ecd1d0dd23963c7/tests/clock/ClockTest.cc

The unit test instantiates a gazebo server fixture and reads the /clock port after a certain number of simulation steps have been ran. Then it checks whether the elapsed simulation time received on the port is the one expected (number of timesteps times delta T).

Next I will try to add test to check other expected behaviors, like the pause and reset of simulation.

xela-95 commented 5 months ago

In commit 5acde4f08c7066d4afbf20918ab7b7df9a16cac9 I've implemented the ISystemReset interface. In this way, every time the user requests a simulation reset through Gazebo UI this method is called instead of destructing and re-constructing the plugin with the consequent closing of the yarp port. Now for a subscriber to the port the reset is transparent and it will just see the simulation time starting back from zero.

Unfortunately I've been not able to implement a unit test since the Server object does not expose a Reset() method that I can use to inject such event.

Some issues and PRs talking about reset: