All parameter arguments have to be simple variables (i.e., not expressions such a+b or 1+a)

50 views
Skip to first unread message

n33

unread,
Apr 7, 2019, 1:31:57 PM4/7/19
to YALMIP
Dear Johan,

I tried to run below MPC code in the implicit prediction form, but I got error (from the last line) saying: "All parameter arguments have to be simple variables (i.e., not expressions such a+b or 1+a)", could you tell me what went wrong?

Sorry I don't know why I cannot format what I typed to make it look nicer.

B = [1;2;3]; Const = [4;5;6];
N = 10; % prediction horizon
Q = eye(2); R = 0.5; P = 1;
options = sdpsettings('verbose', 2, 'debug', 1);

x_s = sdpvar(ones(1, N+1), ones(1, N+1)); y_s = x_s; phi_s = x_s;
u_s = sdpvar(ones(1, N), ones(1, N));

% Propagate Yalmip constraints and objectives
constraints = [];
objective = 0;
for j = 1 : N
    objective = objective ...
        + R * u_s{j}^2 ... % control effort
        + P * (phi_s{j} - phi_s{j+1})^2; % heading angle stability
    constraints = [constraints, ...
        x_s{j+1} == x_s{j} + B(1)*u_s{j} + Const(1), ...
        y_s{j+1} == y_s{j} + B(2)*u_s{j} + Const(2), ...
        phi_s{j+1} == phi_s{j} + B(3)*u_s{j} + Const(3)]; % equality constraints
    constraints = [constraints, -1 <= u_s{j} <= 1]; % inequality constraints
end

controller = optimizer(constraints, objective, options, {x_s{1}, y_s{1}, phi_s{1}}, [u_s{:}]);

Johan Löfberg

unread,
Apr 7, 2019, 3:05:50 PM4/7/19
to YALMIP
Since x_s and y_s (and phi_s) are the same variables, it makes no sense to list all three of them as parameters (the error message is not good here, but that is the cause)

your dynamical model makes no sense either, when you use the same variable to represent all three states

n33

unread,
Apr 7, 2019, 5:32:14 PM4/7/19
to YALMIP
Thanks and sorry for the mistake!
Reply all
Reply to author
Forward
0 new messages