Skip to content

Commit

Permalink
Implement inequality operator for the PlannedContact class (#750)
Browse files Browse the repository at this point in the history
  • Loading branch information
GiulioRomualdi authored Nov 6, 2023
1 parent 9f9e90d commit 7de0256
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions bindings/python/Contacts/src/Contacts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_<EstimatedContact, ContactBase>(module, "EstimatedContact")
Expand Down
8 changes: 8 additions & 0 deletions src/Contacts/include/BipedalLocomotion/Contacts/Contact.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
8 changes: 6 additions & 2 deletions src/Contacts/src/Contact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down

0 comments on commit 7de0256

Please sign in to comment.