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

Definition of math::clock #436

Closed
chapulina opened this issue May 31, 2022 · 4 comments
Closed

Definition of math::clock #436

chapulina opened this issue May 31, 2022 · 4 comments
Assignees
Labels
Breaking change Breaks API, ABI or behavior. Must target unstable version. bug Something isn't working 🏛️ ionic Gazebo Ionic

Comments

@chapulina
Copy link
Contributor

Environment

  • OS Version: all
  • Source or binary build? all

Description

Expected behavior

Maybe it's just me, but I was surprised when I noticed that there's an ignition::math::clock class, defined here:

using clock = std::chrono::steady_clock;

and used for example here:

EXPECT_EQ(ignition::math::clock::duration::zero(),
_time.ElapsedStopTime());

I think it's dangerous to define a clock directly under the math namespace in a specific public header like this. It can collide with other clocks defined in other headers.

Actual behavior:

I'd expect that alias to be either:

  • Internal to the StopWatch class and not visible through the public header
  • Defined in a more global place like Helpers.hh if we want that to be the default clock type used throughout all gz-math classes.

Steps to reproduce

Example on how to cause a compilation error:

diff --git a/include/ignition/math/Helpers.hh b/include/ignition/math/Helpers.hh
index 7152b522..35d83c1f 100644
--- a/include/ignition/math/Helpers.hh
+++ b/include/ignition/math/Helpers.hh
@@ -220,6 +220,7 @@ namespace ignition
   /// \brief Math classes and function useful in robot applications.
   namespace math
   {
+    using clock = std::chrono::system_clock;
     // Inline bracket to help doxygen filtering.
     inline namespace IGNITION_MATH_VERSION_NAMESPACE {
     //
diff --git a/src/Stopwatch_TEST.cc b/src/Stopwatch_TEST.cc
index 5df56321..2db84f37 100644
--- a/src/Stopwatch_TEST.cc
+++ b/src/Stopwatch_TEST.cc
@@ -18,6 +18,7 @@
 #include <gtest/gtest.h>
 #include <thread>
 
+#include "ignition/math/Helpers.hh"
 #include "ignition/math/Stopwatch.hh"
 
 using namespace ignition;

Suggestion

At this point, removing that definition would break API. Considering that steady_clock is the only clock type used throughout the library (so far), we could consider moving that alias to Helper.hh so that it can be used by classes other than StopWatch, i.e. SpeedLimiter, DiffDriveOdometry, GaussMarkovProcess...

Alternatively, we could deprecate ignition::math::clock from version 7 and encourage downstream users to use std::chrono or define their own aliases as they see fit.

@chapulina chapulina added the bug Something isn't working label May 31, 2022
@scpeters
Copy link
Member

scpeters commented Jun 7, 2022

it's probably better to encourage people to use std::chrono::steady_clock directly and deprecate this alias in math7

@nkoenig you have touched this code in the past; does that seem reasonable?

scpeters added a commit to gazebosim/gz-sim that referenced this issue Jun 8, 2022
Part of gazebosim/gz-math#436.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
chapulina pushed a commit to gazebosim/gz-sim that referenced this issue Jun 8, 2022
Part of gazebosim/gz-math#436.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
@azeey azeey self-assigned this Jun 27, 2024
@scpeters
Copy link
Member

scpeters commented Jul 1, 2024

looks like some math::clock references were removed from gz-sim in gazebosim/gz-sim#1526

scpeters added a commit that referenced this issue Jul 1, 2024
Recommend using std::chrono::steady_clock directly
instead of this alias.

Part of #436.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
scpeters added a commit that referenced this issue Jul 1, 2024
Recommend using std::chrono::steady_clock directly
instead of this alias.

Fixes #436.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
@scpeters
Copy link
Member

scpeters commented Jul 1, 2024

deprecating math::clock in #600

@scpeters scpeters added Breaking change Breaks API, ABI or behavior. Must target unstable version. 🏛️ ionic Gazebo Ionic labels Jul 1, 2024
@azeey azeey assigned scpeters and unassigned azeey Jul 1, 2024
@azeey azeey closed this as completed Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking change Breaks API, ABI or behavior. Must target unstable version. bug Something isn't working 🏛️ ionic Gazebo Ionic
Projects
None yet
Development

No branches or pull requests

3 participants