Skip to content

Instantly share code, notes, and snippets.

@superjax
Created April 13, 2017 16:41
Show Gist options
  • Save superjax/2a55f11a292cd7b53624cc8dc36bef8e to your computer and use it in GitHub Desktop.
Save superjax/2a55f11a292cd7b53624cc8dc36bef8e to your computer and use it in GitHub Desktop.
LQR Controller for Python
def lqr(A,B,Q,R):
#first, try to solve the ricatti equation
X = np.matrix(solve_continuous_are(A, B, Q, R))
#compute the LQR gain
K = np.matrix(inv(R)*(B.T*X))
eigVals, eigVecs = eig(A-B*K)
return K, X, eigVals
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment