ocp_nlp_interface

Functions

static int ocp_nlp_plan_calculate_size(int N)
static ocp_nlp_plan *ocp_nlp_plan_assign(int N, void *raw_memory)
static void ocp_nlp_plan_initialize_default(ocp_nlp_plan *plan)
ocp_nlp_plan *ocp_nlp_plan_create(int N)

Constructs an empty plan struct (user nlp configuration), all fields are set to a default/invalid state.

Parameters
  • N: Horizon length

void ocp_nlp_plan_destroy(void *plan_)

Destructor for plan struct, frees memory.

Parameters
  • plan_: The plan struct to destroy.

ocp_nlp_config *ocp_nlp_config_create(ocp_nlp_plan plan)

Constructs an nlp configuration struct from a plan.

Parameters
  • plan: The plan (user nlp configuration).

void ocp_nlp_config_destroy(void *config_)

Desctructor of the nlp configuration.

Parameters
  • config_: The configuration struct.

ocp_nlp_dims *ocp_nlp_dims_create(void *config_)

Constructs an struct that contains the dimensions of the variables.

Parameters
  • config_: The configuration struct.

void ocp_nlp_dims_destroy(void *dims_)

Destructor of The dimension struct.

Parameters
  • dims_: The dimension struct.

ocp_nlp_in *ocp_nlp_in_create(ocp_nlp_config *config, ocp_nlp_dims *dims)

Constructs an input struct for a non-linear programs.

Parameters
  • config: The configuration struct.

  • dims: The dimension struct.

void ocp_nlp_in_destroy(void *in)

Destructor of the inputs struct.

Parameters
  • in: The inputs struct.

void ocp_nlp_in_set(ocp_nlp_config *config, ocp_nlp_dims *dims, ocp_nlp_in *in, int stage, const char *field, void *value)

Sets the sampling times for the given stage.

Parameters
  • config: The configuration struct.

  • dims: The dimension struct.

  • in: The inputs struct.

  • stage: Stage number.

  • field: Has to be “Ts” (TBC other options).

  • value: The sampling times (floating point).

int ocp_nlp_dynamics_model_set(ocp_nlp_config *config, ocp_nlp_dims *dims, ocp_nlp_in *in, int stage, const char *fun_type, void *fun_ptr)

Sets the function pointers to the dynamics functions for the given stage.

Parameters
  • config: The configuration struct.

  • dims: The dimension struct.

  • in: The inputs struct.

  • stage: Stage number.

  • fun_type: The name of the function type, either impl_ode_fun, impl_ode_fun_jac_x_xdot, impl_ode_jac_x_xdot_u (TBC)

  • fun_ptr: Function pointer to the dynamics function.

int ocp_nlp_cost_model_set(ocp_nlp_config *config, ocp_nlp_dims *dims, ocp_nlp_in *in, int stage, const char *field, void *value)

Sets the function pointers to the cost functions for the given stage.

Parameters
  • config: The configuration struct.

  • dims: The dimension struct.

  • in: The inputs struct.

  • stage: Stage number.

  • field: The name of the field, either nls_res_jac, y_ref, W (others TBC)

  • value: Cost values.

int ocp_nlp_constraints_model_set(ocp_nlp_config *config, ocp_nlp_dims *dims, ocp_nlp_in *in, int stage, const char *field, void *value)

Sets the function pointers to the constraints functions for the given stage.

Parameters
  • config: The configuration struct.

  • dims: The dimension struct.

  • in: The inputs struct.

  • stage: Stage number.

  • field: The name of the field, either lb, ub (others TBC)

  • value: Constraints function or values.

ocp_nlp_out *ocp_nlp_out_create(ocp_nlp_config *config, ocp_nlp_dims *dims)

Constructs an output struct for the non-linear program.

Parameters
  • config: The configuration struct.

  • dims: The dimension struct.

void ocp_nlp_out_destroy(void *out)

Destructor of the output struct.

Parameters
  • out: The output struct.

void ocp_nlp_out_set(ocp_nlp_config *config, ocp_nlp_dims *dims, ocp_nlp_out *out, int stage, const char *field, void *value)

Sets fields in the output struct of an nlp solver, used to initialize the solver.

Parameters
  • config: The configuration struct.

  • dims: The dimension struct.

  • out: The output struct.

  • stage: Stage number.

  • field: The name of the field, either x, u, pi.

  • value: Initialization values.

void ocp_nlp_out_get(ocp_nlp_config *config, ocp_nlp_dims *dims, ocp_nlp_out *out, int stage, const char *field, void *value)

Gets values of fields in the output struct of an nlp solver.

Parameters
  • config: The configuration struct.

  • dims: The dimension struct.

  • out: The output struct.

  • stage: Stage number.

  • field: The name of the field, either x, u, z, pi.

  • value: Pointer to the output memory.

int ocp_nlp_dims_get_from_attr(ocp_nlp_config *config, ocp_nlp_dims *dims, ocp_nlp_out *out, int stage, const char *field)
void ocp_nlp_constraint_dims_get_from_attr(ocp_nlp_config *config, ocp_nlp_dims *dims, ocp_nlp_out *out, int stage, const char *field, int *dims_out)
void ocp_nlp_cost_dims_get_from_attr(ocp_nlp_config *config, ocp_nlp_dims *dims, ocp_nlp_out *out, int stage, const char *field, int *dims_out)
void *ocp_nlp_solver_opts_create(ocp_nlp_config *config, ocp_nlp_dims *dims)

Creates an options struct for the non-linear program.

Parameters
  • config: The configuration struct.

  • dims: The dimension struct.

void ocp_nlp_solver_opts_set(ocp_nlp_config *config, void *opts_, const char *field, void *value)

Sets an option.

Parameters
  • config: The configuration struct.

  • opts_: The options struct.

  • field: Name of the option.

  • value: Value of the option.

void ocp_nlp_solver_opts_set_at_stage(ocp_nlp_config *config, void *opts_, int stage, const char *field, void *value)
void ocp_nlp_solver_opts_update(ocp_nlp_config *config, ocp_nlp_dims *dims, void *opts_)

TBC Updates the options.

Parameters
  • config: The configuration struct.

  • dims: The dimension struct.

  • opts_: The options struct.

void ocp_nlp_solver_opts_destroy(void *opts)

Destructor of the options.

Parameters
  • opts: The options struct.

static int ocp_nlp_calculate_size(ocp_nlp_config *config, ocp_nlp_dims *dims, void *opts_)
static ocp_nlp_solver *ocp_nlp_assign(ocp_nlp_config *config, ocp_nlp_dims *dims, void *opts_, void *raw_memory)
ocp_nlp_solver *ocp_nlp_solver_create(ocp_nlp_config *config, ocp_nlp_dims *dims, void *opts_)

Creates an ocp solver.

Return

The solver.

Parameters
  • config: The configuration struct.

  • dims: The dimension struct.

  • opts_: The options struct.

void ocp_nlp_solver_destroy(void *solver)

Destructor of the solver.

Parameters
  • solver: The solver struct.

int ocp_nlp_solve(ocp_nlp_solver *solver, ocp_nlp_in *nlp_in, ocp_nlp_out *nlp_out)

Solves the optimal control problem.

Call ocp_nlp_precompute before calling this functions (TBC).

Parameters
  • solver: The solver struct.

  • nlp_in: The inputs struct.

  • nlp_out: The output struct.

int ocp_nlp_precompute(ocp_nlp_solver *solver, ocp_nlp_in *nlp_in, ocp_nlp_out *nlp_out)

Performs precomputations for the solver.

Needs to be called before ocl_nlp_solve (TBC).

