From 6e37d0d2f3e5425f550bcd8f0e6b7dc433132a2d Mon Sep 17 00:00:00 2001 From: Giulio Romualdi Date: Mon, 6 Nov 2023 10:26:14 +0100 Subject: [PATCH 1/2] Implement inequality operator for the PlannedContact class --- bindings/python/Contacts/src/Contacts.cpp | 1 + src/Contacts/include/BipedalLocomotion/Contacts/Contact.h | 8 ++++++++ src/Contacts/src/Contact.cpp | 8 ++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/bindings/python/Contacts/src/Contacts.cpp b/bindings/python/Contacts/src/Contacts.cpp index d26832aa35..8c0a15639e 100644 --- a/bindings/python/Contacts/src/Contacts.cpp +++ b/bindings/python/Contacts/src/Contacts.cpp @@ -73,6 +73,7 @@ void CreateContact(pybind11::module& module) .def_readwrite("deactivation_time", &PlannedContact::deactivationTime) .def("__repr__", &toString) .def("__eq__", &PlannedContact::operator==, py::is_operator()) + .def("__neq__", &PlannedContact::operator!=, py::is_operator()) .def("is_contact_active", &PlannedContact::isContactActive); py::class_(module, "EstimatedContact") diff --git a/src/Contacts/include/BipedalLocomotion/Contacts/Contact.h b/src/Contacts/include/BipedalLocomotion/Contacts/Contact.h index 64d0e8764b..9d15f4c1d3 100644 --- a/src/Contacts/include/BipedalLocomotion/Contacts/Contact.h +++ b/src/Contacts/include/BipedalLocomotion/Contacts/Contact.h @@ -89,6 +89,14 @@ struct PlannedContact : ContactBase */ bool operator==(const PlannedContact& other) const; + /** + * @brief The inequality operator. + * + * @param other The other object used for the comparison. + * @return True if the contacts are the different, false otherwise. + */ + bool operator!=(const PlannedContact& other) const; + /** * @brief Check if the contact is active at a give time instant * diff --git a/src/Contacts/src/Contact.cpp b/src/Contacts/src/Contact.cpp index 9f75e03f8b..9ba6bc756d 100644 --- a/src/Contacts/src/Contact.cpp +++ b/src/Contacts/src/Contact.cpp @@ -13,8 +13,7 @@ using namespace BipedalLocomotion::Contacts; bool PlannedContact::operator==(const PlannedContact& other) const { - bool eq = true; - eq = eq && this->activationTime == other.activationTime; + bool eq = this->activationTime == other.activationTime; eq = eq && this->name == other.name; eq = eq && this->type == other.type; eq = eq && this->pose.coeffs() == other.pose.coeffs(); @@ -23,6 +22,11 @@ bool PlannedContact::operator==(const PlannedContact& other) const return eq; } +bool PlannedContact::operator!=(const PlannedContact& other) const +{ + return !this->operator==(other); +} + bool PlannedContact::isContactActive(const std::chrono::nanoseconds& t) const { return (this->activationTime <= t) && (t < this->deactivationTime); From c784553c2500d618849eadf909c50de02a6b2e1b Mon Sep 17 00:00:00 2001 From: Giulio Romualdi Date: Mon, 6 Nov 2023 10:29:04 +0100 Subject: [PATCH 2/2] Update the CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c022de4b32..d6c992ef04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ All notable changes to this project are documented in this file. - Implement `GlobalCoPEvaluator` in `Contacts` component (https://github.com/ami-iit/bipedal-locomotion-framework/pull/745) - Implement `Wrench::getLocalCoP()` method (https://github.com/ami-iit/bipedal-locomotion-framework/pull/745) - Add tests for classes of `RobotDynamicsEstimator` library (https://github.com/ami-iit/bipedal-locomotion-framework/pull/743) +- Implement inequality operator for the `PlannedContact` class (https://github.com/ami-iit/bipedal-locomotion-framework/pull/750) ### Changed - Remove the possibility to disable the telemetry in `System::AdvanceableRunner` (https://github.com/ami-iit/bipedal-locomotion-framework/pull/726)