How to convert the code compiled by yalmip to c. #1270
Unanswered
liangjunfu
asked this question in
General discussion
Replies: 1 comment 2 replies
-
That sounds like an impossible to task (well, you could always try to run mcc or what ever the compiler is called these days but I don't think it will be able to compile it to c( Since you are computing a multiparametric solution, don't you want to convert the multiparametric solution with associated look-up to C? If so, you will have to study the MPT manuals, and then use the solution you have computed and get that to work with the stuff available in MPT to derive code. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Dear Johan, I meet a new problem.I would like to ask how to convert the following code (showing model predictive control) to c.
clear;
clc;
% Model data
A = [2 -1;1 0.2];
B = [1;0];
nx = 2; % Number of states
nu = 1; % Number of inputs
% MPC data
Q = eye(2);
R = 2;
N = 7;
u = sdpvar(repmat(nu,1,N),repmat(1,1,N));
x= sdpvar(repmat(nx,1,N+1),repmat(1,1,N+1));
raodong=sdpvar(2,1);
constraints = [];
objective = 0;
for k = 1:N
objective = objective + x{k}'Qx{k} + u{k}'Ru{k};
% constraints = [constraints, x{k+1} == Ax{k} + Bu{k1};
constraints = [constraints,x{k+1} == Ax{k} + B*u{k}+raodong];
constraints = [constraints, -1 <= u{k}<= 1, -5<=x{k+1}<=5];
end
constraints=[constraints ,0.01<=raodong<=1]
[sol,diagnostics,aux,Valuefunction,Optimalsolution]=solvemp(constraints,objective,[],raodong);
assign(x{1},[-1;1]);
value(Valuefunction)
value(Optimalsolution)
figure;plot(Valuefunction)
figure;plot(Optimalsolution)
Beta Was this translation helpful? Give feedback.
All reactions