Skip to content

Commit f0c0536

Browse files
fix(mc_solver): Update the dynamic constraint to make use of the new setExternalTorques funtion of Tasks MotionConstr
1 parent 5b2fd73 commit f0c0536

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

include/mc_solver/DynamicsConstraint.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ struct MC_SOLVER_DLLAPI DynamicsConstraint : public KinematicsConstraint
6161
bool infTorque = false,
6262
bool compensateExtTorques = false);
6363

64+
/** \brief Update the constraint
65+
*
66+
* This is called at every iteration of the controller once the constraint has been added to a solver
67+
*
68+
* \param solver Solver in which the constraint has been inserted
69+
*/
70+
void update(QPSolver & solver) override;
71+
6472
/** Returns the tasks::qp::MotionConstr
6573
*
6674
* This assumes the backend was Tasks

src/mc_solver/DynamicsConstraint.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,37 @@ DynamicsConstraint::DynamicsConstraint(const mc_rbdyn::Robots & robots,
147147
{
148148
}
149149

150+
DynamicsConstraint::DynamicsConstraint(const mc_rbdyn::Robots & robots,
151+
unsigned int robotIndex,
152+
double timeStep,
153+
const std::array<double, 3> & damper,
154+
const std::array<double, 2> & damperSecond,
155+
double velocityPercent,
156+
bool infTorque,
157+
bool compensateExtTorques)
158+
: KinematicsConstraint(robots, robotIndex, timeStep, damper, damperSecond, velocityPercent),
159+
motion_constr_(initialize(backend_, robots, robotIndex, timeStep, infTorque, compensateExtTorques)),
160+
robotIndex_(robotIndex)
161+
{
162+
}
163+
164+
void DynamicsConstraint::update(QPSolver & solver)
165+
{
166+
if(backend_ == QPSolver::Backend::Tasks)
167+
{
168+
auto & robot = solver.robot(robotIndex_);
169+
if(robot.compensationTorques())
170+
{
171+
static_cast<tasks::qp::MotionConstr *>(motion_constr_.get())
172+
->setExternalTorques(robot.compensationTorques().value());
173+
}
174+
else
175+
{
176+
static_cast<tasks::qp::MotionConstr *>(motion_constr_.get())->setExternalTorques(robot.externalTorques());
177+
}
178+
}
179+
}
180+
150181
void DynamicsConstraint::addToSolverImpl(QPSolver & solver)
151182
{
152183
KinematicsConstraint::addToSolverImpl(solver);

0 commit comments

Comments
 (0)