rsLQR  0.1
Problem Definition

Data Structures

struct  LQRData
 Holds the data for a single time step of LQR. More...
 
struct  LQRProblem
 Describes an LQR problem with affine terms. More...
 

Functions

LQRDatandlqr_ReadLQRDataJSONFile (const char *filename)
 Read an LQRData structure from JSON data. More...
 
LQRProblemndlqr_ReadLQRProblemJSONFile (const char *filename)
 Read and LQRProblem structure from JSON data. More...
 
Matrix ReadMatrixJSONFile (const char *filename, const char *name)
 Read a Matrix from a JSON file. More...
 
int ndlqr_InitializeLQRData (LQRData *lqrdata, double *Q, double *R, double *q, double *r, double c, double *A, double *B, double *d)
 Copy data into an initialized LQRData structure. More...
 
LQRDatandlqr_NewLQRData (int nstates, int ninputs)
 Allocate memory for a new LQRData structure. More...
 
int ndlqr_FreeLQRData (LQRData *lqrdata)
 Free the memory for and LQRData object. More...
 
int ndlqr_CopyLQRData (LQRData *dest, LQRData *src)
 Copies one LQRData object to another. More...
 
Matrix ndlqr_GetA (LQRData *lqrdata)
 Get (n,n) state transition matrix.
 
Matrix ndlqr_GetB (LQRData *lqrdata)
 Get (n,m) control input matrix.
 
Matrix ndlqr_Getd (LQRData *lqrdata)
 Get (n,) affine dynamice term.
 
Matrix ndlqr_GetQ (LQRData *lqrdata)
 Get state cost Hessian.
 
Matrix ndlqr_GetR (LQRData *lqrdata)
 Get control cost Hessian.
 
Matrix ndlqr_Getq (LQRData *lqrdata)
 Get affine state cost.
 
Matrix ndlqr_Getr (LQRData *lqrdata)
 Get affine control cost.
 
void ndlqr_PrintLQRData (LQRData *lqrdata)
 Prints the data contained in LQRData. More...
 
int ndlqr_InitializeLQRProblem (LQRProblem *lqrproblem, double *x0, LQRData **lqrdata)
 Initialize the problem with an initial state and the LQR data. More...
 
LQRProblemndlqr_NewLQRProblem (int nstates, int ninputs, int nhorizon)
 Initialize a new LQRProblem data with unitialized data. More...
 
int ndlqr_FreeLQRProblem (LQRProblem *lqrprob)
 Free the data stored by and LQRProblem. More...
 

Detailed Description

Function Documentation

◆ ndlqr_CopyLQRData()

int ndlqr_CopyLQRData ( LQRData dest,
LQRData src 
)

Copies one LQRData object to another.

The two object must have equivalent dimensionality.

Parameters
destCopy destination
srcSource data
Returns
0 if successful

◆ ndlqr_FreeLQRData()

int ndlqr_FreeLQRData ( LQRData lqrdata)

Free the memory for and LQRData object.

Parameters
lqrdataInitialized LQRData object
Postcondition
lqrdata = NULL
Returns
0 if successful

◆ ndlqr_FreeLQRProblem()

int ndlqr_FreeLQRProblem ( LQRProblem lqrprob)

Free the data stored by and LQRProblem.

Also frees the LQRProblem itself.

Parameters
lqrprobAn initialized LQRProblem
Postcondition
lqrprob is NULL
Returns
0 if successful

◆ ndlqr_InitializeLQRData()

int ndlqr_InitializeLQRData ( LQRData lqrdata,
double *  Q,
double *  R,
double *  q,
double *  r,
double  c,
double *  A,
double *  B,
double *  d 
)

Copy data into an initialized LQRData structure.

Does not allocate any new memory.

Parameters
lqrdataInitialized LQRData struct
QDiagonal of state cost Hessian
RDiagonal of control cost Hessian
qState cost affine term
rControl cost affine term
cConstant cost term
ADynamics state matrix
BDynamics control matrix
dDynamics affine term
Returns
0 if successful

◆ ndlqr_InitializeLQRProblem()

int ndlqr_InitializeLQRProblem ( LQRProblem lqrproblem,
double *  x0,
LQRData **  lqrdata 
)

Initialize the problem with an initial state and the LQR data.

Parameters
lqrproblemAn initialized LQRProblem
x0Initial state vector. The data is copied into the problem.
lqrdataA vector of LQR data. Each element is copied into the problem.
Returns
0 if successful

◆ ndlqr_NewLQRData()

LQRData* ndlqr_NewLQRData ( int  nstates,
int  ninputs 
)

Allocate memory for a new LQRData structure.

Must be paired with a single call to ndlqr_FreeLQRData().

Parameters
nstatesLength of the state vector
ninputsNumber of control inputs
Returns
0 if successful

◆ ndlqr_NewLQRProblem()

LQRProblem* ndlqr_NewLQRProblem ( int  nstates,
int  ninputs,
int  nhorizon 
)

Initialize a new LQRProblem data with unitialized data.

Must be paired with a call to ndlqr_FreeLQRProblem().

Parameters
nstatesLength of the state vector
ninputsNumber of control inputs
nhorizonLength of the horizon (i.e. number of knot points)
Returns

◆ ndlqr_PrintLQRData()

void ndlqr_PrintLQRData ( LQRData lqrdata)

Prints the data contained in LQRData.

Cost data is printed in rows and dynamics data is printed as normal matrices.

Parameters
lqrdata

◆ ndlqr_ReadLQRDataJSONFile()

LQRData* ndlqr_ReadLQRDataJSONFile ( const char *  filename)

Read an LQRData structure from JSON data.

The user is responsible for calling ndlqr_FreeLQRData() after calling this function.

Expected format

The json data is expected to be structured as follows:

{
"index": <integer>,
"nstates": <integer>,
"ninputs": <integer>,
"Q": <array>,
"R": <array>,
"q": <array>,
"r": <array>,
"c": <double>,
"A": <2D array, stored columnwise>,
"B": <2D array, stored columnwise>,
"d": <double>,
}
Parameters
filenamepath to the json file
Returns
An initialized LQRData structure. NULL if unsuccessful.

◆ ndlqr_ReadLQRProblemJSONFile()

LQRProblem* ndlqr_ReadLQRProblemJSONFile ( const char *  filename)

Read and LQRProblem structure from JSON data.

The user is expected to call ndlqr_FreeLQRProblem() after calling this function.

Expected Format

The json data is expected to be structured as follows:

{
"nhorizon": <integer>,
"x0": <array>,
"lqrdata": <array of LQRData>,
}

where each element of lqrdata is of the form specified in ndlqr_ReadLQRDataJSONFile().

Parameters
filenamePath to the json file
Returns
An initialized LQRProblem struct. NULL if unsuccessful.

◆ ReadMatrixJSONFile()

Matrix ReadMatrixJSONFile ( const char *  filename,
const char *  name 
)

Read a Matrix from a JSON file.

Parameters
filenameName of the JSON file
nameName of the JSON field where the data is stored
Returns
Transfers ownership. User must call FreeMatrix.