-
Notifications
You must be signed in to change notification settings - Fork 7
/
pendulum.m
48 lines (39 loc) · 1.13 KB
/
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
function [ F, G, C, K, delta ] = pendulum( M, m, b, I, g, l )
%Creating a discrete state space model of inverse pendulum based on input
%arguments
%M Cart Mass
%m Pole Mass
%b Friction coefficient
%I Moment of Inertia
%g Gravity Acceleration
%l Pole Length
%output F- matrix of system dynamic
%output G- matrix of inputs
%output C- matrix of outputs
%output K- feedback gain
%output delata- periode
p = I*(M+m)+M*m*l^2; % Denominator in matrices A and B
% State Space Vector: [Cart Position, Cart Velocity, Pole Angle, Pole Angle Velocity]';
A = [0 1 0 0;
0 -(I+m*l^2)*b/p (m^2*g*l^2)/p 0;
0 0 0 1;
0 -(m*l*b)/p m*g*l*(M+m)/p 0];
B = [ 0;
(I+m*l^2)/p;
0;
m*l/p];
C = [1 0 0 0;
0 0 1 0];
D = [0;
0];
% Discrete Model:
delta = 0.1*(max(abs(real(eig(A)))))^(-1);
[F, G] = c2d(A, B, delta);
%feedback gain computation
p1 = 0.7;
p2 = 0.8;
p3 = 0.9;
p4 = 0.95;
desired_dynamics = [p1, p2, p3, p4];
K = place(F, G, desired_dynamics);
end