analytical mechanics: matlabagenda problem we drive a 2-dof open loop menipulator based on joint pid...
TRANSCRIPT
![Page 1: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/1.jpg)
Analytical Mechanics: MATLAB
Shinichi Hirai
Dept. Robotics, Ritsumeikan Univ.
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 1 / 47
![Page 2: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/2.jpg)
Agenda
Agenda
1 Vector and Matrix
2 Graph
3 Ordinary Differential Equations
4 Optimization
5 Parameter Passing
6 Random Numbers
7 Summary
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 2 / 47
![Page 3: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/3.jpg)
Agenda
Problem
We drive a 2-DOF open loop menipulator based on joint PID control.Let us simulate the motion of the manipulator.
θ1
θ2l1
l2
link 1
link 2
joint 1
joint 2
lc2
lc1
x
y
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 3 / 47
![Page 4: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/4.jpg)
Agenda
Problem
Step 1. Derive equations of motion (kinematics / dynamics)
Step 2. Numerically solve the derived equations of motion
Step 3. Describe the derived numerical solution by graphs ormovies (visualization)
Step 4. Analyze the simulated motion
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 4 / 47
![Page 5: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/5.jpg)
Agenda
Problem
Soloving a set of simultaneous linear equations[H11 H12
H12 H22
] [ω1
ω2
]=
[f1f2
]⇓
Solving a set of ordinary differential equations[ω1
ω2
]=
[α1(θ1, θ2, ω1, ω2)α2(θ1, θ2, ω1, ω2)
]
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 5 / 47
![Page 6: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/6.jpg)
Agenda
What is MATLAB?
1 Software for numerical calculation
2 can handle vectors or matrices directly
3 Functions such as ODE solvers and optimization
4 Toolboxes for various applications
5 both programming and interactive calculation
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 6 / 47
![Page 7: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/7.jpg)
Agenda
What is MATLAB?
MATLAB environment
MATLAB Total Academic Headcount (TAH)MATLAB with all toolboxes is availableApril 2018 – 2021 March
Information
http://www.ritsumei.ac.jp/acd/mr/i-system/topics/2017/
matlab.html
http://www.ritsumei.ac.jp/acd/mr/i-system/staff/
rainbow/service/software_matlab_student.html
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 7 / 47
![Page 8: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/8.jpg)
Agenda
What is MATLAB?
Install MATLAB into your own PC or mobile
Sample programs are on the web of the class
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 8 / 47
![Page 9: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/9.jpg)
Vector and Matrix
Vector and Matrix
Column vector
x = [ 2; 3; -1 ];
Row vector
y = [ 2, 3, -1 ];
Matrix
A = [ 4, -2, 1; ...
-2, 5, 2; ...
-2, 3, 2 ];
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 9 / 47
![Page 10: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/10.jpg)
Vector and Matrix
Vector and Matrix
Symbol ... implies that the sentense continues.
Column vector
x = [ 2; ...
3; ...
-1 ];
Column vector
x = [ 2; 3; -1 ];
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 10 / 47
![Page 11: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/11.jpg)
Vector and Matrix
Vector and Matrix
Multiplication
p = A*x;
q = y*A;
>> p
p =
1
9
3
>>
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 11 / 47
![Page 12: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/12.jpg)
Vector and Matrix
Vector and Matrix
Multiplication
p = A*x;
q = y*A;
>> q
q =
4 8 6
>>
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 12 / 47
![Page 13: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/13.jpg)
Vector and Matrix
Matrix operations
>> A
A =
4 -2 1
-2 5 2
-2 3 2
>> A(3,2)
ans =
3
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 13 / 47
![Page 14: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/14.jpg)
Vector and Matrix
Matrix operations
>> A
A =
4 -2 1
-2 5 2
-2 3 2
>> A(3,2) = 6;
>> A
A =
4 -2 1
-2 5 2
-2 6 2
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 14 / 47
![Page 15: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/15.jpg)
Vector and Matrix
Matrix operations
>> A(3,:)
ans =
-2 3 2
>> A(:,2)
ans =
-2
5
3
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 15 / 47
![Page 16: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/16.jpg)
Vector and Matrix
Matrix operations
>> A
A =
4 -2 1
-2 5 2
-2 3 2
>> A(:,2) = [ 0; 2; 1 ];
>> A
A =
4 0 1
-2 2 2
-2 1 2
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 16 / 47
![Page 17: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/17.jpg)
Vector and Matrix
Matrix operations
>> A
A =
4 -2 1
-2 5 2
-2 3 2
>> A(3,:) = [ 3, -5, -1 ];
>> A
A =
4 -2 1
-2 5 2
3 -5 -1
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 17 / 47
![Page 18: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/18.jpg)
Vector and Matrix
Matrix operations
>> A
A =
4 -2 1
-2 5 2
-2 3 2
>> B = A([1,3],:);
>> B
B =
4 -2 1
-2 3 2
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 18 / 47
![Page 19: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/19.jpg)
Vector and Matrix
Matrix operations
>> A
A =
4 -2 1
-2 5 2
-2 3 2
>> C = A(:,[2,1]);
>> C
C =
-2 4
5 -2
3 -2
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 19 / 47
![Page 20: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/20.jpg)
Vector and Matrix
Basic row operations
A(3,:) = 5*A(3,:); multiply the 3rd row by 5A(1,:) = A(1,:) + 4*A(2,:); add 4-times of the 2nd row
to the 1st rowA([3,1],:) = A([1,3],:); exchange the 1st
and the 3rd rows
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 20 / 47
![Page 21: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/21.jpg)
Vector and Matrix
Solving simultaneous linear equation
A = [ 4, -2, 1; ...
-2, 5, 2; ...
-2, 3, 2 ];
p = [ 1; 9; 3 ];
Solve a simultaneous linear equation Ax = p>> x = A\p;
>> x
x =
2
3
-1
>> A*x
ans =
1
9
3
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 21 / 47
![Page 22: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/22.jpg)
Vector and Matrix
Solving simultaneous linear equation
operator \ is general but less effective
when coefficient matrix is positive-definite and symmetric, applyCholesky decomposition
inertia matrices are positive-definite and symmetric
Cholesky decomposition
positive-definite and symmetric matrix M can be decomposed as
M = UTU
where U is an upper trianglular matrix.
Mx = b =⇒ UTUx = b =⇒{
UTy = bUx = y
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 22 / 47
![Page 23: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/23.jpg)
Vector and Matrix
Cholesky decomposition
program Cholesky.m
fprintf(’Cholesky decomposition\n’);
M = [ 4, -2, -2; ...
-2, 2, 0; ...
-2, 0, 3 ];
U = chol(M);
U
U’*U
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 23 / 47
![Page 24: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/24.jpg)
Vector and Matrix
Cholesky decomposition
>> Cholesky
Cholesky decomposition
U =
2 -1 -1
0 1 -1
0 0 1
ans =
4 -2 -2
-2 2 0
-2 0 3
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 24 / 47
![Page 25: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/25.jpg)
Vector and Matrix
Cholesky decomposition
program
b = [ 4; 2; -7 ];
y = U’\b;
x = U\y;
x
result
x =
2
3
-1
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 25 / 47
![Page 26: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/26.jpg)
Graph
Graph
>> x = [0:10]’
x =
0
1
2
3
...
>> f = x.*x
f =
0
1
4
9
...
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 26 / 47
![Page 27: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/27.jpg)
Graph
Graph
>> plot(x,f)
0 1 2 3 4 5 6 7 8 9 100
10
20
30
40
50
60
70
80
90
100
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 27 / 47
![Page 28: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/28.jpg)
Graph
Graph
>> t = [0:0.1:10]’
t =
0
0.1000
0.2000
0.3000
...
>> x = sin(t)
x =
0
0.0998
0.1987
0.2955
...
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 28 / 47
![Page 29: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/29.jpg)
Graph
Graph
>> plot(t,x)
0 1 2 3 4 5 6 7 8 9 10-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 29 / 47
![Page 30: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/30.jpg)
Ordinary Differential Equations
Solving Ordinary Differential Equations
van der Pol equation
x − 2(1− x2)x + x = 0
⇓{x = vv = 2(1− x2)v − x
⇓
q =
[xv
], q = f (t,q) =
[v
2(1− x2)v − x
]
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 30 / 47
![Page 31: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/31.jpg)
Ordinary Differential Equations
Solving Ordinary Differential Equations
File van_der_Pol.m describes function f (t,q)
function dotq = van_der_Pol (t, q)
x = q(1);
v = q(2);
dotx = v;
dotv = 2*(1-x^2)*v - x;
dotq = [dotx; dotv];
end
File name ”van der Pol” should be consistent to function name”van der Pol”.
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 31 / 47
![Page 32: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/32.jpg)
Ordinary Differential Equations
Solving Ordinary Differential Equations
Program van_der_Pol_solve.m
interval = 0.00:0.10:10.00;
qinit = [ 2.00; 0.00 ];
[time, q] = ode45(@van_der_Pol, interval, qinit);
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 32 / 47
![Page 33: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/33.jpg)
Ordinary Differential Equations
Solving Ordinary Differential Equations
Draw a graph of time t and variable x
plot(time, q(:,1), ’-’);
Draw a graph of time t and variable v
plot(time, q(:,2), ’-’);
’-’ solid line’--’ broken line’-.’ dot-dash line’:’ dotted line
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 33 / 47
![Page 34: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/34.jpg)
Ordinary Differential Equations
Solving Ordinary Differential Equations
graph of time t and variable x
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 34 / 47
![Page 35: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/35.jpg)
Ordinary Differential Equations
Solving Ordinary Differential Equations
graph of time t and variable v
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 35 / 47
![Page 36: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/36.jpg)
Optimization
Optimization
Minimizing Rosenbrock function
minimize f (x1, x2) = 100(x2 − x21 )2 + (1− x1)
2
File Rosenbrock.m
function f = Rosenbrock( x )
x1 = x(1); x2 = x(2);
f = 100*(x2 - x1^2)^2 + (1 - x1)^2;
end
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 36 / 47
![Page 37: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/37.jpg)
Optimization
Optimization
File Rosenbrock_minimize.m
xinit = [ -1.2; 1.0 ];
[xmin, fmin] = fminsearch(@Rosenbrock, xinit);
xmin
fmin
Result
>> Rosenbrock_minimize
xmin =
1.0000
1.0000
fmin =
8.1777e-10
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 37 / 47
![Page 38: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/38.jpg)
Parameter Passing
ODE with Parameter
ordinary differential equation
x + bx + 9x = 0
where b is a parameter⇓
x = v
v = −bv − 9x
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 38 / 47
![Page 39: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/39.jpg)
Parameter Passing
Global Variable
Function
function dotq = damped_vibration (t, q)
global b;
x = q(1); v = q(2);
dotx = v; dotv = -b*v - 9*x;
dotq = [dotx; dotv];
end
Program
global b;
interval = [0,10];
qinit = [2.00;0.00];
b = 1.00;
[time,q] = ode45(@damped_vibration,interval,qinit);
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 39 / 47
![Page 40: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/40.jpg)
Parameter Passing
Nested Function
Function with arguments of time, state variable vector, and parameter
function dotq = damped_vibration_param (t, q, b)
x = q(1); v = q(2);
dotx = v; dotv = -b*v - 9*x;
dotq = [dotx; dotv];
end
Program
interval = [0,10];
qinit = [2.00;0.00];
b = 1.00;
damped_vibration = @(t,q) damped_vibration_param (t,q,b);
[time,q] = ode45(damped_vibration,interval,qinit);
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 40 / 47
![Page 41: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/41.jpg)
Parameter Passing
Global Variable vs Nested Function
Global Variable
Simple programGlobal variables may conflict against local variables
Nested Function
Somewhat complicatedMust perform function defininion whenever paramerer values changeNever conflict with other variables
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 41 / 47
![Page 42: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/42.jpg)
Random Numbers
Uniform Random Numbers
Uniform Random Numbers in interval ( 0, 1 )
rng(’shuffle’, ’twister’);
for k=1:10
x = rand;
s = num2str(x);
disp(s);
end
Symbol ’shuffle’ generates different random numbers wheneverthe program runs.
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 42 / 47
![Page 43: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/43.jpg)
Random Numbers
Uniform Random Numbers
Uniform Random Numbers in interval ( 0, 1 )
rng(0, ’twister’);
for k=1:10
x = rand;
s = num2str(x);
disp(s);
end
specifying seed 0 generates unique random numbers whenever theprogram runs.
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 43 / 47
![Page 44: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/44.jpg)
Random Numbers
dice.m
function k = dice()
% simulating a dice
x = rand;
if x < 1/6.00 k = 1;
elseif x < 2/6.00 k = 2;
elseif x < 3/6.00 k = 3;
elseif x < 4/6.00 k = 4;
elseif x < 5/6.00 k = 5;
else k = 6;
end
end
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 44 / 47
![Page 45: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/45.jpg)
Random Numbers
dice run.m
for i=1:10
s = [];
for j=1:10
k = dice();
s = [s, ’ ’, num2str(k)];
end
disp(s);
end
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 45 / 47
![Page 46: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/46.jpg)
Random Numbers
dice run.m
>> dice_run
2 4 6 5 6 3 3 4 2 5
4 4 2 1 3 3 5 5 5 1
1 4 2 6 6 2 5 6 4 6
6 4 5 4 1 3 4 4 3 6
5 6 3 4 6 6 5 2 4 1
3 5 6 5 3 5 3 6 6 6
3 3 2 5 6 6 4 4 1 6
3 2 6 5 6 2 5 4 1 3
2 5 2 6 5 3 3 5 6 4
4 2 3 5 6 5 1 5 3 3
>> dice_run
1 5 2 2 3 3 4 4 3 3
4 4 6 5 3 5 1 1 1 1
2 2 1 4 1 1 4 6 6 4
6 4 4 2 3 3 1 6 1 3
5 3 4 5 6 6 2 2 6 4
4 4 5 4 2 3 3 6 4 5
5 3 4 4 1 4 5 3 6 5
3 3 3 5 5 3 5 6 5 5
1 3 4 3 1 2 6 1 6 1
5 4 2 4 1 5 4 1 1 1
>>
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 46 / 47
![Page 47: Analytical Mechanics: MATLABAgenda Problem We drive a 2-DOF open loop menipulator based on joint PID control. Let us simulate the motion of the manipulator. q1 l1 q2 l2 link 1 link](https://reader030.vdocument.in/reader030/viewer/2022040817/5e623d7ff03f7c35dc78bbcf/html5/thumbnails/47.jpg)
Summary
Summary
Numerical calculation using MATLAB
linear calculation (vectors and matrices)
solving simultaneous linear equations
solving ordinary differential equations numerically
optimization
parameter passing
random numbers
Shinichi Hirai (Dept. Robotics, Ritsumeikan Univ.) Analytical Mechanics: MATLAB 47 / 47