Given some specific matricies, numA, numB, numP, q and r to calculate LQR gains, one can use simply LQRegulatorGains
or solve the same via RiccatiSolve
:
Inverse[r].(numB\[Transpose].RiccatiSolve[{numA, numB}, {q, r, matP}] + matP\[Transpose])
Giving the stated matricies some values, gains can be calculated and present the same solution as the aformentions LQRegulatorGains
I am attempting to compile either one of these functions for external use in embeddedhardware to adaptively calculate new gains on the fly but am completely overwhelmed in its generation. As far as I've come to understand not all code can be compiled and there are few and far between examples of higher level functions being compiled.
Is this possible? How would one give Compile matrices as a variable to be updated frequently for the given function?
Test matricies:
{numA, numB, numC, numD}={{{0,1,0},{113.116,-2.45364,0.00808392},{-113.116,2.45364,-0.136792}},{{0},{-15.4569},{261.555}},{{1,0,0},{0,1,0},{0,0,1}},{{0},{0},{0}}}
matP = {{0}, {0}, {0}}
q = DiagonalMatrix[{50, 1, 0.001}];
r = 2 {{1}};