Skip to content

Commit

Permalink
Added coupler constraint
Browse files Browse the repository at this point in the history
Signed-off-by: Aditya Pande <[email protected]>
  • Loading branch information
Aditya Pande committed Aug 9, 2024
1 parent 1abc882 commit 4090f8a
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
37 changes: 37 additions & 0 deletions dart/constraint/CouplerConstraint.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "dart/constraint/CouplerConstraint.hpp"

namespace dart {
namespace constraint {

CouplerConstraint::CouplerConstraint(dynamics::BodyNode* body1, dynamics::BodyNode* body2, double ratio)
: mBodyNode1(body1), mBodyNode2(body2), mRatio(ratio), mImpulse(Eigen::Vector6d::Zero()) {}

void CouplerConstraint::setRatio(double ratio)
{
mRatio = ratio;
}

double CouplerConstraint::getRatio() const
{
return mRatio;
}

void CouplerConstraint::update()
{
// Implement the logic to update the constraint based on the ratio
// For simplicity, we'll assume a direct proportional relationship
Eigen::Vector6d velocity1 = mBodyNode1->getSpatialVelocity();
Eigen::Vector6d velocity2 = mBodyNode2->getSpatialVelocity();

mImpulse = mRatio * (velocity2 - velocity1);
}

void CouplerConstraint::applyImpulse()
{
// Apply equal and opposite impulses to the connected bodies
mBodyNode1->addConstraintImpulse(mImpulse);
mBodyNode2->addConstraintImpulse(-mImpulse);
}

} // namespace constraint
} // namespace dart
32 changes: 32 additions & 0 deletions dart/constraint/CouplerConstraint.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef DART_CONSTRAINT_COUPLERCONSTRAINT_HPP_
#define DART_CONSTRAINT_COUPLERCONSTRAINT_HPP_

#include <dart/dynamics/ConstraintBase.hpp>
#include <dart/dynamics/BodyNode.hpp>

namespace dart {
namespace constraint {

class CouplerConstraint : public ConstraintBase
{
public:
CouplerConstraint(dynamics::BodyNode* body1, dynamics::BodyNode* body2, double ratio);

void setRatio(double ratio);
double getRatio() const;

void update() override;
void applyImpulse() override;

private:
dynamics::BodyNode* mBodyNode1;
dynamics::BodyNode* mBodyNode2;
double mRatio;
Eigen::Vector6d mImpulse;
};

} // namespace constraint
} // namespace dart

#endif // DART_CONSTRAINT_COUPLERCONSTRAINT_HPP_

0 comments on commit 4090f8a

Please sign in to comment.