-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcp_display_exp.m
86 lines (73 loc) · 2.17 KB
/
cp_display_exp.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
%% Display an experiment with the Cart-Pole systems
%
% Based on a script by
% Marc Deisenroth, Andrew McHutchon, Joe Hall, and Carl Edward Rasmussen.
%
%% Overview
% This script displays an experiment with the cart-pole system with reward,
% applied force, and predictive uncertainty of the tip of the pendulum
% Note that this is only required for visualization
%
% function Sol_3_display_exp(x, theta, force, cost, text1, text2, M, S)
%
%
% *Input arguments:*
%
% x position of the cart
% theta angle of pendulum
% force force applied to cart
% cost cost structure
% .fcn function handle (it is assumed to use saturating cost)
% .<> other fields that are passed to cost
% M (optional) mean of state
% S (optional) covariance of state
% text1 (optional) text field 1
% text2 (optional) text field 2
%
function cp_display_exp(x, theta, force, cost, text1, text2, M, S)
%% Code
l = 0.6;
xmin = -3;
xmax = 3;
height = 0.1;
width = 0.3;
maxU = 10;
% Compute positions
cart = [ x + width, height
x + width, -height
x - width, -height
x - width, height
x + width, height ];
pendulum = [x, 0; x+2*l*sin(theta), -cos(theta)*2*l];
clf; hold on
plot(0,2*l,'k+','MarkerSize',20,'linewidth',2)
plot([xmin, xmax], [-height-0.03, -height-0.03],'k','linewidth',2)
% Plot force
plot([0 force/maxU*xmax],[-0.3, -0.3],'g','linewidth',10)
% Plot reward
reward = 1-cost.fcn(cost,[x, 0, 0, theta]', zeros(4));
plot([0 reward*xmax],[-0.5, -0.5],'y','linewidth',10)
% Plot the cart-pole
fill(cart(:,1), cart(:,2),'k','edgecolor','k');
plot(pendulum(:,1), pendulum(:,2),'r','linewidth',4)
% Plot the joint and the tip
plot(x,0,'y.','markersize',24)
plot(pendulum(2,1),pendulum(2,2),'y.','markersize',24)
% plot ellipse around tip of pendulum (if M, S exist)
try
[M1 S1] = cp_tip(M,S,2*l);
error_ellipse(S1,M1,'style','b');
catch
end
% Text
text(0,-0.3,'applied force')
text(0,-0.5,'immediate reward')
if exist('text1','var')
text(0,-0.9, text1)
end
if exist('text2','var')
text(0,-1.1, text2)
end
set(gca,'DataAspectRatio',[1 1 1],'XLim',[xmin xmax],'YLim',[-1.4 1.4]);
axis off;
drawnow;