ulqr  0.1.0
Riccati Solver

Data Structures

struct  RiccatiSolver
 Solver that uses Riccati recursion to solve an LQR problem. More...
 

Functions

int ulqr_SolveRiccati (RiccatiSolver *solver)
 Solve the LQR problem using Riccati recursion and a forward simulation of the linear dynamics. More...
 
int ulqr_BackwardPass (RiccatiSolver *solver)
 Run the Riccati solver backward pass. More...
 
int ulqr_ForwardPass (RiccatiSolver *solver)
 Run the Riccati forward pass to solve for the solution vector. More...
 
RiccatiSolverulqr_NewRiccatiSolver (int nstates, int ninputs, int nhorizon)
 Initialize a new Riccati solver. More...
 
int ulqr_FreeRiccatiSolver (RiccatiSolver **solver)
 Free the memory for a Riccati solver. More...
 
int ulqr_PrintRiccatiSummary (RiccatiSolver *solver)
 Prints a summary of the solve. More...
 
int ulqr_GetNumVars (RiccatiSolver *solver)
 
enum ulqr_ReturnCode ulqr_SetInitialState (RiccatiSolver *solver, double *x0)
 Set the initial state. More...
 
enum ulqr_ReturnCode ulqr_SetCost (RiccatiSolver *solver, const double *Q, const double *R, const double *H, const double *q, const double *r, double c, int k_start, int k_end)
 
enum ulqr_ReturnCode ulqr_SetDynamics (RiccatiSolver *solver, const double *A, const double *B, const double *f, int k_start, int k_end)
 
Matrixulqr_GetA (RiccatiSolver *solver, int k)
 Get (n,n) state transition matrix.
 
Matrixulqr_GetB (RiccatiSolver *solver, int k)
 Get (n,m) control input matrix.
 
Matrixulqr_Getf (RiccatiSolver *solver, int k)
 Get (n,) affine dynamice term.
 
Matrixulqr_GetQ (RiccatiSolver *solver, int k)
 Get state cost Hessian.
 
Matrixulqr_GetR (RiccatiSolver *solver, int k)
 Get control cost Hessian.
 
Matrixulqr_GetH (RiccatiSolver *solver, int k)
 Get cost Hessian cross-term (m,n)
 
Matrixulqr_Getq (RiccatiSolver *solver, int k)
 Get affine state cost.
 
Matrixulqr_Getr (RiccatiSolver *solver, int k)
 Get affine control cost.
 
double ulqr_Getc (RiccatiSolver *solver, int k)
 Get cost constant.
 
Matrixulqr_GetFeedbackGain (RiccatiSolver *solver, int k)
 Get (m,n) feedback gain.
 
Matrixulqr_GetFeedforwardGain (RiccatiSolver *solver, int k)
 Get (m,) feedforward gain.
 
Matrixulqr_GetCostToGoHessian (RiccatiSolver *solver, int k)
 Get (n,n) Hessian of the cost-to-go.
 
Matrixulqr_GetCostToGoGradient (RiccatiSolver *solver, int k)
 Get (n,) Gradient of the cost-to-go.
 
Matrixulqr_GetQxx (RiccatiSolver *solver, int k)
 Get (n,n) Action-value state Hessian.
 
Matrixulqr_GetQuu (RiccatiSolver *solver, int k)
 Get (m,m) Action-value control Hessian.
 
Matrixulqr_GetQux (RiccatiSolver *solver, int k)
 Get (m,n) Action-value Hessian cross-term.
 
Matrixulqr_GetQx (RiccatiSolver *solver, int k)
 Get (n,) Action-value state gradient.
 
Matrixulqr_GetQu (RiccatiSolver *solver, int k)
 Get (m,) Action-value conrol gradient.
 
Matrixulqr_GetState (RiccatiSolver *solver, int k)
 Get (n,) state vector.
 
Matrixulqr_GetInput (RiccatiSolver *solver, int k)
 Get (m,) input vector.
 
Matrixulqr_GetDual (RiccatiSolver *solver, int k)
 Get (n,) dual vector.
 
double ulqr_CalcCost (RiccatiSolver *solver)
 

Detailed Description

Function Documentation

◆ ulqr_BackwardPass()

int ulqr_BackwardPass ( RiccatiSolver solver)

Run the Riccati solver backward pass.

Uses backward Riccati recursion to solve for the feedback and feedforward LQR gains along the trajectory. Also computes the quadratic cost-to-go and the expansions of the action-value function. All the data is stored in the solver.

Parameters
solverAn initialized RiccatiSolver
Returns
0 if successful

◆ ulqr_ForwardPass()

int ulqr_ForwardPass ( RiccatiSolver solver)

Run the Riccati forward pass to solve for the solution vector.

Computes the solution vector by simulating the linear dynamics forward using the the feedback law \( u = -K x + d \).

Precondition
The LQR gains must have been computed using ulqr_BackwardPass()
Parameters
solverAn initialized RiccatiSolver
Returns
0 if successful

◆ ulqr_FreeRiccatiSolver()

int ulqr_FreeRiccatiSolver ( RiccatiSolver **  solver)

Free the memory for a Riccati solver.

Parameters
solverPointer to initialized Riccati solver.
Postcondition
solver will be NULL
Returns
0 if successful

◆ ulqr_NewRiccatiSolver()

RiccatiSolver* ulqr_NewRiccatiSolver ( int  nstates,
int  ninputs,
int  nhorizon 
)

Initialize a new Riccati solver.

Create a new Riccati solver, provided the problem data given by lqrprob.

Parameters
lqrprobContains all the data to describe the LQR problem to be solved.
Returns
An initialized Riccati solver.

◆ ulqr_PrintRiccatiSummary()

int ulqr_PrintRiccatiSummary ( RiccatiSolver solver)

Prints a summary of the solve.

Sample output

NDLQR Riccati Solve Summary
Solve time: 1.24 ms
Backward Pass: 1.13 ms (91.1 % of total)
Foward Pass: 0.11 ms (8.9 % of total)
Final error: 5.05696e-12
Final error after 2nd solve: 5.05696e-12
Precondition
ulqr_SolveRiccati() has already been called
Parameters
solverAn initialized solver
Returns
0 if successful

◆ ulqr_SetInitialState()

enum ulqr_ReturnCode ulqr_SetInitialState ( RiccatiSolver solver,
double *  x0 
)

Set the initial state.

Parameters
solverInitialized RiccatiSolver
x0Initial state. Length must be at least solver->nstates
Returns
Info code

◆ ulqr_SolveRiccati()

int ulqr_SolveRiccati ( RiccatiSolver solver)

Solve the LQR problem using Riccati recursion and a forward simulation of the linear dynamics.

Parameters
solverAn initialized RiccatiSolver
Returns
0 if successful