Giter Site home page Giter Site logo

y2f's Introduction

Y2F - YALMIP to FORCES Pro Interface

This project provides a simple MATLAB interface that connects YALMIP with FORCES Pro. It combines YALMIP's intuitiveness with the high efficiency of FORCES Pro 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.

y2f's People

Contributors

adomahidi avatar gianulli avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.