[37] | 1 | function mpt_pwa_3 |
---|
| 2 | % Prediction horizon |
---|
| 3 | N = 4; |
---|
| 4 | |
---|
| 5 | opt_sincos |
---|
| 6 | |
---|
| 7 | probStruct.N=N-1; |
---|
| 8 | |
---|
| 9 | ctrl=mpt_control(sysStruct,probStruct) |
---|
| 10 | |
---|
| 11 | nx = 2; |
---|
| 12 | nu = 1; |
---|
| 13 | |
---|
| 14 | % States x(k), ..., x(k+N) |
---|
| 15 | x = sdpvar(repmat(nx,1,N),repmat(1,1,N)); |
---|
| 16 | |
---|
| 17 | % Inputs u(k), ..., u(k+N) (last one not used) |
---|
| 18 | u = sdpvar(repmat(nu,1,N),repmat(1,1,N)); |
---|
| 19 | |
---|
| 20 | % Binary for PWA selection |
---|
| 21 | d = binvar(2,1); |
---|
| 22 | |
---|
| 23 | % Value functions |
---|
| 24 | J = cell(1,N); |
---|
| 25 | |
---|
| 26 | % Initialize value function at stage N |
---|
| 27 | J{N} = 0; |
---|
| 28 | |
---|
| 29 | for k = N-1:-1:1 |
---|
| 30 | % Feasible region |
---|
| 31 | t = sdpvar(2,1); |
---|
| 32 | bounds(x{k},sysStruct.xmin,sysStruct.xmax); |
---|
| 33 | bounds(u{k},sysStruct.umin,sysStruct.umax); |
---|
| 34 | bounds(x{k+1},sysStruct.xmin,sysStruct.ymax); |
---|
| 35 | bounds(t,0,60); |
---|
| 36 | |
---|
| 37 | F = set(sysStruct.umin < u{k} < sysStruct.umax); |
---|
| 38 | F = F + set(sysStruct.xmin < x{k} < sysStruct.xmax); |
---|
| 39 | F = F + set(sysStruct.xmin < x{k+1} < sysStruct.xmax); |
---|
| 40 | F = F + set(sysStruct.ymin < sysStruct.C{1}*x{k} < sysStruct.ymax); |
---|
| 41 | F = F + set(sysStruct.ymin < sysStruct.C{1}*x{k+1} < sysStruct.ymax); |
---|
| 42 | |
---|
| 43 | F = F + set(-t(1) < x{k} < t(1)) ; |
---|
| 44 | F = F + set(-t(2) < u{k} < t(2)) ; |
---|
| 45 | |
---|
| 46 | % PWA Dynamics |
---|
| 47 | for i = 1:length(sysStruct.A) |
---|
| 48 | F = F + set(implies(d(i),x{k+1} == sysStruct.A{i}*x{k}+sysStruct.B{i}*u{k}+sysStruct.f{i})); |
---|
| 49 | F = F + set(implies(d(i),sysStruct.guardX{i}*x{k} < sysStruct.guardC{i})); |
---|
| 50 | end |
---|
| 51 | F = F + set(sum(d) == 1); |
---|
| 52 | |
---|
| 53 | % Compute value function for one step backwards |
---|
| 54 | [mpsol{k},sol{k},Uz{k},J{k},U{k}] = solvemp(F,sum(t) + J{k+1},[],x{k},u{k}); |
---|
| 55 | |
---|
| 56 | end |
---|
| 57 | |
---|
| 58 | mpsol{1} = mpt_removeOverlaps(mpsol{1}) |
---|
| 59 | |
---|
| 60 | mbg_asserttolequal(mpt_isPWAbigger(mpsol{1},ctrl),0); |
---|