Skip to content

Commit 0ad0910

Browse files
committed
Auto stash before merge of "test_ex_singletrack" and "origin/test_ex_singletrack"
1 parent bfaa1a3 commit 0ad0910

File tree

2 files changed

+7
-69
lines changed

2 files changed

+7
-69
lines changed

drawpendulum.m

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +0,0 @@
1-
2-
function drawpendulum(t,x, m1, m2,g,l)
3-
%% drawpendulum
4-
% adapted from Patrick Suhms code
5-
% (source: https://github.com/PatrickSuhm/LqrControlTutorial)
6-
% ------------------------------------------------------------------------
7-
% input:
8-
% t ... time (,1)
9-
% x ... state ([s, ds, phi, dphi])
10-
% m1 ... mass of the cart
11-
% m2 ... mass of pole
12-
% ------------------------------------------------------------------------
13-
14-
s = x(1,:); % position
15-
phi = x(3,:); % angle
16-
17-
18-
% dimensions of cart and mass
19-
W = 1*sqrt(m1/5); % cart width
20-
H = .5*sqrt(m1/5); % cart height
21-
mr = .3*sqrt(m2); % mass radius
22-
23-
% position mass
24-
px = s - l*sin(phi);
25-
py = H/2 + l*cos(phi);
26-
27-
% create new figure and
28-
figure
29-
plot([-25 10],[0 0],'w','LineWidth',2)
30-
hold on
31-
32-
% plot the cart
33-
h1=rectangle('Position',[s(1)-W/2,0,W,H],'Curvature',.1,'FaceColor',[1 0.1 0.1],'EdgeColor',[1 1 1]);
34-
35-
% plot the pole
36-
h2=plot([s(1) px(1)],[0 py(1)],'w','LineWidth',2);
37-
h3=rectangle('Position',[px(1)-mr/2,py(1)-mr/2,mr,mr],'Curvature',1,'FaceColor',[.3 0.3 1],'EdgeColor',[1 1 1]);
38-
h4=text(0.95, 1.5, ['phi: ', num2str(1)]);
39-
set(h4,'color','w', 'fontsize', 14);
40-
xlim([-12 2]);
41-
ylim([-1 5]);
42-
set(gca,'Color','k','XColor','w','YColor','w')
43-
set(gcf,'Color','k')
44-
45-
pause(0.1)
46-
tic
47-
48-
% animation in a for loop
49-
for k=1:length(t)
50-
51-
% update pole and cart position
52-
set(h1, 'position',[s(k)-W/2,0,W,H]);
53-
set(h2, 'XData',[s(k) px(k)], 'YData', [H/2 py(k)]);
54-
set(h3, 'position', [px(k)-mr/2,py(k)-mr/2,mr,mr]);
55-
set(h4, 'string',['time: ', num2str(t(k))]);
56-
57-
drawnow();
58-
pause(0.1)
59-
60-
61-
% meassure the time and create a fixed time loop
62-
% t2=toc;
63-
% while t2 < t(k)
64-
% t2 = toc;
65-
% end
66-
% t3(k) = t2;
67-
68-
end

main_invertedPendulum.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
%% True Dynamics Model
4040
%--------------------------------------------------------------------------
41-
% xk+1 = fd(xk,uk) + Bd * ( w ),
41+
% xk+1 = fd_true(xk,uk) + Bd * ( w ),
4242
%
4343
% where: w ~ N(0,var_w)
4444
%------------------------------------------------------------------
@@ -259,6 +259,12 @@
259259

260260
% plot prediction bias and variance
261261
d_GP.plot2d( gptrue )
262+
263+
264+
%% simulation of inverse pendulum
265+
266+
g = 9.81;
267+
drawpendulum(out.t,out.x,Mc,Mp,g,l)
262268

263269
% simulation of inverse pendulum
264270
g = 9.81;

0 commit comments

Comments
 (0)