Simple example how to linearize a system and design an LQR controller.
int main(
int argc,
char** argv)
{
ct::core::ADCGScalar
w_n(50.0);
std::shared_ptr<ct::core::ControlledSystem<state_dim, control_dim, ct::core::ADCGScalar>>
oscillatorDynamics(
ct::core::ADCodegenLinearizer<state_dim, control_dim> adLinearizer(oscillatorDynamics);
adLinearizer.compileJIT();
x.setZero();
u.setZero();
auto A = adLinearizer.getDerivativeState(x, u, t);
auto B = adLinearizer.getDerivativeControl(x, u, t);
quadraticCost.
loadConfigFile(ct::optcon::exampleDir +
"/lqrCost.info",
"termLQR");
std::cout << "A: " << std::endl << A << std::endl << std::endl;
std::cout << "B: " << std::endl << B << std::endl << std::endl;
std::cout << "Q: " << std::endl << Q << std::endl << std::endl;
std::cout << "R: " << std::endl << R << std::endl << std::endl;
std::cout << "LQR gain matrix:" << std::endl << K << std::endl;
return 1;
}