rsLQR  0.1
Riccati Solver

Data Structures

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

Functions

int ndlqr_SolveRiccati (RiccatiSolver *solver)
 Solve the LQR problem using Riccati recursion and a forward simulation of the linear dynamics. More...
 
int ndlqr_BackwardPass (RiccatiSolver *solver)
 Run the Riccati solver backward pass. More...
 
int ndlqr_ForwardPass (RiccatiSolver *solver)
 Run the Riccati forward pass to solve for the solution vector. More...
 
RiccatiSolverndlqr_NewRiccatiSolver (LQRProblem *lqrprob)
 Initialize a new Riccati solver. More...
 
int ndlqr_FreeRiccatiSolver (RiccatiSolver *solver)
 Free the memory for a Riccati solver. More...
 
int ndlqr_PrintRiccatiSummary (RiccatiSolver *solver)
 Prints a summary of the solve. More...
 
Matrix ndlqr_GetRiccatiSolution (RiccatiSolver *solver)
 Get the solution vector. More...
 
int ndlqr_GetNumVarsRiccati (RiccatiSolver *solver)
 
int ndlqr_CopyRiccatiSolution (RiccatiSolver *solver, double *soln)
 Copies the solution to a user-supplied array. More...
 
int ndlqr_GetRiccatiSolveTimes (RiccatiSolver *solver, double *t_solve, double *t_bp, double *t_fp)
 Get the Riccati solve times. More...
 

Detailed Description

Function Documentation

◆ ndlqr_BackwardPass()

int ndlqr_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

◆ ndlqr_CopyRiccatiSolution()

int ndlqr_CopyRiccatiSolution ( RiccatiSolver solver,
double *  soln 
)

Copies the solution to a user-supplied array.

See ndlqr_CopyRiccatiSolution() for variable ordering

Precondition
ndlqr_SolveRiccati() has already been called
Parameters
solverAn initialized RiccatiSolver that has been solved but not freed
solnDestination for solution vector. Must have length at least equal to solver.nvars.
Returns
0 if successful

◆ ndlqr_ForwardPass()

int ndlqr_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 ndlqr_BackwardPass()
Parameters
solverAn initialized RiccatiSolver
Returns
0 if successful

◆ ndlqr_FreeRiccatiSolver()

int ndlqr_FreeRiccatiSolver ( RiccatiSolver solver)

Free the memory for a Riccati solver.

Parameters
solverInitialized Riccati solver.
Returns
0 if successful
Postcondition
solver will be NULL

◆ ndlqr_GetRiccatiSolution()

Matrix ndlqr_GetRiccatiSolution ( RiccatiSolver solver)

Get the solution vector.

Returns the solution vector as a Matrix object, which is a simple wrapper around a raw pointer which points to the data actually stored by the solver. The user must not free the data, as it is owned by the solver. To get a solution vector owned by the caller, use ndlqr_CopySolution() instead.

Variable ordering

The variabled are ordered as follows:

\[ \begin{bmatrix} \lambda_1^T & x_1^T & u_1^T & \lambda_2^T & \dots & x_{N-1}^T & u_{N-1}^T & \lambda_N^T & x_N^T \end{bmatrix}^T \]

Precondition
ndlqr_SolveRiccati() has already been called
Parameters
solver
Returns

◆ ndlqr_GetRiccatiSolveTimes()

int ndlqr_GetRiccatiSolveTimes ( RiccatiSolver solver,
double *  t_solve,
double *  t_bp,
double *  t_fp 
)

Get the Riccati solve times.

Writes the solve times to the given pointers.

Precondition
ndlqr_SolveRiccati() has already been called
Parameters
solverAn initialized RiccatiSolver
[out]t_solveTotal solve time, in milliseconds
[out]t_bpBackward pass time, in milliseconds
[out]t_fpForward pass time, in milliseconds
Returns
0 if successful

◆ ndlqr_NewRiccatiSolver()

RiccatiSolver* ndlqr_NewRiccatiSolver ( LQRProblem lqrprob)

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.

◆ ndlqr_PrintRiccatiSummary()

int ndlqr_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
ndlqr_SolveRiccati() has already been called
Parameters
solverAn initialized solver
Returns
0 if successful

◆ ndlqr_SolveRiccati()

int ndlqr_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