-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.m
96 lines (72 loc) · 1.71 KB
/
init.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
87
88
89
90
91
92
93
94
95
96
addpath(genpath("utils"))
% gravity terms
g0 = 9.81;
g = g0*[0;-1;0];
% robot kinematic parameters
l1 = 1;
l2 = 1;
l3 = 1;
l = [l1;l2;l3];
% motor dynamic parameters
% include reduction ratios?
Im1 = 1;
Im2 = 1;
Im3 = 1;
% robot dynamic parameters
m1 = 10;
m2 = 7.5;
m3 = 5;
m = [m1;m2;m3];
d1 = -0.5;
d2 = -0.5;
d3 = -0.5;
I = zeros(3,3,3);
I(3,3,1) = (1/12)*m(1)*l1*l1;
I(3,3,2) = (1/12)*m(2)*l2*l2;
I(3,3,3) = (1/12)*m(3)*l3*l3;
% viscous friction coefficients
f1 = 0;
f2 = 0;
f3 = 0;
friction = [f1;f2;f3];
q = sym('q',[3,1]); assume(q,"real");
dq = sym('dq',[3,1]); assume(dq,"real");
ddq = sym('ddq',[3,1]); assume(ddq,"real");
u = sym('u',[3,1]); assume(u,"real");
table = [0 l1 0 q(1);
0 l2 0 q(2);
0 l3 0 q(3)];
[T,dkin] = DHplus(table);
r = [d1 d2 d3; 0 0 0; 0 0 0];
% set up simulation using euler lagrange ( do only once )
[vc,om] = moving_frames(table,[0,0,0], r,q,dq) ;
[~,M] = kinM(vc,om,[m1;m2;m3],I,dq);
invM = inv(M);
c = christoffel(M,q,dq)*dq;
gr = gravity_terms(m,g,r,T,q);
% ddq = (invM*(u-c-gr));
ddq = (M\(u-c-gr));
open("RRR_rigid_joints")
% https://it.mathworks.com/help/symbolic/generate-matlab-function-blocks.html
matlabFunctionBlock("RRR_rigid_joints/Direct Dynamics/euler_lagrange",ddq,"vars",[u q dq])
%% state and regulation parameters
% you can fine-tune launching only this part of the file ctrl+send
iteration_period = 5;
gamma = 3.01;
beta = 1/6;
% stiffness coefficients
k1 = 1500;
k2 = 1000;
k3 = 500;
k = [k1;k2;k3];
% initial state
q0 = [-pi/2;0;0];
% theta0 at steady state is related to q0 by:
theta0 = double(diag(k)^-1*subs(gr,q,q0)+q0);
dq0 = [0;0;0];
dtheta0 = [0;0;0];
% gain matrices
Kp = [400;400;400];
Kd = [400;400;350];
% desired set-point
qd = [pi/4;0;0];