-
Notifications
You must be signed in to change notification settings - Fork 0
/
inverted_pendulum.m
63 lines (42 loc) · 1.43 KB
/
inverted_pendulum.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
clear all;
nAct = 3;
nBaseDof = 6;
robotObj = struct();
robotObj.nAct = nAct;
robotObj.nBaseDof = nBaseDof;
robotObj.ndof = nAct+nBaseDof;
nDof = nAct + nBaseDof;
if nDof == 9
addpath("build");
% ic = [0;0;0;0;0;0;0.1;0.1;0;0;0;0;0;0;0;0;0;0];
ic = [0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0];
else
addpath("build_2dof");
ic = [0;0;0;0;0;0;0.3;-0.3;0;0;0;0;0;0;0;0];
endif
options = odeset("RelTol",1e-2, "AbsTol", 1e-2,"InitialStep",1e-2,"MaxStep",1e-1);
tEnd = 3;
[t,sol] = ode45(@dynamics,[0 tEnd], ic,options,[robotObj]);
figure(1);clf;
leg = plot3(NaN,NaN,NaN,"r","linewidth",2);
hold on
comBall = plot3(NaN,NaN,NaN,"o","markersize",20,"linewidth",20);
hold on
footRect = plot3(NaN,NaN,NaN,"linewidth",5);
axis([-1.1 1.1 -1.1 1.1 -1.1 3]);
pFoot = [0;0;0];
for i = 1:length(t)
legLine =jpos(sol(i,1:nDof));
foot = footpts(sol(i,1:nDof));
CoM = pCoM(sol(i,1:nDof));
set(comBall,'XData',CoM(1),'erasemode','normal');
set(comBall,'YData',CoM(2),'erasemode','normal');
set(comBall,'ZData',CoM(3),'erasemode','normal');
set(leg,'XData',legLine(1,:),'erasemode','normal');
set(leg,'YData',legLine(2,:),'erasemode','normal');
set(leg,'ZData',legLine(3,:),'erasemode','normal');
set(footRect,'XData',foot(1,:),'erasemode','normal');
set(footRect,'YData',foot(2,:),'erasemode','normal');
set(footRect,'ZData',foot(3,:),'erasemode','normal');
drawnow;
endfor