Tsegazeab Shishaye
[ID:2012420012]
Northwestern Polytechnical University, Xian,China
Abstract
In this paper an inverted pendulum is presented using state space modeling method. And full state feedback controller is
developed using pole placement and LQR (Linear Quadratic Regulation) methods. After that, tracking problem is
addressed by designing a steady state error controller. Then, considering the reality conditions, first assuming by some of
the state variables are measurable, a reduced state observer is designed and then for a worst scenario a full order state
observer is designed. Finally, the state feedback controller and the state observer are summed up to give a precompensator and an overall steady state error controller is added to that new system. All mathematical modeling are
presented clearly and simulations together with their analysis were done using MATLAB software. For clear view on
what is going on with the control method and the system, an animation GUI is also presented.
Introduction
As a typical control system, the control of an inverted pendulum is excellent in testing and evaluating different control
methods. Its popularity derives in part from the fact that it is unstable without control, that is, the pendulum will simply
fall over if the cart isn't moved to balance it. Additionally, the dynamics of the system are nonlinear. The objective of the
control system is to balance the inverted pendulum by applying a force to the cart that the pendulum is attached to. A realworld example that relates directly to this inverted pendulum system is the attitude control of a booster rocket at takeoff
but The fundamental principles within this control system can be found in many industrial applications, such as stability
control of walking robots, vibration control of launching platform for shuttles etc
Problem formulation
The cart which a slim stick is fasted on can move along
a smooth track under the force, a controller needs to be
designed such that the one stage inverted pendulum
can be steadily balanced at its vertical position
after some disturbance.
Given parameters:
#Task1

System modeling
Since the analysis (state space model) and control design techniques that I will employ in this problem apply only to linear
systems, these equations need to be linearized. Specifically, I will linearize the equations about the vertically upward
equilibrium position, = 0, and will assume that the system stays within a small neighborhood of this equilibrium.
Linearization
Here, instead of using the linearization method (Taylor method for small perturbations), I will use simple approximation
around = 0. This assumption is reasonably valid since under control it is desired that the pendulum not deviate more
than 20 degrees (0.35 radians) from the vertically upward position.
So, for small ,
=
, And
will lie in the first quadrant. so, the Cosine function is positive)
Also dropping all the nonlinear components ( = 0) the above equations will become:
(
) +
)
( +
.. (3)
= m x
.. (4)
Solving for and independently from equation (3) and equation (4) respectively gives,
=
=
. (5)
. (6)
(
(
)
)
(
(
Statespace model
= ,
Now, let
= ,
= = ,
= ,
= = ,
= ,
=
=
+
)+
+ )+
( +
)
+ )+
)+
=
=
)+
So, substituting the above equations in to the matrices properly will give the following state space representation.
0
(
(
)
)
0
(
0 0
1 0
1 0
0 0
0
0
0
(
(
(
)
)
(
+
0
)
0
)
. (7)
. (8)
In MATLAB,
=
=
N.B.
Examining the results, especially the numerators, in the transfer functions of each output solved from the state space
model, there exists some terms with very small coefficients. These terms should actually be zero, they only show up due
to numerical roundoff errors that accumulate in the conversion algorithms that MATLAB employs. This can be checked
by solving the transfer functions of the cart and the pendulum independently from the motion equations using Laplace
transform by assuming zero initial conditions.
#Tsak2

Simulating the dynamic behavior of the system under impulse force and step force
Overshoot of
and
System analysis
1. Openloop impulse response of the system
Examining on how the system responds to a 1Nsec impulsive force applied to the cart, I found the following result.
OpenLoop Impulse Response
From: u
80
To: x
60
40
Amplitude
20
0
0
To: theta
100
200
300
400
500
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
Time (sec)
From the plot, the response is unsatisfactory. Both outputs never settle, the angle of the pendulum goes to several
hundred radians in a clockwise direction though it should be less than 0.35 rad. And the cart goes to the right infinitely.
So, this system is unstable in an open loop condition when there is a small impulsive force applied to the cart.
40
30
20
10
0
10
20
30
40
50
0.2
0.4
0.6
0.8
1.2
1.4
1.6
1.8
Or it can be shown by polezero mapping of the system as below using MATLAB command
Imaginary Axis
0.4
0.2
0
0.2
0.4
0.6
0.8
1
8
6
4
2
Real Axis
As can be seen from the output, there is one pole on the righthalf plane at 7.1430. This confirms the intuition that the
system is unstable in open loop.
) =
So, the necessary and sufficient condition for controllability of the system is:
(
)=
]=
Using the following MATLAB command, the controllability matrix of the system is:
RankCO = rank (
RankCO=
( , ))
So, since the controllability matrix has full rank, the system is controllable!
In cases where all the state variables of a system may not be directly measurable, it is necessary to estimate the values of
the unknown internal state variables using only the available system outputs.
Conceptually, a system is observable if the initial state, x(t_0), can be determined from the system output, y(t), over some
finite time t0 < t < tf.
Since this system is linearized to be LTI system, the system is observable if and only if the Observability matrix, OB, has
(
) =
)=
( , ))
RankOB=
4
So, since the observability matrix has full rank, the system is observable!
#Task3

