GithubHelp home page GithubHelp logo

chenyutao36 / matmpc Goto Github PK

View Code? Open in Web Editor NEW
61.0 61.0 34.0 3.58 MB

Home Page: https://matmpc-docs.readthedocs.io/en/latest/

License: GNU General Public License v3.0

MATLAB 44.39% C 55.61%

matmpc's People

Contributors

chenyutao36 avatar gsilano avatar marco-perin avatar ytunipd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

matmpc's Issues

Paths in compile_hpipm.m

Hi,

when following the installation instructions for Windows, the mex_core/compile_hpipm.m script does not run successfully. Turns out that the paths defined in that file do not point to the 'C:\msys64' folder anymore. This change has been introduced with the most recent commit (6291f59) and I assume that it was not intended this way.

Kind regards & thanks for this awesome tool!
Mario

Ununderstandable results when simulating a simple model

Hello,

Thank you for the very nice work. This is a great toolbox with a lot of potential.

I have been playing around with the toolbox and while your examples work and some of my models also worked well, I noticed some issues which I could not explain. Basically, in some scenarios, the system does not manage to achieve the target value of the DoF even if it could. It gets close but not quite there and the optimality criterion and the objective become near zero even though we did not quite reach the goal.

I boiled it down to this example. Create an ultra-simple:

  • 1 DoF
  • 1 control input
  • 1 Control bounds on the input
  • Only end-point objectives

You can find the model here:

%% Dimensions

nx=2;  % No. of differential states
nu=1;  % No. of controls
nz=0;  % No. of algebraic states
ny=0;  % No. of outputs

nyN=2; % No. of outputs at the terminal point
np=0; % No. of model parameters
nc=0; % No. of general inequality constraints
ncN=0; % No. of general inequality constraints
nbx = 0; % No. of bounds on states
nbu = 1; % No. of bounds on controls

% state and control bounds-+
nbx_idx = [];  % indexs of states which are bounded
nbu_idx = 1;  % indexs of controls which are bounded

%% create variables

import casadi.*

states   = SX.sym('states',nx,1);   % differential states
controls = SX.sym('controls',nu,1); % control input
alg      = SX.sym('alg',nz,1);      % algebraic states
params   = SX.sym('paras',np,1);    % parameters
refs     = SX.sym('refs',ny,1);     % references of the first N stages
refN     = SX.sym('refs',nyN,1);    % reference of the last stage
Q        = SX.sym('Q',ny,1);        % weighting matrix of the first N stages
QN       = SX.sym('QN',nyN,1);      % weighting matrix of the last stage
aux      = SX.sym('aux',ny,1);      % auxilary variable
auxN     = SX.sym('auxN',nyN,1);    % auxilary variable


%% Dynamics

%Constant
mVal = 2;

p=states(1); 
pdot = states(2); 

u1=controls(1);% f1

% explicit ODE RHS
x_dot= [pdot; 
 u1/mVal];

% algebraic function
z_fun = [];

% implicit ODE: impl_f = 0
xdot = SX.sym('xdot',nx,1);
impl_f = xdot - x_dot;

%% Objectives and constraints


% inner objectives
h=[];
hN=[p pdot]';


% outer objectives
obji =0;% 0.5*(h-refs)'*diag(Q)*(h-refs);
objN = 0.5*(hN-refN)'*diag(QN)*(hN-refN);

obji_GGN =0;% 0.5*(aux-refs)'*(aux-refs);
objN_GGN = 0.5*(auxN-refN)'*(auxN-refN);

% general inequality path constraints
general_con = [];
general_con_N = []; 

%% NMPC discretizing time length [s]

Ts_st = 0.01; % shooting interval time

In the file initData.m, I set my initial values as follows:

        x_ini = zeros(nx,1);
        input.x0=x_ini;
        input.u0=zeros(nu,1);
        input.z0 = zeros(nz,1);
        para0 = 0;
        q =0;
        qN = [1, 1];     % pz pzdot
        Q = 0;
        QN = qN';
        % upper and lower bounds for states (=nbx) 
        lb_x = [];
        ub_x = [];
        % upper and lower bounds for controls (=nbu)           
        lb_u = -1;
        ub_u = 1;
        % upper and lower bounds for general constraints (=nc)
        lb_g = [];
        ub_g = [];
        lb_gN = [];
        ub_gN = [];

And my reference trajectory as:

        refss=zeros(1,nx+nu);
        refss(1)=0.1;
        data.REF=refss;

This is the resulting behaviour (plotting the 1 DoF which should reach 0.1):

Screenshot from 2020-07-29 11-21-05

And this is the control output. Its is visibly within range:

Screenshot from 2020-07-29 11-21-22

I tried for several values and I get this behaviour. If I remove all bounds on the control or increase it a lot (ex., 100), I get the expected convergence. But I expect to get the desired convergence within feasible control bounds too. Any explanations or am I doing something wrong?

Thank you

The objective keeps increasing during the whole process.

Thank you for your kind sharing. I have tried this code for a fully-actuated multirotor system (modeled as an Euler Lagrange equation). The model and the target should be OK, since I have successfully controlled it using sliding mode control method. The constraints added are only normal boundary conditions. However it finally gets far away from the target. The objective keeps increasing during the whole process and finally goes to very large. I am confused. Do you have any idea about this issue?

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.