Parameters
  • solver: The solver struct.

  • nlp_in: The inputs struct.

  • nlp_out: The output struct.

void ocp_nlp_eval_param_sens(ocp_nlp_solver *solver, char *field, int stage, int index, ocp_nlp_out *sens_nlp_out)
void ocp_nlp_get(ocp_nlp_config *config, ocp_nlp_solver *solver, const char *field, void *return_value_)

Parameters
  • config: The configuration struct.

  • solver: The solver struct.

  • field: Supports “sqp_iter”, “status”, “nlp_res”, “time_tot”, …

  • return_value_: Pointer to the output memory.

void ocp_nlp_get_at_stage(ocp_nlp_config *config, ocp_nlp_dims *dims, ocp_nlp_solver *solver, int stage, const char *field, void *value)
void ocp_nlp_set(ocp_nlp_config *config, ocp_nlp_solver *solver, int stage, const char *field, void *value)

Sets the initial guesses for the integrator for the given stage.

Parameters
  • config: The configuration struct.

  • solver: The ocp_nlp_solver struct.

  • stage: Stage number.

  • field: Supports “z_guess”, “xdot_guess” (IRK), “phi_guess” (GNSF-IRK)

  • value: The initial guess for the algebraic variables in the integrator (if continuous model is used).

Enums

enum ocp_nlp_solver_t

Solution methods for optimal control problems.

Values:

SQP
SQP_RTI
INVALID_NLP_SOLVER
enum ocp_nlp_cost_t

Types of the cost function.

Values:

LINEAR_LS
NONLINEAR_LS
EXTERNAL
INVALID_COST
enum ocp_nlp_dynamics_t

Types of the system dynamics, discrete or continuous time.

Values:

CONTINUOUS_MODEL
DISCRETE_MODEL
INVALID_DYNAMICS
enum ocp_nlp_constraints_t

Constraint types.

Values:

BGH

Comprises simple bounds, polytopic constraints, general non-linear constraints.

BGP

Comprises simple bounds, polytopic constraints, general non-linear constraints, and positive definite constraints.

INVALID_CONSTRAINT
enum ocp_nlp_reg_t

Regularization types.

Values:

NO_REGULARIZE
MIRROR
PROJECT
PROJECT_REDUC_HESS
CONVEXIFY
INVALID_REGULARIZE

Functions

ocp_nlp_plan *ocp_nlp_plan_create(int N)

Constructs an empty plan struct (user nlp configuration), all fields are set to a default/invalid state.

Parameters
  • N: Horizon length

void ocp_nlp_plan_destroy(void *plan_)

Destructor for plan struct, frees memory.

Parameters
  • plan_: The plan struct to destroy.

ocp_nlp_config *ocp_nlp_config_create(ocp_nlp_plan plan)

Constructs an nlp configuration struct from a plan.

Parameters
  • plan: The plan (user nlp configuration).

void ocp_nlp_config_destroy(void *config_)

Desctructor of the nlp configuration.

Parameters
  • config_: The configuration struct.

ocp_nlp_dims *ocp_nlp_dims_create(void *config_)

Constructs an struct that contains the dimensions of the variables.

Parameters
  • config_: The configuration struct.

void ocp_nlp_dims_destroy(void *dims_)

Destructor of The dimension struct.

Parameters
  • dims_: The dimension struct.

ocp_nlp_in *ocp_nlp_in_create(ocp_nlp_config *config, ocp_nlp_dims *dims)

Constructs an input struct for a non-linear programs.

Parameters
  • config: The configuration struct.

  • dims: The dimension struct.

void ocp_nlp_in_destroy(void *in)

Destructor of the inputs struct.

Parameters
  • in: The inputs struct.

void ocp_nlp_in_set(ocp_nlp_config *config, ocp_nlp_dims *dims, ocp_nlp_in *in, int stage, const char *field, void *value)

Sets the sampling times for the given stage.

Parameters
  • config: The configuration struct.

  • dims: The dimension struct.

  • in: The inputs struct.

  • stage: Stage number.

  • field: Has to be “Ts” (TBC other options).

  • value: The sampling times (floating point).

int ocp_nlp_dynamics_model_set(ocp_nlp_config *config, ocp_nlp_dims *dims, ocp_nlp_in *in, int stage, const char *fun_type, void *fun_ptr)

Sets the function pointers to the dynamics functions for the given stage.

Parameters
  • config: The configuration struct.

  • dims: The dimension struct.

  • in: The inputs struct.

  • stage: Stage number.

  • fun_type: The name of the function type, either impl_ode_fun, impl_ode_fun_jac_x_xdot, impl_ode_jac_x_xdot_u (TBC)

  • fun_ptr: Function pointer to the dynamics function.

int ocp_nlp_cost_model_set(ocp_nlp_config *config, ocp_nlp_dims *dims, ocp_nlp_in *in, int stage, const char *field, void *value)

Sets the function pointers to the cost functions for the given stage.

Parameters
  • config: The configuration struct.

  • dims: The dimension struct.

  • in: The inputs struct.

  • stage: Stage number.

  • field: The name of the field, either nls_res_jac, y_ref, W (others TBC)

  • value: Cost values.

int ocp_nlp_constraints_model_set(ocp_nlp_config *config, ocp_nlp_dims *dims, ocp_nlp_in *in, int stage, const char *field, void *value)

Sets the function pointers to the constraints functions for the given stage.

Parameters
  • config: The configuration struct.

  • dims: The dimension struct.

  • in: The inputs struct.

  • stage: Stage number.

  • field: The name of the field, either lb, ub (others TBC)

  • value: Constraints function or values.

ocp_nlp_out *ocp_nlp_out_create(ocp_nlp_config *config, ocp_nlp_dims *dims)

Constructs an output struct for the non-linear program.

Parameters
  • config: The configuration struct.

  • dims: The dimension struct.

void ocp_nlp_out_destroy(void *out)

Destructor of the output struct.

Parameters
  • out: The output struct.

void ocp_nlp_out_set(ocp_nlp_config *config, ocp_nlp_dims *dims, ocp_nlp_out *out, int stage, const char *field, void *value)

Sets fields in the output struct of an nlp solver, used to initialize the solver.

Parameters
  • config: The configuration struct.

  • dims: The dimension struct.

  • out: The output struct.

  • stage: Stage number.

  • field: The name of the field, either x, u, pi.

  • value: Initialization values.

void ocp_nlp_out_get(ocp_nlp_config *config, ocp_nlp_dims *dims, ocp_nlp_out *out, int stage, const char *field, void *value)

Gets values of fields in the output struct of an nlp solver.

Parameters
  • config: The configuration struct.

  • dims: The dimension struct.

  • out: The output struct.

  • stage: Stage number.

  • field: The name of the field, either x, u, z, pi.

  • value: Pointer to the output memory.

void ocp_nlp_get_at_stage(ocp_nlp_config *config, ocp_nlp_dims *dims, ocp_nlp_solver *solver, int stage, const char *field, void *value)
int ocp_nlp_dims_get_from_attr(ocp_nlp_config *config, ocp_nlp_dims *dims, ocp_nlp_out *out, int stage, const char *field)
void ocp_nlp_constraint_dims_get_from_attr(ocp_nlp_config *config, ocp_nlp_dims *dims, ocp_nlp_out *out, int stage, const char *field, int *dims_out)
void ocp_nlp_cost_dims_get_from_attr(ocp_nlp_config *config, ocp_nlp_dims *dims, ocp_nlp_out *out, int stage, const char *field, int *dims_out)
void *ocp_nlp_solver_opts_create(ocp_nlp_config *config, ocp_nlp_dims *dims)

Creates an options struct for the non-linear program.

Parameters
  • config: The configuration struct.

  • dims: The dimension struct.

