Skip to content

Commit

Permalink
Merge pull request #88 from gergondet/topic/CoMConstraintJointSelector
Browse files Browse the repository at this point in the history
  • Loading branch information
gergondet authored Jun 12, 2023
2 parents d9c9dc2 + 5a505d2 commit e54d258
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
18 changes: 10 additions & 8 deletions src/QPConstr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,8 @@ CoMIncPlaneConstr::PlaneData::PlaneData(int planeId,

CoMIncPlaneConstr::CoMIncPlaneConstr(const std::vector<rbd::MultiBody> & mbs, int robotIndex, double step)
: robotIndex_(robotIndex), alphaDBegin_(-1), dataVec_(), step_(step), nrVars_(0), nrActivated_(0), activated_(0),
jacCoM_(mbs[robotIndex]), AInEq_(), bInEq_()
jacCoM_(mbs[static_cast<size_t>(robotIndex)]), selector_(Eigen::VectorXd::Ones(jacCoM_.jacobian().cols())), AInEq_(),
bInEq_()
{
}

Expand Down Expand Up @@ -730,8 +731,8 @@ void CoMIncPlaneConstr::reset()

void CoMIncPlaneConstr::updateNrPlanes()
{
AInEq_.setZero(dataVec_.size(), nrVars_);
bInEq_.setZero(dataVec_.size());
AInEq_.setZero(static_cast<Eigen::DenseIndex>(dataVec_.size()), nrVars_);
bInEq_.setZero(static_cast<Eigen::DenseIndex>(dataVec_.size()));
}

void CoMIncPlaneConstr::updateNrVars(const std::vector<rbd::MultiBody> & /* mbs */, const SolverData & data)
Expand All @@ -745,10 +746,9 @@ void CoMIncPlaneConstr::update(const std::vector<rbd::MultiBody> & mbs,
const std::vector<rbd::MultiBodyConfig> & mbcs,
const SolverData & data)
{
using namespace Eigen;

const rbd::MultiBody & mb = mbs[robotIndex_];
const rbd::MultiBodyConfig & mbc = mbcs[robotIndex_];
const rbd::MultiBody & mb = mbs[static_cast<size_t>(robotIndex_)];
const rbd::MultiBodyConfig & mbc = mbcs[static_cast<size_t>(robotIndex_)];
assert(selector_.size() == mb.nrDof());

Eigen::Vector3d com = rbd::computeCoM(mb, mbc);

Expand All @@ -770,7 +770,7 @@ void CoMIncPlaneConstr::update(const std::vector<rbd::MultiBody> & mbs,
nrActivated_ = 0;
if(!activated_.empty())
{
const MatrixXd & jacComMat = jacCoM_.jacobian(mb, mbc);
const Eigen::MatrixXd & jacComMat = jacCoM_.jacobian(mb, mbc);
Eigen::Vector3d comSpeed = jacCoM_.velocity(mb, mbc);
Eigen::Vector3d comNormalAcc = jacCoM_.normalAcceleration(mb, mbc, data.normalAccB(robotIndex_));

Expand All @@ -794,6 +794,8 @@ void CoMIncPlaneConstr::update(const std::vector<rbd::MultiBody> & mbs,

// -dt*normal^T*J_com
AInEq_.block(nrActivated_, alphaDBegin_, 1, mb.nrDof()).noalias() = -(step_ * d.normal.transpose()) * jacComMat;
AInEq_.block(nrActivated_, alphaDBegin_, 1, mb.nrDof()).noalias() =
-(step_ * d.normal.transpose()) * jacComMat * selector_.asDiagonal();

// dampers + ddot + dt*normal^T*J*qdot
bInEq_(nrActivated_) = dampers + distDot + step_ * (d.normal.dot(comNormalAcc) + distDDot);
Expand Down
15 changes: 14 additions & 1 deletion src/Tasks/QPConstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -521,9 +521,21 @@ class TASKS_DLLAPI CoMIncPlaneConstr : public ConstraintFunction<Inequality>
/// @return Number of plane.
std::size_t nrPlanes() const;

/// Remove all plane.
/// Remove all plane
void reset();

/** Access the joint selector
*
* By default the vector selects all joints in the robot
*/
inline Eigen::VectorXd & selector() noexcept { return selector_; }

/** Access the joint selector (const)
*
* By default the vector selects all joints in the robot
*/
inline const Eigen::VectorXd & selector() const noexcept { return selector_; }

/// Reallocate A and b matrix.
void updateNrPlanes();

Expand Down Expand Up @@ -583,6 +595,7 @@ class TASKS_DLLAPI CoMIncPlaneConstr : public ConstraintFunction<Inequality>
std::vector<std::size_t> activated_;

rbd::CoMJacobian jacCoM_;
Eigen::VectorXd selector_;
Eigen::MatrixXd AInEq_;
Eigen::VectorXd bInEq_;
};
Expand Down

0 comments on commit e54d258

Please sign in to comment.