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.
int main(
int argc,
char** argv)
{
double w_n = 0.1;
double zeta = 5.0;
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(
bool verbose = true;
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);
iLQR.setInitialGuess(initController);
iLQR.solve();
plotResultsOscillator<state_dim, control_dim>(solution.
x_ref(), solution.
uff(), solution.
time());
}
You can run this example with the following command