void ocp_nlp_solver_opts_destroy(void *opts)

Destructor of the options.

Parameters
  • opts: The options struct.

void ocp_nlp_solver_opts_set(ocp_nlp_config *config, void *opts_, const char *field, void *value)

Sets an option.

Parameters
  • config: The configuration struct.

  • opts_: The options struct.

  • field: Name of the option.

  • value: Value of the option.

void ocp_nlp_solver_opts_set_at_stage(ocp_nlp_config *config, void *opts_, int stage, const char *field, void *value)
void ocp_nlp_solver_opts_update(ocp_nlp_config *config, ocp_nlp_dims *dims, void *opts_)

TBC Updates the options.

Parameters
  • config: The configuration struct.

  • dims: The dimension struct.

  • opts_: The options struct.

ocp_nlp_solver *ocp_nlp_solver_create(ocp_nlp_config *config, ocp_nlp_dims *dims, void *opts_)

Creates an ocp solver.

Return

The solver.

Parameters
  • config: The configuration struct.

  • dims: The dimension struct.

  • opts_: The options struct.

void ocp_nlp_solver_destroy(void *solver)

Destructor of the solver.

Parameters
  • solver: The solver struct.

int ocp_nlp_solve(ocp_nlp_solver *solver, ocp_nlp_in *nlp_in, ocp_nlp_out *nlp_out)

Solves the optimal control problem.

Call ocp_nlp_precompute before calling this functions (TBC).

Parameters
  • solver: The solver struct.

  • nlp_in: The inputs struct.

  • nlp_out: The output struct.

int ocp_nlp_precompute(ocp_nlp_solver *solver, ocp_nlp_in *nlp_in, ocp_nlp_out *nlp_out)

Performs precomputations for the solver.

Needs to be called before ocl_nlp_solve (TBC).

Parameters
  • solver: The solver struct.

  • nlp_in: The inputs struct.

  • nlp_out: The output struct.

void ocp_nlp_eval_param_sens(ocp_nlp_solver *solver, char *field, int stage, int index, ocp_nlp_out *sens_nlp_out)
void ocp_nlp_get(ocp_nlp_config *config, ocp_nlp_solver *solver, const char *field, void *return_value_)

Parameters
  • config: The configuration struct.

  • solver: The solver struct.

  • field: Supports “sqp_iter”, “status”, “nlp_res”, “time_tot”, …

  • return_value_: Pointer to the output memory.

void ocp_nlp_set(ocp_nlp_config *config, ocp_nlp_solver *solver, int stage, const char *field, void *value)

Sets the initial guesses for the integrator for the given stage.

Parameters
  • config: The configuration struct.

  • solver: The ocp_nlp_solver struct.

  • stage: Stage number.

  • field: Supports “z_guess”, “xdot_guess” (IRK), “phi_guess” (GNSF-IRK)

  • value: The initial guess for the algebraic variables in the integrator (if continuous model is used).

struct ocp_nlp_plan
#include <ocp_nlp_interface.h>

Structure to store the configuration of a non-linear program.

Public Members

ocp_qp_solver_plan ocp_qp_solver_plan

QP solver configuration.

sim_solver_plan *sim_solver_plan

Simulation solver configuration for each stage.

ocp_nlp_solver_t nlp_solver

Nlp solver type.

ocp_nlp_reg_t regularization

Regularization type, defaults to no regularization.

ocp_nlp_cost_t *nlp_cost

Cost type for each stage.

ocp_nlp_dynamics_t *nlp_dynamics

Dynamics type for each stage.

ocp_nlp_constraints_t *nlp_constraints

Constraints type for each stage.

int N

Horizon length.

struct ocp_nlp_solver
#include <ocp_nlp_interface.h>

Structure to store the state/configuration for the non-linear programming solver.

Public Members

ocp_nlp_config *config
void *dims
void *opts
void *mem
void *work