Skip to content

Commit ea1f81e

Browse files
committed
Terminal constraint on foot height > 0
1 parent 8611a62 commit ea1f81e

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

include/simple-mpc/ocp-handler.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <aligator/modelling/costs/quad-state-cost.hpp>
1515
#include <aligator/modelling/costs/sum-of-costs.hpp>
1616
#include <aligator/modelling/function-xpr-slice.hpp>
17+
#include <aligator/modelling/linear-function-composition.hpp>
1718
#include <proxsuite-nlp/modelling/constraints/box-constraint.hpp>
1819
#include <proxsuite-nlp/modelling/constraints/negative-orthant.hpp>
1920
#ifndef ALIGATOR_PINOCCHIO_V3
@@ -33,6 +34,7 @@ namespace simple_mpc
3334
using NegativeOrthant = proxsuite::nlp::NegativeOrthantTpl<double>;
3435
using EqualityConstraint = proxsuite::nlp::EqualityConstraintTpl<double>;
3536
using FunctionSliceXpr = FunctionSliceXprTpl<double>;
37+
using LinearUnaryFunctionComposition = LinearUnaryFunctionCompositionTpl<double>;
3638

3739
#define SIMPLE_MPC_DEFINE_DEFAULT_MOVE_CTORS(Type) \
3840
Type(Type &&) = default; \

src/fulldynamics.cpp

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <aligator/modelling/multibody/frame-velocity.hpp>
1313
#include <aligator/modelling/multibody/multibody-friction-cone.hpp>
1414
#include <aligator/modelling/multibody/multibody-wrench-cone.hpp>
15+
#include <pinocchio/multibody/fwd.hpp>
1516

1617
namespace simple_mpc
1718
{
@@ -190,7 +191,7 @@ namespace simple_mpc
190191
}
191192
if (land_constraint.at(name))
192193
{
193-
std::vector<int> vel_id = {0, 1, 2};
194+
/* std::vector<int> vel_id = {0, 1, 2};
194195
FrameVelocityResidual velocity_residual = FrameVelocityResidual(
195196
space.ndx(), nu_, model_handler_.getModel(), Motion::Zero(), model_handler_.getFootId(name),
196197
pinocchio::LOCAL_WORLD_ALIGNED);
@@ -205,7 +206,7 @@ namespace simple_mpc
205206
206207
FunctionSliceXpr frame_slice = FunctionSliceXpr(frame_residual, frame_id);
207208
208-
stm.addConstraint(frame_slice, EqualityConstraint());
209+
stm.addConstraint(frame_slice, EqualityConstraint());*/
209210
}
210211
}
211212
}
@@ -405,10 +406,8 @@ namespace simple_mpc
405406
auto cent_mom =
406407
CentroidalMomentumResidual(ter_space.ndx(), nu_, model_handler_.getModel(), Eigen::VectorXd::Zero(6));
407408

408-
term_cost.addCost("state_cost", QuadraticStateCost(ter_space, nu_, x0_, settings_.w_x));
409-
/* term_cost.addCost(
410-
"centroidal_cost",
411-
QuadraticResidualCost(ter_space, cent_mom, settings_.w_cent)); */
409+
term_cost.addCost("state_cost", QuadraticStateCost(ter_space, nu_, x0_, 10 * settings_.w_x));
410+
term_cost.addCost("centroidal_cost", QuadraticResidualCost(ter_space, cent_mom, 10 * settings_.w_cent));
412411

413412
return term_cost;
414413
}
@@ -419,30 +418,33 @@ namespace simple_mpc
419418
{
420419
throw std::runtime_error("Create problem first!");
421420
}
422-
CenterOfMassTranslationResidual com_cstr =
423-
CenterOfMassTranslationResidual(ndx_, nu_, model_handler_.getModel(), com_ref);
421+
auto space = MultibodyPhaseSpace(model_handler_.getModel());
424422

425-
double tau = sqrt(com_ref[2] / 9.81);
426-
DCMPositionResidual dcm_cstr = DCMPositionResidual(ndx_, nu_, model_handler_.getModel(), com_ref, tau);
423+
std::vector<int> frame_id = {2};
427424

428-
problem_->addTerminalConstraint(dcm_cstr, EqualityConstraint());
425+
Eigen::Vector3d b;
426+
b << 0, 0, -0.01;
429427

430-
Motion v_ref = Motion::Zero();
431428
for (auto const & name : model_handler_.getFeetNames())
432429
{
433-
FrameVelocityResidual frame_vel = FrameVelocityResidual(
434-
ndx_, nu_, model_handler_.getModel(), v_ref, model_handler_.getFootId(name), pinocchio::LOCAL_WORLD_ALIGNED);
435-
if (settings_.force_size == 6)
436-
problem_->addTerminalConstraint(frame_vel, EqualityConstraint());
437-
else
438-
{
439-
std::vector<int> vel_id = {0, 1, 2};
430+
FrameTranslationResidual frame_residual_foot = FrameTranslationResidual(
431+
space.ndx(), nu_, model_handler_.getModel(), Eigen::Vector3d::Zero(), model_handler_.getFootId(name));
440432

441-
FunctionSliceXpr vel_slice = FunctionSliceXpr(frame_vel, vel_id);
442-
problem_->addTerminalConstraint(vel_slice, EqualityConstraint());
443-
}
433+
LinearUnaryFunctionComposition cst_height_foot =
434+
LinearUnaryFunctionComposition(frame_residual_foot, -Eigen::Matrix3d::Identity());
435+
FunctionSliceXpr frame_slice_foot = FunctionSliceXpr(cst_height_foot, frame_id);
436+
437+
problem_->addTerminalConstraint(frame_slice_foot, NegativeOrthant());
444438
}
445439

440+
/* CenterOfMassTranslationResidual com_cstr =
441+
CenterOfMassTranslationResidual(ndx_, nu_, model_handler_.getModel(), com_ref);
442+
443+
double tau = sqrt(com_ref[2] / 9.81);
444+
DCMPositionResidual dcm_cstr = DCMPositionResidual(ndx_, nu_, model_handler_.getModel(), com_ref, tau);
445+
446+
problem_->addTerminalConstraint(dcm_cstr, EqualityConstraint());*/
447+
446448
terminal_constraint_ = true;
447449
}
448450

0 commit comments

Comments
 (0)