Designing a state feedback controller to stabilize the system by improving performance of the system using pole
placement and linear quadratic regulator(LQR) methods
If all the states are not measurable, designing a faster stable fullorder state observer for state feedback controller.
If only
To make design more challenging, applying a step input to the cart and yet achieving the following design
are measurable, designing a reducedorder state observer for state feedback controller.
requirements,
o
Overshoot of
and
Here the main purpose is to design a controller so that when a step reference is given to the system, the pendulum should
be displaced, but eventually return to zero (i.e. vertical) and the cart should move to its new commanded position.
Design procedure:
Placing the eigenvalues of the controller matrix in a desired position by finding an arbitrary vector state feedback
control gain vector
assuming that all of the state variables are measurable. This can be accomplished using
either of the two methods pole placement method and LQR (Linear Quadratic Regulation) method.
So, it has been checked before that the system is controllable. i.e. the pair ( , ) is controllable.
Since, the state of the system is to be to be feedback as an input, the controller dynamics will be:
=
=
+ (
)=(
) +
Settling time,
%Overshoot, %OS, of the angle of the pendulum should be less than 20 (0.35 radians).
Design procedures for pole placement:
(%
(%
= . This is done by
)
/
2. Then placing rest of poles so they are much faster than the dominant second order behavior.
Typically, keeping the same damped frequency and then moving the real part to make them faster
than the real part of the dominant poles so that the transient response of the real poles of the system will
decay exponentially to insignificance at the settling time generated by the second order pair.
While taking care of moving the poles too far to the left because it takes a lot of control effect (needs
large actuating signal)
#procedure 1
Given %
=5
=0.456,
=1.78rad/sec,
= 62.870,
=
=
= 0.811,
= 1.584
#procedure 2
0.2
0.06
0.04
0.2
0.02
0.4
0.6
0.02
0.8
0.04
Test 1
K1 = [12.4835
1.2055
0.2423
0.4731]
1
0.06
10
Test 2
Step Response using pole placement2nd test
0.05
0.02
0.01
0.05
0.1
K3 = [40.2010
5.9361
6.7842
0.01
4.8694]
0.15
0.02
10
Note:
As can be seen from the respective plots of the system step
3
x 10
4
0.01
faster when the real poles go farther to the left from the real
part of the dominant poles. A more faster response can be
found by moving the real poles deeper in to the left half
0.01
0.02
2
0.03
4
0.04
6
10
[ ( )
( )+ ( )
( )]
Where:
 is the state cost with weight
 is the control cost with weight
Therefore, LQR selects closedloop poles that balance between state errors and control effort.
Design procedures for LQR:
is to be minimized. If so,
2. Solving the algebraic Riccati equation for P, (done using MATLAB software)
+
5. Verifying design, if it seen to be unsatisfactory, trying again with different weighting matrices Q and R
All the above procedures are completed easily in MATLB as follow:
Q =
80
0
0
0
0
0
0
0
0 400
0
0
K = [38.1423
0
0
0
0
, R = 1
6.2197 10.0000
3
x 10
5
0.02
7.7060]
0.02
5
10
Q = C'*C;
Q(1,1) = 10;
Q(3,3) = 100
R = 1
K = lqr(A,B,Q,R)
Ac = AB*K;
%control matrix
system_c = ss(Ac,B,C,D);
cart position (m)
>>
>>
>>
>>
>>
>>
>>
Note:

The reason this weighting was chosen is because it just satisfies the transient design requirements. Increasing the
magnitude of
more would make the tracking error smaller, but would require greater control force. More
The above LQR design method has brought a good stability to the system and fulfilled the design requirements in
a good manner. But, if the reference input is different from
fro zero,
( )=
degraded. So, for best quality of performance, an asymptotic tracking of a step reference input must be designed.
So far, both controller design methods, the pole placement and LQR design, helped to pick the gain vector K so
that the dynamics of the system to have nice properties more importantly to stabilize A.
The question remains as to how well the designed controller in both methods allows to track a reference
command?
This deals with performance issue of the system rather than just stability.
=
=
=
, where
) +
=
Then, the new transfer function will be
( )
= (
( )
))
( )
= ( (
( )
, the
= , which means the reference input is only applied to the position of the
cart.
Therefore, having K from the previous LQR design and scaling the reference input with following result, the system
responses are plotted below.
= (
In MATLAB,
>> Cn = [0 0 1 0]; %modification of C matrix
>> Nbar=inv(Cn*((AB*K)\B));
>> system_cl = ss(Ac,B*Nbar,C,D);
0.4
0.15
0.3
0.1
0.2
0.05
0.1
0.1
0.05
0.1
10
<0.5 sec. And also, it can be clearly seen that the system
limits, the settling time is also <5 sec and the rise time is
If
are measurable, then a reduced order state estimator can be designed to estimate and .
and
=
Generally if
=
of he
, where
+
+
=
For ( ) to be an estimate of
must be satisfied.

to be an estimate of
=
=
All eigenvalues of F have to have negative real parts and are different from the eigenvalues of A.
Design Procedures:
1. Choosing an arbitrary 2 2 matrix
.
so that all eigenvalues have negative real parts and are different from those of
F =
1.0e+003 *
0.0632
1.0497
0.0011
0.0016
And checking its eig(F)= 30.8206 +10.2537i and 30.8206 10.2537i, both eigenvalues of F have negative real
values and all are different from those of eig(A)= 0,7.1430, 7.2220, 0.1000.
2. Choosing a 2x2 vector
=
1.0 + 004
6.4715 0.0600
so that ( , ) is controllable,
0.2790 0.0034
( , ) = 2 so, it is satisfied.
And checking
in MATLAB software
( , , )
T =
1.0e+004 *
0.0035
0.1986
0.0002
0.0084
0.0094
6.4223
0.0068
0.3785
p=
1.0e+004 *
0
0.0001
0.0035
0.1986
0
0
0.0002
0.0084
0.0001
0
0.0094
6.4223
0
0
0.0068
0.3785
0
0.0019
0
0.0000
0
0.0000
0
0.0000
( )=
=
1.0e+003 *
0.0000
2.0405
0.0010
0.0624
0.0010
0.0009
0
0.0005
1.0e+003 *
0.1315
7.2163
=
And the error is
=
=
= 1.
+ (
0.0000 0.0010
0
0
2.0405 0.0009 0.0019 0.0000
+ 003
0.0010
0
0
0
0.0624 0.0005 0.0000 0.0000
= 1.0 + 003
0.0632 0.0011
1.0497 0.0016
4 Making sure that the estimator eigenvalues are faster than the desired eigenvalues of the state feedback,
because it will be used together to form a compensator.
So, it has been checked initially that this system is observable. i.e the pair ( , ) is observable.
=
+ ( )
=(
) +
=
( )=
][
=(
)( )
=(
=(
Where
+ ( )]
will approach to zero at faster rates. Thus, there is no need to compute the initial state of the
To select
a common guideline is to make the estimator poles 410 times faster than the slowest controller pole. Making
the estimator poles too fast can be problematic if the measurement is corrupted by noise or there are errors in the sensor
measurement in general.
Controller poles from the above system with error tracking controller are:
>>contr_poles=eig(Ac)
>>contr_poles =
7.6280 + 3.4727i
7.6280  3.4727i
3.1744 + 2.1467i
3.1744  2.1467i
The slowest poles have real parts at 3.1744, so the estimator poles can be placed at 30. Since the closedloop estimator
dynamics are determined by a matrix (
statefeedback system (
) that has a similar form to the matrix that determines the dynamics of the
).
Therefore, the same commands, that were used to find the state feedback gain , can be used to find the estimator gain .
Since
)=
) and
0.0632
1.0497
0.0008
0.0341
Final goal is to build the compensator (state feedback controller + full state observer).
Dynamic output feedback compensator is the combination of the regulator (state feedback controller developed using the
LQR method) and full state estimator using
=
=(
) +
=(
) +
=
Where
=
So, equations that can describe the overall closed loop dynamics will be
=
Having
=
and
while
+
( )=
In short, the overall closed loop final state space model is:
=[
Where
=
By making an equivalent transformation to the above state space model, it can be represented as the following equivalent
state equation. And this equivalent state equation governs the whole controllerestimator configuration.
=
=[
Where
0.02
x 10
5
0.02
5
10
Note:
The overall design requirements are satisfied and the system has a relatively good performance. But it can be seen that the
response graph for the inverted pendulum lucks a slight smoothness. That means there is something which creates that
vibration. i.e. there is a tracking problem of the output to the reference input. The next task will solve this problem.
#FinalTask
=
Redefining
Designing no steady state error tracking controller for the new SISO system to eliminate the steady state
error
Having the final controllerobserver state space model, if the reference input is a constant different from zero, ( ) =
=
This has the same approach as I used in the LQR controller, but slightly different in calculating the scaling factor
since
=[
Where
to
should be unity.
, where
(
=
))
=[
and
] in which
=[
] because the
=[
0.15
0.3
0.1
0.2
0.05
0.1
0.05
0.1
0.1
10
Explanation:

Weighting factor
x  This editable text field weights the cart's position in the LQR controller. Increasing the weighting
factor improves the cart's response, making it reach it's commanded position faster.
theta  This editable text field weights the pendulum's angle. Similar to the x weighting factor, making
this larger will quicken the pendulum's response. Feel free to change the weighting factors to see what
happens!
Step Slider  The slider allows you to change the magnitude of the step disturbance on the cart.
Manual Advance  If this control is checked, the user is able to advance the animation and plot one frame at a
time. The frames are advanced by pressing any key on the keyboard. This function is useful if the animation
moves too fast for the user and will allow the user to better visualize the entirety of the system's motion.
Reference Input  This box is automatically checked when the GUI is run. By unchecking it the user removes
the reference input term, Nbar, from the simulation. The reference input is used to correct steadystate errors
common to fullstate feedback systems.
Conclusion
Modeling of an inverted pendulum shows that the system is unstable without a controller. Results of applying state
feedback controllers show that the system can be stabilized. While both pole placement and LQR controller methods are
cumbersome because of selection of constants of controller though they can brought a good result if done systematically
with some guide lines.
When a DC reference input is applied to the cart, the system has failed slightly to track the input and has given a stable
output with some oscillations unsatisfactory steady state performances. To eliminate this, a no steady state error tracking
controller is designed and has brought good results as can be seen on the graphs in each steps.
And since in reality all the states cant be measured, a fullorder state estimator (observer) is designed. Finally, the state
feedback controller is summed with a fullorder state observer to give a precompensator and then a steady state error
tracking mechanism is also added to the whole new system. All those have brought a really nice controlled inverted
pendulum system with good performance.
References
[1] ChiTsong Chen, Linear system theory and design, 3rd edition , 1999 Oxford University press
[2] ChiTsong Chen, Analog and digital control system design transfer function, state space and algebraic methods
[3] B.Wayne Bequette, Process control Modeling, Design and simulation, Rensselaer Polytechnic Institute
[4] Friedland, Bernard, Control System Design, McGrawHill, Boston, 1986.
[5] P. Kumar, O.N. Mehrotra, J. Mahto, Controller design of inverted pendulum using pole placement and LQR, ISSN:
2319  1163
[6] A. Bazoune, Transient Response Specifications of a Second Order System
[7] Andrew K. Stimac, Standup and Stabilization of the Inverted Pendulum, MIT, June 1999
[8] Stormy Attaway, MATLAB, Practical Introduction to Programming and Problem Solving Second Edition,
department of Mechanical engineering Boston university, 2012
[9] http://ocw.mit.edu/courses/aeronauticsandastronautics/1630feedbackcontrolsystemsfall2010/lecturenotes/
[10] http://ctms.engin.umich.edu/CTMS/index.php?example=InvertedPendulum§ion=ControlStateSpace
This file has all the steps of developing the state feedback controller, full order state observer and the steady state
error controller. Its outputs are shown in graphs launched automatically when you run it.
%{
====================================================================
File:InvertedPendulum.m
Project: Controlling an inverted pendulum
Method: state space model and state feedback
By: TSEGAZEAB SHISHAYE (ID:2012420012), July2013,NWPU, Xi'anChina
===================================================================
%}
%System Modeling%
% Defining variables
clc;
clear;
M=0.5;
m=0.5;
b=0.1;
l=.3;
I=.006;
g=9.8;
d=I*(M+m)+M*m*l^2;
% Statespace model
disp('====================================')
disp('state space model of the system is:')
disp('====================================')
A=[0 1 0 0;m*g*l(M+m)/d 0 0 m*l*b/d;0 0 0 1;g*m^2*l^2/d 0 0 b*(I+m*l^2)/d];
B=[0;m*l/d;0;(I+m*l^2)/d];
C=[0 0 1 0;1 0 0 0];
D=[0;0];
system=ss(A,B,C,D)
%
disp('=======================================')
disp('The transfer function of the system is:')
disp('=======================================')
inputs = {'u'};
outputs = {'x'; 'tetha'};
G=tf(system)
set(G,'InputName',inputs)
set(G,'OutputName',outputs)
%System Analysis%
%Checking stability of the system%
%openLoop impulse response
inputs = {'u'};
outputs = {'x'; 'theta'};
set(G,'InputName',inputs)
set(G,'OutputName',outputs)
figure(1);clf;subplot(221)
t=0:0.01:1;
impulse(G,t);
grid;
title('OpenLoop Impulse Response of the system')
%OpenLoop step response
subplot(222)
t = 0:0.05:10;
u = ones(size(t));
[y,t] = lsim(G,u,t);
plot(t,y)
title('OpenLoop Step Response of the system')
axis([0 2 50 50])
legend('x','theta')
grid;
disp('================================================')
disp('desirable poles and the respective gain vectors:')
disp('================================================')
% First test....taking to 2 and 3 times of the real part of the dominant
% poles to the left
desirable_1=[2.433 1.622 0.811+1.584j 0.8111.584j]
K1=place(A,B,desirable_1)
Ac1 = AB*K1;
system_c1 = ss(Ac1,B,C,D);
t = 0:0.01:10;
r =0.2*ones(size(t));
figure(2);clf;subplot(311)
[y,t,x]=lsim(system_c1,r,t);
[AX,H1,H2] = plotyy(t,y(:,1),t,y(:,2),'plot');
set(get(AX(1),'Ylabel'),'String','cart position (m)')
set(get(AX(2),'Ylabel'),'String','pendangle(rad)')
title('Step Response using pole placement1st test')
grid
% Second test.....taking to 5 and 10 times of the real part of dominant
% poles to the left
desirable_2=[8.11 4.055 0.811+1.584j 0.8111.584j]
K2=place(A,B,desirable_2)
Ac2 = AB*K2;
system_c2 = ss(Ac2,B,C,D);
t = 0:0.01:10;
r =0.2*ones(size(t));
subplot(312)
[y,t,x]=lsim(system_c2,r,t);
[AX,H1,H2] = plotyy(t,y(:,1),t,y(:,2),'plot');
set(get(AX(1),'Ylabel'),'String','cart position (m)')
set(get(AX(2),'Ylabel'),'String','pendangle(rad)')
title('Step Response using pole placement2nd test')
grid
% Third test....taking to 12 and 14 times of the real part of the dominant
% poles to the left
desirable_3=[11.354 9.732 0.811+1.584j 0.8111.584j]
K3=place(A,B,desirable_3)
Ac3 = AB*K3;
system_c3 = ss(Ac3,B,C,D);
t = 0:0.01:10;
r =0.2*ones(size(t));
subplot(313)
[y,t,x]=lsim(system_c3,r,t);
[AX,H1,H2] = plotyy(t,y(:,1),t,y(:,2),'plot');
set(get(AX(1),'Ylabel'),'String','cart position (m)')
set(get(AX(2),'Ylabel'),'String','pendangle(rad)')
title('Step Response using pole placement3rd test')
grid
Cn = [0 0 1 0];
% Modifiying C matrix for y=x
Nbar=inv(Cn*((AB*K)\B)); %calculating gain scaling factor
sys_lqr_et = ss(Ac,B*Nbar,C,D);
t = 0:0.01:10;
r =0.2*ones(size(t));
figure(4);clf
[y,t,x]=lsim(sys_lqr_et,r,t);
[AX,H1,H2] = plotyy(t,y(:,1),t,y(:,2),'plot');
set(get(AX(1),'Ylabel'),'String','cart position (m)')
set(get(AX(2),'Ylabel'),'String','pendulum angle (radians)')
title('Step Response using LQR and steady state error controller')
grid
%Designing state observer (state estimator)
%ob = obsv(system_c);
observability = rank(ob)
contr_poles = eig(Ac)
obsr_poles = [30 31 32 33] % 10 times faster than the controller
L = place(A',C',obsr_poles)'
% placing observer poles
=
=
=
=
sys_co_ob = ss(Aco,Bco,Cco,Dco);
t = 0:0.01:10;
r = 0.2*ones(size(t));
figure(5);clf
[y,t,x]=lsim(sys_co_ob,r,t);
[AX,H1,H2] = plotyy(t,y(:,1),t,y(:,2),'plot');
set(get(AX(1),'Ylabel'),'String','cart position (m)')
set(get(AX(2),'Ylabel'),'String','pendulum angle (radians)')
title('Step Response using compensator (controller + observer)')
grid
% the new system with Compensator + no steady state error tracker
%Acl = [(AB*K) (B*K);zeros(size(A)) (AL*C)];
Bcl = [B;zeros(size(B))];
Ccl = [C zeros(size(C))];
Dcl = [0;0];
Ccln=[Cn zeros(size(Cn))];%reference step command applied to x only
Nbar=inv(Ccln*(Acl\Bcl))
Bclt = [B*Nbar;zeros(size(B))]; %modifing Bcl for the error traking purpose
sys_cm_et = ss(Acl,Bclt,Ccl,Dcl);
t = 0:0.01:10;
r = 0.2*ones(size(t));
figure(6);clf
[y,t,x]=lsim(sys_cm_et,r,t);
[AX,H1,H2] = plotyy(t,y(:,1),t,y(:,2),'plot');
set(get(AX(1),'Ylabel'),'String','cart position (m)')
set(get(AX(2),'Ylabel'),'String','pendulum angle (radians)')
title('Step Response using compensator with steady state error controller')
grid
File2: inv_pend_ani.m
 This file has all the necessary codes (functions) for the GUI animation of the Inverted Pendulum system control
using a compensator and a steady state error controller.
%  Outputs from this function are returned to the command line.
function varargout = inv_pend_ani_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject
handle to figure
% eventdata reserved  to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
global
global
global
global
pendangl
T
Nbar
stepval
0
0
0
0
1.789];
0];
0;
0.5263;
1;
0.1789];
% Get the weighing factors from the editable text fields of the GUI
% x=for pendulum angle, y=for cart position
x=str2num(get(handles.xtext,'string'));
y=str2num(get(handles.ytext,'String'));
Q=[x 0
0 0
0 0
0 0
R = 1;
0
0
y
0
0;
0;
0;
0];
%Finding the state feedback gain K matrix with the lqr command
disp('state feedback gain vector is:')
K = lqr(A,B,Q,R)
%The resulting LQR controller matrices
Ac = [(AB*K)];
Bc = [B];
Cc = [C];
Dc = [D];
%finding Controller poles
disp('controller poles are:')
cp= eig(Ac);
% making the observer poles 10 times faster than the...
%real part of the slowest pole of the controller
disp('observer poles are:')
obsr_poles = [real(min(cp))*10 real(min(cp))*101
real(min(cp))*102 real(min(cp))*103];
% placing observer poles
disp('gain vector for the output feedback to the observer is:')
L = place(A',C',obsr_poles)'
%Compensator(controller + observer) matrices
Acl
Bcl
Ccl
Dcl
=
=
=
=
%Modifing Ccl because reference step command applied to x only ==> y=x
Ccln=[Cn zeros(size(Cn))];
%there should be some modification in the input signal for good tracking performance. that means...
%there should be extra gain used to scale the closed loop transfer function to make the steady state step
error=0.
Nbarval = get(handles.reference,'Value');
if Nbarval == 0
Nbar = 1;
set(handles.Run,'UserData',Nbar);
stepaxis=stepval/1000;
elseif Nbarval == 1
pause
end
set(J,'XData', [cartl(i) cartr(i)]);
set(L,'XData', [cartpos(i) pendx(i)]);
set(L,'YData', [0.03 pendy(i)]);
drawnow;
axes(handles.axes1)
plot([T(i),T(i+1)],[cartpos(i),cartpos(i+1)], 'r', 'EraseMode', 'none')
plot([T(i),T(i+1)],[pendangl(i),pendangl(i+1)], 'b', 'EraseMode', 'none')
end
%Add legend to step plot
axes(handles.axes1)
hold on
legend('Pendulum Angle (rad.)','Cart Position (cm.)')
guidata(hObject, handles);
'xor','LineWidth',[20]);
guidata(hObject, handles);