-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuser_ocp.m
More file actions
21 lines (21 loc) · 723 Bytes
/
user_ocp.m
File metadata and controls
21 lines (21 loc) · 723 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
%-------------------------------------------------------------------------------
% pdf_mpc package: Example 1 - Definition of the user_ocp map
%-------------------------------------------------------------------------------
function [J,g]=user_ocp(xx,uu,p_ode,p_uparam,p_ocp)
J=0;xd=[p_ocp.rd;0;0;0];
for i=1:p_uparam.Np
if i==1
du=uu(1)-p_ode.u0;
else
du=uu(i)-uu(i-1);
end
e=xx(i+1,:)'-xd;
J=J+(e'*p_ocp.Q*e+p_ocp.R*uu(i)^2+p_ocp.M*du^2);
end
h1=max(xx(:,3)-p_ocp.theta_max);
h2=max(-xx(:,3)-p_ocp.theta_max);
h3=max(xx(:,4)-p_ocp.thetap_max);
h4=max(-xx(:,4)-p_ocp.thetap_max);
g=max([h1;h2;h3;h4]);
end
%-------------------------------------------------------------------------------