-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfdyn_ne.m
80 lines (59 loc) · 1.31 KB
/
fdyn_ne.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
function [robota,q_out] = fdyn_ne(N)
%% params
if nargin < 1,
N = 3;
end
tau_act = zeros(N,1);
%all zeros
q0 = [pi/2; zeros(N-1,1)];
qd0 = zeros(N,1);
qdd0 = zeros(N,1);
fv = 0.9;
fc = 0.9;
I = 10;
L = 1;
m = 50;
g = [0 -9.81 0]';
%% DeltaTime for Euler integration
% 0.5
deltaTime = 0.25;
time = 0:deltaTime:100;
q = q0;
qd = qd0;
qdd = qdd0;
q_out = [];
for t=time,
%% Computing Inertia Matrix B (According to Siciliano's Book)
B = [];
Binv = [];
for i=(1:N),
q_tmp = zeros(N,1);
qd_tmp = zeros(N,1);
qdd_tmp = zeros(N,1);
qdd_tmp(i) = 1;
bi = NewtonEuler(N,L,m,I,fv,fc,g,q_tmp,qd_tmp,qdd_tmp);
B = [B bi];
end
Binv = inv(B);
tau = NewtonEuler(N,L,m,I,fv,fc,g,q,qd,qdd0);
qdd = Binv*(tau_act - tau);
qd = qd + qdd*deltaTime;
q = q + qd*deltaTime + qdd*(deltaTime^2)*0.5;
q_out = [q_out; q'];
end
figure(1);
clf;
DH = [];
for i=(1:N),
subplot(N,1,i);
plot(time,q_out(:,i))
xlabel('Time (s)');
ylabel(sprintf('Joint %d (rad)',i));
display('Press any key to continue');
% k = waitforbuttonpress;
DH = [DH;1 0 0 0 0];
end
robota = constructRobot(DH);
figure(2);
clf;
plot(robota,q_out);