Question about Adaptive MPC using Yalmip

190 views
Skip to first unread message

Mao

unread,
Apr 9, 2019, 2:19:01 AM4/9/19
to YALMIP
Hi Professor,

I am trying to do adaptive MPC using Yalmip, but I encountered some error that I do not know how to solve, please help!

% Pre
r
= 0 : 1 : 10; % reference to track
N
= 10; % prediction horizon
Nc = 4; % control horizon
Q
= 1;


% Yalmip Pre
x
= sdpvar(ones(1, N+1), ones(1, N+1));
angle
= sdpvar(ones(1, N+1), ones(1, N+1));
u
= sdpvar(ones(1, N), ones(1, N));
options
= sdpsettings('solver', 'gurobi', 'verbose', 1, 'debug', 0);


for k = 1 : length(r) - N
     
% Yalmip Arg
      constraints
= [];
      objective
= 0;
     
for j = 1 : N
            objective
= objective + Q*(r(k+j-1) - x{j})^2; % tracking
            constraints
= [constraints, -1 <= u{j} <= 1];
           
           
% Linearization and Update
           
if j ~= 1
                  A
= sin(value(angle{j-1}) + value(u{j-1}));
                 
x{j+1} = x{j} + A*(u{j} - u{j-1});
                  angle
{j+1} = angle{j} + (u{j} - u{j-1});
           
else
                  A
= sin(0.3);
                  x
{j+1} = x{j} + A*(u{j} - 0);
                  angle
{j+1} = angle{j} + (u{j} - 0);
           
end
     
end
      optimize
([constraints, x{1} == 11, angle{1} == 0.3], objective, options)
end

Originally, I used "optimizer" to solve which yielded no error, but the tracking is really poor so I figured I should use "optimize" to debug (see values of my parameters).
After switching to "optimize", I keep having Multiplying NaN with an SDPVAR makes no sense from the underscored line, which I think indicates that A cannot be obtained after j > 1. (I tried to get rid of value(), the model then became nonlinear and I want to use a linear solver)

My questions are:
1. Is there a way to check parameter values using "optimizer"? I think you said no in your tutorial.
2. How to fix the error I had? Should I put "optimize" inside the prediction horizon? 

Johan Löfberg

unread,
Apr 9, 2019, 2:38:41 AM4/9/19
to YALMIP
Since you haven't solved any problem when you run this line  A = sin(value(angle{j-1}) + value(u{j-1})), A will be Nan (as angle and u does not have any value yet)

You are simply setting up a nonlinear model, in a weird flawed way. It is not clear what you actually want to do. Do you want to use an A matrix which is based on the values computed in the last solve (previous k)? If you add assign([u{:}],.3) before the simulation loop, an initial value will be available., and when you solve the problem the second time, the new angle trajectory will be used. With that, you can remove your if-statement. Or perhaps you simply meant the if-switch to be based on k, not j.

Also, you want

constraint = [constraint,  x{j+1} == x{j} + A*(u{j} - u{j-1});
                     angle{j+1} == angle{j} + (u{j} - u{j-1})];


Mao

unread,
Apr 11, 2019, 7:21:00 PM4/11/19
to YALMIP
My mistake was weird because I thought Yalmip collects all constraints and objectives first, then "optimize" them in sequence in one time, but now my codes work fine. Thanks Professor!
Reply all
Reply to author
Forward
0 new messages