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

Use ImplPtr, fix rule of 0 #608

Merged
merged 6 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions include/gz/math/Capsule.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ namespace gz
{
namespace math
{
// Foward declarations
class CapsulePrivate;

// Inline bracket to help doxygen filtering.
inline namespace GZ_MATH_VERSION_NAMESPACE {
//
Expand Down
3 changes: 0 additions & 3 deletions include/gz/math/Cylinder.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ namespace gz
{
namespace math
{
// Foward declarations
class CylinderPrivate;

// Inline bracket to help doxygen filtering.
inline namespace GZ_MATH_VERSION_NAMESPACE {
//
Expand Down
22 changes: 3 additions & 19 deletions include/gz/math/MecanumDriveOdometry.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,18 @@
#define GZ_MATH_MECANUMDRIVEODOMETRY_HH_

#include <chrono>
#include <memory>
#include <gz/math/Angle.hh>
#include <gz/math/Export.hh>
#include <gz/math/config.hh>
#include <gz/utils/ImplPtr.hh>

namespace gz
{
namespace math
{
// Inline bracket to help doxygen filtering.
inline namespace GZ_MATH_VERSION_NAMESPACE {
// Forward declarations.
class MecanumDriveOdometryPrivate;

//
Copy link
Contributor

Choose a reason for hiding this comment

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

delete

Copy link
Member Author

Choose a reason for hiding this comment

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

/// \class MecanumDriveOdometry MecanumDriveOdometry.hh
/// gz/math/MecanumDriveOdometry.hh
///
Expand Down Expand Up @@ -59,9 +57,6 @@ namespace gz
/// velocity mean
public: explicit MecanumDriveOdometry(size_t _windowSize = 10);

/// \brief Destructor.
public: ~MecanumDriveOdometry();

/// \brief Initialize the odometry
/// \param[in] _time Current time.
public: void Init(const clock::time_point &_time);
Expand Down Expand Up @@ -134,18 +129,7 @@ namespace gz
/// \return Right wheel radius in meters.
public: double RightWheelRadius() const;


#ifdef _WIN32
// Disable warning C4251 which is triggered by
// std::unique_ptr
#pragma warning(push)
#pragma warning(disable: 4251)
#endif
/// \brief Private data pointer.
private: std::unique_ptr<MecanumDriveOdometryPrivate> dataPtr;
#ifdef _WIN32
#pragma warning(pop)
#endif
GZ_UTILS_IMPL_PTR(dataPtr)
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
GZ_UTILS_IMPL_PTR(dataPtr)
/// \brief Private data pointer.
GZ_UTILS_IMPL_PTR(dataPtr)

Here and elsewhere

Copy link
Member Author

Choose a reason for hiding this comment

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

};
} // namespace GZ_MATH_VERSION_NAMESPACE
} // namespace math
Expand Down
21 changes: 3 additions & 18 deletions include/gz/math/SpeedLimiter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,24 @@
#define GZ_MATH_SYSTEMS_SPEEDLIMITER_HH_

#include <chrono>
#include <memory>
#include <gz/math/config.hh>
#include "gz/math/Helpers.hh"
#include <gz/utils/ImplPtr.hh>

namespace gz
{
namespace math
{
// Inline bracket to help doxygen filtering.
inline namespace GZ_MATH_VERSION_NAMESPACE {
// Forward declaration.
class SpeedLimiterPrivate;

//
Copy link
Contributor

Choose a reason for hiding this comment

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

delete

Copy link
Member Author

Choose a reason for hiding this comment

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

/// \brief Class to limit velocity, acceleration and jerk.
class GZ_MATH_VISIBLE SpeedLimiter
{
/// \brief Constructor.
/// There are no limits by default.
public: SpeedLimiter();

/// \brief Destructor.
public: ~SpeedLimiter();

/// \brief Set minimum velocity limit in m/s, usually <= 0.
/// \param[in] _lim Minimum velocity.
public: void SetMinVelocity(double _lim);
Expand Down Expand Up @@ -130,17 +125,7 @@ inline namespace GZ_MATH_VERSION_NAMESPACE {
double _prevPrevVel,
std::chrono::steady_clock::duration _dt) const;

#ifdef _WIN32
// Disable warning C4251 which is triggered by
// std::unique_ptr
#pragma warning(push)
#pragma warning(disable: 4251)
#endif
/// \brief Private data pointer.
private: std::unique_ptr<SpeedLimiterPrivate> dataPtr;
#ifdef _WIN32
#pragma warning(pop)
#endif
GZ_UTILS_IMPL_PTR(dataPtr)
};
}
}
Expand Down
3 changes: 0 additions & 3 deletions include/gz/math/Sphere.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ namespace gz
{
namespace math
{
// Foward declarations
class SpherePrivate;

// Inline bracket to help doxygen filtering.
inline namespace GZ_MATH_VERSION_NAMESPACE {
//
Expand Down
50 changes: 30 additions & 20 deletions src/MecanumDriveOdometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,28 @@
#include "gz/math/MecanumDriveOdometry.hh"
#include "gz/math/RollingMean.hh"

using namespace gz;
using namespace math;

// The implementation was borrowed from: https://github.com/ros-controls/ros_controllers/blob/melodic-devel/diff_drive_controller/src/odometry.cpp
// And these calculations are based on the following references:
// https://robohub.org/drive-kinematics-skid-steer-and-mecanum-ros-twist-included
// https://research.ijcaonline.org/volume113/number3/pxc3901586.pdf

class gz::math::MecanumDriveOdometryPrivate
namespace gz
{
namespace math
{
inline namespace GZ_MATH_VERSION_NAMESPACE
{
class MecanumDriveOdometry::Implementation
{
/// \brief Constructor.
/// \param[in] _windowSize Rolling window size used to compute the
/// velocity mean.
public: explicit Implementation(size_t _windowSize)
: linearMean(_windowSize), lateralMean(_windowSize),
angularMean(_windowSize)
{
}

/// \brief Integrates the pose.
/// \param[in] _linear Linear velocity.
/// \param[in] _lateral Lateral velocity.
Expand All @@ -51,7 +63,7 @@ class gz::math::MecanumDriveOdometryPrivate
public: double y{0.0};

/// \brief Current heading in radians.
public: Angle heading;
public: gz::math::Angle heading;

/// \brief Current linear velocity in meter/second.
public: double linearVel{0.0};
Expand All @@ -60,7 +72,7 @@ class gz::math::MecanumDriveOdometryPrivate
public: double lateralVel{0.0};

/// \brief Current angular velocity in radians/second.
public: Angle angularVel;
public: gz::math::Angle angularVel;

/// \brief Left wheel radius in meters.
public: double leftWheelRadius{0.0};
Expand All @@ -87,29 +99,27 @@ class gz::math::MecanumDriveOdometryPrivate
public: double backRightWheelOldPos{0.0};

/// \brief Rolling mean accumulators for the linear velocity
public: RollingMean linearMean;
public: gz::math::RollingMean linearMean;

/// \brief Rolling mean accumulators for the lateral velocity
public: RollingMean lateralMean;
public: gz::math::RollingMean lateralMean;

/// \brief Rolling mean accumulators for the angular velocity
public: RollingMean angularMean;
public: gz::math::RollingMean angularMean;

/// \brief Initialized flag.
public: bool initialized{false};
};

//////////////////////////////////////////////////
MecanumDriveOdometry::MecanumDriveOdometry(size_t _windowSize)
: dataPtr(new MecanumDriveOdometryPrivate)
{
this->dataPtr->linearMean.SetWindowSize(_windowSize);
this->dataPtr->lateralMean.SetWindowSize(_windowSize);
this->dataPtr->angularMean.SetWindowSize(_windowSize);
}
}
}

using namespace gz;
using namespace math;

//////////////////////////////////////////////////
MecanumDriveOdometry::~MecanumDriveOdometry()
MecanumDriveOdometry::MecanumDriveOdometry(size_t _windowSize)
: dataPtr(gz::utils::MakeImpl<Implementation>(_windowSize))
{
}

Expand Down Expand Up @@ -292,7 +302,7 @@ double MecanumDriveOdometry::RightWheelRadius() const
}

//////////////////////////////////////////////////
void MecanumDriveOdometryPrivate::IntegrateRungeKutta2(
void MecanumDriveOdometry::Implementation::IntegrateRungeKutta2(
double _linear, double _lateral, double _angular)
{
const double direction = *this->heading + _angular * 0.5;
Expand All @@ -304,7 +314,7 @@ void MecanumDriveOdometryPrivate::IntegrateRungeKutta2(
}

//////////////////////////////////////////////////
void MecanumDriveOdometryPrivate::IntegrateExact(double _linear,
void MecanumDriveOdometry::Implementation::IntegrateExact(double _linear,
double _lateral, double _angular)
{
if (std::fabs(_angular) < 1e-6)
Expand Down
23 changes: 14 additions & 9 deletions src/SpeedLimiter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
#include "gz/math/Helpers.hh"
#include "gz/math/SpeedLimiter.hh"

using namespace gz;
using namespace math;

/// \brief Private SpeedLimiter data class.
class gz::math::SpeedLimiterPrivate
namespace gz
{
namespace math
{
inline namespace GZ_MATH_VERSION_NAMESPACE
{
class SpeedLimiter::Implementation
{
/// \brief Minimum velocity limit.
public: double minVelocity{-std::numeric_limits<double>::infinity()};
Expand All @@ -42,16 +44,19 @@ class gz::math::SpeedLimiterPrivate
/// \brief Maximum jerk limit.
public: double maxJerk{std::numeric_limits<double>::infinity()};
};
}
}
}

using namespace gz;
using namespace math;

//////////////////////////////////////////////////
SpeedLimiter::SpeedLimiter()
: dataPtr(std::make_unique<SpeedLimiterPrivate>())
: dataPtr(gz::utils::MakeImpl<Implementation>())
{
}

//////////////////////////////////////////////////
SpeedLimiter::~SpeedLimiter() = default;

//////////////////////////////////////////////////
void SpeedLimiter::SetMinVelocity(double _lim)
{
Expand Down
Loading