forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunHinf.m
36 lines (28 loc) · 792 Bytes
/
runHinf.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function runHinf
d = CartPolePlant;
d = setInputLimits(d,-inf,inf);
v = CartPoleVisualizer(d);
[c,V] = balanceHinf(d);
sys = feedback(d,c);
x0 = [0;pi;0;0];
%for i=1:5
% xtraj=simulate(sys,[0 4],x0+.2*randn(4,1));
% v.playback(xtraj);
%end
V = V.inFrame(d.getStateFrame);
figure(1); plotFunnel(V,struct('inclusion','projection','plotdims',[2 4]));
xlabel('$\theta$','interpreter','latex');
ylabel('$\dot\theta$','interpreter','latex');
n=5;
y=getLevelSet(V,[],struct('num_samples',n));
for i=1:n
xtraj=simulate(sys,[0 4],.01*x0 + .99*y(:,i));
figure(1); fnplt(xtraj,[2 4]);
figure(25);
v.playback(xtraj);
if (V.eval(4,xtraj.eval(4))>V.eval(0,xtraj.eval(0)))
xtraj.eval(4)-x0
error('simulation appears to be going uphill on the Lyapunov function');
end
end
end