This example shows how to use the nonlinear optimal control solvers iLQR, unconstrained Gauss-Newton-Multiple-Shooting (GNMS), as well as the hybrid methods iLQR-GNMS(M), where M denotes the number of multiple-shooting intervals. This example applies them to a simple second-order oscillator.
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);
x0.setRandom();
timeHorizon, x0, oscillatorDynamics, costFunction, adLinearizer);
nloc_settings.
load(ct::optcon::exampleDir +
"/nlocSolver.info",
true,
"ilqr");
size_t K = nloc_settings.
computeK(timeHorizon);
plotResultsOscillator<state_dim, control_dim>(solution.
x_ref(), solution.
uff(), solution.
time());
}