Skip to content
/ Y2F Public

YALMIP to FORCESPRO interface

License

Notifications You must be signed in to change notification settings

embotech/Y2F

Repository files navigation

Y2F - YALMIP to FORCESPRO Interface

This project provides a simple MATLAB interface that connects YALMIP with FORCESPRO. It combines YALMIP's intuitiveness with the high efficiency of FORCESPRO for rapid development.

Installation

Simply download the code to the desired location and add the Y2F folder to your MATLAB search path.

The Y2F interface requires a working YALMIP installation. See https://yalmip.github.io/tutorial/installation/ for instructions on how to install YALMIP.

The code has been tested with YALMIP release 20150919. Older versions might work but have not been tested.

Example Usage

Consider the following linear MPC problem with lower and upper bounds on state and inputs, and a terminal cost term:

\begin{aligned}\text{minimize} \quad & x_N^T P x_N + \sum_{i=0}^{N-1} x_i^T Q x_i + u_i^T R u_i \ \text{s.t.} \quad & x_0 = x(t) \& x_{i+1} = Ax_i + Bu_i \& \underline{x} \leq x_i \leq \bar{x} \& \underline{u} \leq u_i \leq \bar{u}\end{aligned}

This problem is parametric in the initial state x(t), and the first input u0 is typically applied to the system after a solution has been obtained. The following code generates a solver that returns u0, which can then be applied to the system:

% Define variables
X = sdpvar(nx,N+1,'full'); % state trajectory: x0,x1,...,xN (columns of X)
U = sdpvar(nu,N,'full'); % input trajectory: u0,...,u_{N-1} (columns of U)

% Initialize objective and constraints of the problem
cost = 0; const = [];

% Assemble MPC formulation
for i = 1:N        
    % cost
    if( i < N )
        cost = cost + 0.5*X(:,i+1)'*Q*X(:,i+1) + 0.5*U(:,i)'*R*U(:,i);
    else
        cost = cost + 0.5*X(:,N+1)'*P*X(:,N+1) + 0.5*U(:,N)'*R*U(:,N);
    end
    
    % model
    const = [const, X(:,i+1) == A*X(:,i) + B*U(:,i)];

    % bounds
    const = [const, umin <= U(:,i) <= umax];
    const = [const, xmin <= X(:,i+1) <= xmax];
end

controller = optimizerFORCES(const, cost, codeoptions, X(:,1), U(:,1));

The generated solver can then be called using curly braces:

u0 = controller{x0};

Limitations

  • The Y2F interface only supports convex quadratically constrained programs (QCQPs). FORCES' NLP solver is currently not supported.
  • If you have rate constraints or cost, you need to manually define delta variables (e.g. U+ = U + dU, and then constrain dU). Otherwise, Y2F cannot figure out the multistage structure from your problem, and you might obtain a slow solver.

License

The code is licensed under the MIT License. For more information see LICENSE file.

Contributing

See CONTRIBUTING.md file.

Releases

The following Y2F versions have been released since 2021.

Y2F Version Release Date Compatible FORCESPRO Versions
0.2.0 Jun 12, 2023 6.2.0 onwards
0.1.20 Sep 8, 2021 5.0.0 - 6.1.0 [1]
<= 0.1.19 <= 2020

[1] In order to use Y2F 0.1.20 with FORCESPRO 6.2.0 or higher, you need to manually set codeoptions.legacy_interface = 1 when generating a FORCESPRO solver.

About

YALMIP to FORCESPRO interface

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages