This file implements a NLOC unit tests. For more intuitive examples, visit the tutorial.
#include <chrono>
#include <fenv.h>
#include <gtest/gtest.h>
#include "DiehlSystem.h"
#include "nloc_test_dir.h"
namespace optcon {
namespace example {
using std::shared_ptr;
TEST(NLOCTest, NonlinearSystemAlgorithmComparison)
{
std::cout << "setting up problem " << std::endl;
std::string configFile = std::string(NLOC_TEST_DIR) + "/nonlinear/solver.info";
std::string
costFunctionFile = std::string(NLOC_TEST_DIR) +
"/nonlinear/cost.info";
Eigen::Matrix<double, 1, 1> x_0;
Eigen::Matrix<double, 1, 1> x_f;
gnms_settings.
load(configFile,
true,
"gnms");
ilqr_settings.
load(configFile,
true,
"ilqr");
std::shared_ptr<ControlledSystem<state_dim, control_dim>> nonlinearSystem(
new Dynamics);
std::shared_ptr<LinearSystem<state_dim, control_dim>> analyticLinearSystem(new LinearizedSystem);
std::shared_ptr<CostFunctionQuadratic<state_dim, control_dim>> costFunction(
size_t nSteps = gnms_settings.
computeK(tf);
uff_init_guess << -(x_0(0) + 1) * x_0(0);
tf, x0[0], nonlinearSystem, costFunction, analyticLinearSystem);
tf, x0[0], nonlinearSystem, costFunction, analyticLinearSystem);
std::cout << "initializing solvers" << std::endl;
NLOptConSolver gnms(optConProblem1, gnms_settings);
NLOptConSolver ilqr(optConProblem2, ilqr_settings);
std::cout << "============ running solvers ==============" << std::endl;
for (
size_t i = 0;
i < xRollout_gnms.
size();
i++)
{
ASSERT_NEAR(xRollout_gnms[
i](0), xRollout_ilqr[
i](0), 1e-4);
}
for (
size_t i = 0;
i < uRollout_ilqr.
size();
i++)
{
ASSERT_NEAR(uRollout_gnms[
i](0), uRollout_ilqr[
i](0), 1e-4);
}
}
}
}
}