This example shows how to use box constraints alongside NLOC and requires HPIPM to be installed The unconstrained Riccati backward-pass is replaced by a high-performance interior-point constrained linear-quadratic Optimal Control solver.
int main(
int argc,
char** argv)
{
std::shared_ptr<ct::core::SystemLinearizer<state_dim, control_dim>> adLinearizer(
std::shared_ptr<ct::optcon::TermQuadratic<state_dim, control_dim>> intermediateCost(
std::shared_ptr<ct::optcon::TermQuadratic<state_dim, control_dim>> finalCost(
intermediateCost->loadConfigFile(ct::optcon::exampleDir + "/nlocCost.info", "intermediateCost", verbose);
finalCost->loadConfigFile(ct::optcon::exampleDir + "/nlocCost.info", "finalCost", verbose);
std::shared_ptr<CostFunctionQuadratic<state_dim, control_dim>> costFunction(
costFunction->addIntermediateTerm(intermediateCost);
costFunction->addFinalTerm(finalCost);
Eigen::VectorXi sp_control(control_dim);
sp_control << 1;
Eigen::VectorXd u_lb(control_dim);
Eigen::VectorXd u_ub(control_dim);
u_lb.setConstant(-0.5);
u_ub = -u_lb;
std::shared_ptr<ControlInputConstraint<state_dim, control_dim>> controlInputBound(
controlInputBound->setName("ControlInputBound");
std::shared_ptr<ConstraintContainerAnalytical<state_dim, control_dim>> inputBoxConstraints(
inputBoxConstraints->addIntermediateConstraint(controlInputBound, verbose);
inputBoxConstraints->initialize();
Eigen::VectorXi sp_state(state_dim);
sp_state << 0, 1;
Eigen::VectorXd x_lb(1);
Eigen::VectorXd x_ub(1);
x_lb.setConstant(-0.2);
x_ub = -x_lb;
std::shared_ptr<StateConstraint<state_dim, control_dim>> stateBound(
stateBound->setName("StateBound");
std::shared_ptr<ConstraintContainerAnalytical<state_dim, control_dim>> stateBoxConstraints(
stateBoxConstraints->addIntermediateConstraint(stateBound, verbose);
stateBoxConstraints->initialize();
x0.setZero();
timeHorizon, x0, oscillatorDynamics, costFunction, adLinearizer);
ilqr_settings.
integrator =
ct::core::IntegrationType::EULERCT;
ilqr_settings.
discretization = NLOptConSettings::APPROXIMATION::FORWARD_EULER;
ilqr_settings.
lqocp_solver = NLOptConSettings::LQOCP_SOLVER::HPIPM_SOLVER;
size_t K = ilqr_settings.
computeK(timeHorizon);
plotResultsOscillator<state_dim, control_dim>(solution.
x_ref(), solution.
uff(), solution.
time());
}