% FILE: myPoles1_0.m
% DATE: 1.0 02/17/05
% AUTH: P.Oh
% DESC: Damped compound pendulum: pole calculations

% Pendulum properties
J   = 0.0090;           % Moment of Inertia [kg m^2]
c   = 0.00035;          % Viscous damping coefficient [Nms/rad]
d   = 0.023;            % Distance from pivot to center-of-mass [m]
L   = 0.495;            % Length of bar [m]
z   = 0.0059;           % Damping ratio
w   = 2.50;             % Natural frequency [rad/s]
mL  = 0.43;             % Mass of system [kg]
g   = 9.81;             % Gravitational constant [m/s^2]
PI  = 3.1416;           % Pi constant

r   = d + (L/2);    % Distance between motor-prop and pivot point [m]
Fl  = 0.123;        % Lift force when applying 2.0 Volts to motor-prop [N]
tor = Fl*r;         % Torque when applying 2.0 Volts to motor-prop [Nm]

vTest = 2.0;        % Test voltage [Volt]
Km = tor/vTest;     % Motor constant [Nm/Volt]

% Open Loop system: xDot = Fol*x + Gol*u  where u scalar
%                      y = Hol*x + Jol*u

Fol = [ 0  1; -(mL*g*d/J) -(c/J) ];
Gol = [ 0;  Km/J ];
Hol = [ 1 0];
Jol = 0;

% Create open-loop transfer function using ss2tf command
[oltfNum, oltfDen] = ss2tf(Fol, Gol, Hol, Jol);

% Suppose gains k1 and k2 are: 
gainK = [1  1];

Fcl = Fol - Gol*gainK;
Gcl = Gol;
Hcl = Hol;
Jcl = Jol;
[cltfNum, cltfDen] = ss2tf(Fcl, Gcl, Hcl, Jcl);

roots(cltfDen)

