Pendulum Project: Difference between revisions

From Sccswiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 61: Line 61:
Completing the differentiation above gives
Completing the differentiation above gives


:<math>  mg-ml\ddot{\theta}\sin\theta-ml\dot{\theta}\cos\theta=V.  </math> &npbs; (1)
:<math>  mg-ml\ddot{\theta}\sin\theta-ml\dot{\theta}\cos\theta=V.  </math> (1)


The balance of forces of the rod in the horizontal direction with respect to its center of gravity is given by [4]
The balance of forces of the rod in the horizontal direction with respect to its center of gravity is given by [4]


:<math>  m\frac{d^2}{dt^2}(x+l\sin\theta)=H, \ m\ddot{x}+ml\ddot{\theta}\cos\theta-ml\dot{\theta}^2\sin\theta=H.  </math>
:<math>  m\frac{d^2}{dt^2}(x+l\sin\theta)=H, \ m\ddot{x}+ml\ddot{\theta}\cos\theta-ml\dot{\theta}^2\sin\theta=H.  </math> (2)


The balance of forces of the cart in the x direction is described by
The balance of forces of the cart in the x direction is described by


:<math>  M\frac{d^2}{dt^2}x=F-H \Rightarrow m\ddot{x}=F-H.  </math>
:<math>  M\frac{d^2}{dt^2}x=F-H \Rightarrow m\ddot{x}=F-H.  </math> (3)


The balance of rotational motion of the pendulum rod around its center of gravity is given by
The balance of rotational motion of the pendulum rod around its center of gravity is given by


:<math>  l\ddot{\theta}=Vl\sin\theta-Hl\cos\theta.  </math>
:<math>  l\ddot{\theta}=Vl\sin\theta-Hl\cos\theta.  </math> (4)


The nonlinear dynamical equations are found by substituting (2) into (3), and (1) into (4) as follows
The nonlinear dynamical equations are found by substituting (2) into (3), and (1) into (4) as follows


:<math>  (M+m)\ddot{x}+ml\ddot{\theta}\cos\theta-ml\dot{\theta}^2\sin\theta=F,  </math>
:<math>  (M+m)\ddot{x}+ml\ddot{\theta}\cos\theta-ml\dot{\theta}^2\sin\theta=F,  </math> (5)


:<math>  (l+ml^2)\ddot{\theta}+ml\ddot{x}\cos\theta-mgl\sin\theta=0.  </math>
:<math>  (l+ml^2)\ddot{\theta}+ml\ddot{x}\cos\theta-mgl\sin\theta=0.  </math> (6)


Therefore, the nonlinear equations (5) and (6) mathematically describe the inverted pendulum on a cart. [3]
Therefore, the nonlinear equations (5) and (6) mathematically describe the inverted pendulum on a cart. [3]
Line 93: Line 93:
By applying the above rules for small values of <math>\textstyle \theta</math>, equations (5) and (6) transform to
By applying the above rules for small values of <math>\textstyle \theta</math>, equations (5) and (6) transform to


:<math>  (M+m)\ddot{x}+ml\ddot{\theta}=F,  </math>
:<math>  (M+m)\ddot{x}+ml\ddot{\theta}=F,  </math> (7)


:<math>  (l+ml^2)\ddot{\theta}+ml\ddot{x}-mgl\theta=0.  </math>
:<math>  (l+ml^2)\ddot{\theta}+ml\ddot{x}-mgl\theta=0.  </math> (8)


Therefore, the linearized equations (7) and (8) mathematically describe the inverted pendulum on a cart for small values of <math>\textstyle \theta</math>.
Therefore, the linearized equations (7) and (8) mathematically describe the inverted pendulum on a cart for small values of <math>\textstyle \theta</math>.
Line 111: Line 111:
Assuming negligible armature inductance, the mathematical model of the motor is given by
Assuming negligible armature inductance, the mathematical model of the motor is given by


:<math>  V=R_AI_A+K_m\omega_m  </math>
:<math>  V=R_AI_A+K_m\omega_m  </math> (9)


where <math>\textstyle V</math> is the input voltage to the motor, <math>\textstyle R_A</math> is the armature resistance of the motor, <math>\textstyle I_A</math> is the armature current drawn by the motor, <math>\textstyle K_m</math> is the motor torque constant, and <math>\textstyle \omega_m</math> is the motor speed. The mechanical equation relating the motor torque to the input armature current is given by
where <math>\textstyle V</math> is the input voltage to the motor, <math>\textstyle R_A</math> is the armature resistance of the motor, <math>\textstyle I_A</math> is the armature current drawn by the motor, <math>\textstyle K_m</math> is the motor torque constant, and <math>\textstyle \omega_m</math> is the motor speed. The mechanical equation relating the motor torque to the input armature current is given by


:<math>  \tau_m=K_mK_gI_A.  </math>
:<math>  \tau_m=K_mK_gI_A.  </math> (10)


where <math>\textstyle \tau_m</math> is the torque produced at the output shaft of the motor, and <math>\textstyle K_g</math> is the gear ratio of the gear head on the motor if present.
where <math>\textstyle \tau_m</math> is the torque produced at the output shaft of the motor, and <math>\textstyle K_g</math> is the gear ratio of the gear head on the motor if present.
Line 121: Line 121:
The linear force applied to the cart by the motor can be described by
The linear force applied to the cart by the motor can be described by


:<math>  F=\frac{\tau_m}{r}  </math>
:<math>  F=\frac{\tau_m}{r}  </math> (11)


where <math>\textstyle r</math> is the radius of the output gear.
where <math>\textstyle r</math> is the radius of the output gear.
Line 127: Line 127:
The angular velocity of the output shaft relates to the linear velocity of the cart by
The angular velocity of the output shaft relates to the linear velocity of the cart by


:<math>  \omega_m=\frac{\dot{x}}{r}K_g  </math>
:<math>  \omega_m=\frac{\dot{x}}{r}K_g  </math> (12)


where <math>\textstyle x</math> is the linear velocity of the cart.
where <math>\textstyle x</math> is the linear velocity of the cart.
Line 133: Line 133:
We may now combine (11) into (10) and solve for <math>\textstyle I_A</math> obtaining the following
We may now combine (11) into (10) and solve for <math>\textstyle I_A</math> obtaining the following


:<math>  I_A=\frac{Fr}{K_mK_g}.  </math>
:<math>  I_A=\frac{Fr}{K_mK_g}.  </math> (13)


Finally, combining (12) and (13) into (9) we obtain an equation relating the input motor voltage V to the linear force F applied to the cart given by
Finally, combining (12) and (13) into (9) we obtain an equation relating the input motor voltage V to the linear force F applied to the cart given by


:<math>  F=\frac{K_mK_g}{rR_A}V-\frac{K^2_mk^2_g}{r^2R_A}\dot{x}.  </math>
:<math>  F=\frac{K_mK_g}{rR_A}V-\frac{K^2_mk^2_g}{r^2R_A}\dot{x}.  </math> (14)


====State Space Representation====
====State Space Representation====
Line 143: Line 143:
Now that we have the linearized dynamical equations and the control force equation relating the motor voltage to a linear force, we can substitute (14) into (7) and rearrange to solve for the linear acceleration <math>\textstyle \ddot{x}</math> as follows
Now that we have the linearized dynamical equations and the control force equation relating the motor voltage to a linear force, we can substitute (14) into (7) and rearrange to solve for the linear acceleration <math>\textstyle \ddot{x}</math> as follows


:<math>  \ddot{x} = \frac{K_m K_g}{(M+m)R_A r} V -\frac{K^2_m K^2_g}{(M+m)R_A r^2} \dot{x} - \frac{ml}{(M+m)}\ddot{\theta}.  </math>
:<math>  \ddot{x} = \frac{K_m K_g}{(M+m)R_A r} V -\frac{K^2_m K^2_g}{(M+m)R_A r^2} \dot{x} - \frac{ml}{(M+m)}\ddot{\theta}.  </math> (15)


Similarly, we may rearrange (8) to solve for the angular acceleration <math>\textstyle \theta</math> as follows
Similarly, we may rearrange (8) to solve for the angular acceleration <math>\textstyle \theta</math> as follows


:<math>  \ddot{\theta} = \frac{mgl}{(I+ml^2)}\theta - \frac{ml}{(I+ml^2)} \ddot{x}.  </math>
:<math>  \ddot{\theta} = \frac{mgl}{(I+ml^2)}\theta - \frac{ml}{(I+ml^2)} \ddot{x}.  </math> (16)


Now we will define the state variables as <math>\textstyle x_1 = \theta, x_2 = \dot \theta , x_3 = x, x_4 = \dot{x}</math>, where <math>\textstyle \theta</math> is the angular position of the rod, <math>\textstyle \dot\theta</math> is the angular acceleration of the rod, <math>\textstyle x</math> is the linear position of the cart, and <math>\textstyle \dot x</math> is the linear acceleration of the cart.
Now we will define the state variables as <math>\textstyle x_1 = \theta, x_2 = \dot \theta , x_3 = x, x_4 = \dot{x}</math>, where <math>\textstyle \theta</math> is the angular position of the rod, <math>\textstyle \dot\theta</math> is the angular acceleration of the rod, <math>\textstyle x</math> is the linear position of the cart, and <math>\textstyle \dot x</math> is the linear acceleration of the cart.
Line 176: Line 176:
Swinging the pendulum rod upright using minimal energy is achieved when the oscillating control input frequency is the natural frequency <math>\textstyle \omega_n</math> of the rod. To determine the natural frequency of the rod we must first obtain an equation of motion for the pendulum rod as follows
Swinging the pendulum rod upright using minimal energy is achieved when the oscillating control input frequency is the natural frequency <math>\textstyle \omega_n</math> of the rod. To determine the natural frequency of the rod we must first obtain an equation of motion for the pendulum rod as follows


:<math> I_0 \ddot \theta + \frac{1}{2} mgl \sin \theta =0,  I_0 = \frac{1}{3} ml^2 </math>
:<math> I_0 \ddot \theta + \frac{1}{2} mgl \sin \theta =0,  I_0 = \frac{1}{3} ml^2 </math>  


:<math>  \Rightarrow \ddot\theta + \frac{3g}{2l} \sin\theta =0  </math>
:<math>  \Rightarrow \ddot\theta + \frac{3g}{2l} \sin\theta =0  </math> (17)


Comparing (17) with the characteristic equation for a second order system, we obtain the natural frequency equation as
Comparing (17) with the characteristic equation for a second order system, we obtain the natural frequency equation as


:<math>  \omega_n = \sqrt{\frac{3g}{2l}}  (rad/s)  </math>
:<math>  \omega_n = \sqrt{\frac{3g}{2l}}  (rad/s)  </math> (18)


The open loop control function for the simulation is given by
The open loop control function for the simulation is given by


:<math>  V=A\sin(\omega_n t).  </math>
:<math>  V=A\sin(\omega_n t).  </math> (19)


The control function of (19) has two software adjustable values, the natural frequency <math>\textstyle \omega_n</math> and the gain <math>\textstyle A</math>. The gain <math>\textstyle A</math> of the control function adjusts the amplitude of the sine wave function. Since the motor voltage is software limited to \pm7.5 V during swing up, any value of <math>\textstyle A</math> above this value will be saturated.
The control function of (19) has two software adjustable values, the natural frequency <math>\textstyle \omega_n</math> and the gain <math>\textstyle A</math>. The gain <math>\textstyle A</math> of the control function adjusts the amplitude of the sine wave function. Since the motor voltage is software limited to \pm7.5 V during swing up, any value of <math>\textstyle A</math> above this value will be saturated.
Line 202: Line 202:
The control law to be implemented is given by
The control law to be implemented is given by


:<math>  V(t)= -KX(t)+K_i \int^{t}_{0} (x_d - x) dt.  </math>
:<math>  V(t)= -KX(t)+K_i \int^{t}_{0} (x_d - x) dt.  </math> (20)


To solve for <math>\textstyle K_i</math> we must define <math>\textstyle xi</math> as the integral of the linear position error as follows
To solve for <math>\textstyle K_i</math> we must define <math>\textstyle xi</math> as the integral of the linear position error as follows


:<math>  \xi = \int^{t}_{0} (x_d - x) dt  </math>
:<math>  \xi = \int^{t}_{0} (x_d - x) dt  </math> (21)


where <math>\textstyle x</math> is the linear position given by <math>\textstyle CX</math>. Differentiating (21) and subbing in <math>\textstyle CX</math> for <math>\textstyle x</math> yields the linear position error given by <math>\textstyle \dot \xi</math> as follows
where <math>\textstyle x</math> is the linear position given by <math>\textstyle CX</math>. Differentiating (21) and subbing in <math>\textstyle CX</math> for <math>\textstyle x</math> yields the linear position error given by <math>\textstyle \dot \xi</math> as follows


:<math>  \dot \xi = x_d -CX  </math>
:<math>  \dot \xi = x_d -CX  </math> (22)


The state space representation of the system is now given by
The state space representation of the system is now given by


:<math>  \dot X = AX +BV, \dot \xi = x_d - CX,  y=CX  </math>
:<math>  \dot X = AX +BV, \dot \xi = x_d - CX,  y=CX  </math> (23)


Now, we can rewrite (23) to include <math>\textstyle \dot\xi</math> as follows
Now, we can rewrite (23) to include <math>\textstyle \dot\xi</math> as follows


:<math>  \dot X = A^{'} X + B^{'} V , y=CX,  </math>
:<math>  \dot X = A^{'} X + B^{'} V , y=CX,  </math> (24)


where
where


:<math>A^{'} = \begin{bmatrix} A & 0 \ -C & 0 \end{bmatrix}, B^{'} = \begin{bmatrix} B \ 0 \end{bmatrix} </math>
:<math>A^{'} = \begin{bmatrix} A & 0 \ -C & 0 \end{bmatrix}, B^{'} = \begin{bmatrix} B \ 0 \end{bmatrix} </math>  


We may now rewrite the control law given in (20) as follows
We may now rewrite the control law given in (20) as follows


:<math>  V(t)= -KX(t)+K_i \xi.  </math>
:<math>  V(t)= -KX(t)+K_i \xi.  </math> (25)


(25) may be further reduced to achieve
(25) may be further reduced to achieve


:<math>  V(t)= - K^{'} X^{'}  </math>
:<math>  V(t)= - K^{'} X^{'}  </math> (26)


where
where


:<math> K^{'} = [K,-K_i],  X^{'} = \begin{bmatrix} X \ \xi \end{bmatrix}. </math>
:<math> K^{'} = [K,-K_i],  X^{'} = \begin{bmatrix} X \ \xi \end{bmatrix}. </math>  


Using the LQR method of design, the state feedback gain matrix <math>\textstyle K^{'}</math> must be determined so the system state variables converge to zero ensuring system stability, and to minimize the performance index <math>\textstyle J</math> given by
Using the LQR method of design, the state feedback gain matrix <math>\textstyle K^{'}</math> must be determined so the system state variables converge to zero ensuring system stability, and to minimize the performance index <math>\textstyle J</math> given by


:<math>  J= \int^{\infty}_0 (x^{'T} Q X^{'} + V(t)^T Ru)dt.  </math>
:<math>  J= \int^{\infty}_0 (x^{'T} Q X^{'} + V(t)^T Ru)dt.  </math> (27)


The matrix <math>\textstyle Q</math> represents the energy in the state variables. The vector <math>\textstyle R</math> represents the energy in the control. The two variables may be adjusted to obtain the desired performance of the system. Once appropriate values of <math>\textstyle Q</math>  and <math>\textstyle R</math> are chosen, matrix <math>\textstyle P</math> must be determined by solving the Ricatti equation given by
The matrix <math>\textstyle Q</math> represents the energy in the state variables. The vector <math>\textstyle R</math> represents the energy in the control. The two variables may be adjusted to obtain the desired performance of the system. Once appropriate values of <math>\textstyle Q</math>  and <math>\textstyle R</math> are chosen, matrix <math>\textstyle P</math> must be determined by solving the Ricatti equation given by


:<math>  PA^{'} + A^{'T}P-PB^{'}R^-1 B^{'T}P+Q=0.  </math>
:<math>  PA^{'} + A^{'T}P-PB^{'}R^-1 B^{'T}P+Q=0.  </math> (28)


Now, the state feedback gain matrix <math>\textstyle K^{'}</math> may be determined by
Now, the state feedback gain matrix <math>\textstyle K^{'}</math> may be determined by


:<math>  K^{'} = R^{-1} B^{'T} P.  </math>
:<math>  K^{'} = R^{-1} B^{'T} P.  </math> (29)


==Fuzzy Controller==
==Fuzzy Controller==
Line 280: Line 280:
At each time step those four state variables are computed and a fuzzy rule corresponding to that specific state of the system will become active. Thus, it makes the cart move in one direction as it is specified in that fuzzy rule.
At each time step those four state variables are computed and a fuzzy rule corresponding to that specific state of the system will become active. Thus, it makes the cart move in one direction as it is specified in that fuzzy rule.


\includegraphics[width=0.6\columnwidth]{membership_functions.PNG}  \textbf{Fig. 4.4.1} Membership Function Example
<center>
[[Image:Membership_functions.PNG]]
<br>
'''Fig. 4.4.1''' Membership Function Example
</center>


In Fig. 4.4.1 above, we can see five membership functions made up by triangles (except the left-and rightmost areas).
In Fig. 4.4.1 above, we can see five membership functions made up by triangles (except the left-and rightmost areas).


\includegraphics[width=0.9\columnwidth]{stabilizer.PNG}  \textbf{Fig. 4.4.2} Simulink Model Diagram of the Stabilizer
<center>
[[Image:stabilizer.PNG]]
<br>
'''Fig. 4.4.2''' Simulink Model Diagram of the Stabilizer
</center>


The erector swings the rod like a sine-wave and aims to bring the rod close to the region (<math>\textstyle +/- 0.3^\circ</math>) so that the stabilizer can kick in. Fig. 4.5.4 above depicts the inside of the stabilizer. The membership functions are defined in "zugehörigkeiten" block whereas the fuzzy rules are defined inside the S-Function builder called "fuzzy_stabilisator".
The erector swings the rod like a sine-wave and aims to bring the rod close to the region (<math>\textstyle +/- 0.3^\circ</math>) so that the stabilizer can kick in. Fig. 4.5.4 above depicts the inside of the stabilizer. The membership functions are defined in "zugehörigkeiten" block whereas the fuzzy rules are defined inside the S-Function builder called "fuzzy_stabilisator".
Line 304: Line 312:
The science of artificial neural networks is based on the neuron. In order to understand the structure of artificial networks, the basic elements of the neuron should be understood. Neurons are the fundamental elements in the central nervous system. Fig. 5.1 below depicts the components of a neuron [7].
The science of artificial neural networks is based on the neuron. In order to understand the structure of artificial networks, the basic elements of the neuron should be understood. Neurons are the fundamental elements in the central nervous system. Fig. 5.1 below depicts the components of a neuron [7].


\includegraphics[width=0.5\columnwidth]{neuron_components.PNG}  \textbf{Fig. 5.1} Components of a Neuron
<center>
[[Image:neuron_components.PNG]]
<br>
'''Fig. 5.1''' Components of a Neuron
</center>


A neuron is made up of 3 main parts -dendrites, cell body and axon. The dendrites receive signals coming from the neighbouring neurons. The dendrites send their signals to the body of the cell. The cell body contains the nucleus of the neuron. If the sum of the received signals is greater than a threshold value, the neuron fires by sending an electrical pulse along the axon to the next neuron.
A neuron is made up of 3 main parts -dendrites, cell body and axon. The dendrites receive signals coming from the neighbouring neurons. The dendrites send their signals to the body of the cell. The cell body contains the nucleus of the neuron. If the sum of the received signals is greater than a threshold value, the neuron fires by sending an electrical pulse along the axon to the next neuron.
Line 310: Line 322:
The following model is based on the components of the biological neuron. The inputs X0-X3 represent the dendrites. Each input is multiplied by weights W0, W3. The output of the neuron model, Y is a function, F of the summation of the input signals. (Fig. 5.2)
The following model is based on the components of the biological neuron. The inputs X0-X3 represent the dendrites. Each input is multiplied by weights W0, W3. The output of the neuron model, Y is a function, F of the summation of the input signals. (Fig. 5.2)


\includegraphics[width=0.5\columnwidth]{dentrides.PNG}  \textbf{Fig. 5.2} Dentrides
<center>
[[Image:Dentrides.PNG]]
<br>
'''Fig. 5.2''' Dentrides
</center>


The main advantage of ANN is they operate as black boxes. This avoids most of the complex modeling activities, and reduces the model to just a set of weights. But, this also would be a disadvantage since the rules of operation in neural networks are completely unknown. But the disadvantage is the amount of time taken to train networks. It can take considerable time to train an ANN for certain functions.
The main advantage of ANN is they operate as black boxes. This avoids most of the complex modeling activities, and reduces the model to just a set of weights. But, this also would be a disadvantage since the rules of operation in neural networks are completely unknown. But the disadvantage is the amount of time taken to train networks. It can take considerable time to train an ANN for certain functions.
Line 318: Line 334:
There are 3 main types of ANN structures -single layer feed-forward network, multi-layer feed-forward network and recurrent networks [8]. In feed-forward networks the direction of signals is from input to output, there is no feedback in the layers. Other types of single layer networks are based on the perceptron model. The details of the perceptron are shown in Fig. 5.2.1.
There are 3 main types of ANN structures -single layer feed-forward network, multi-layer feed-forward network and recurrent networks [8]. In feed-forward networks the direction of signals is from input to output, there is no feedback in the layers. Other types of single layer networks are based on the perceptron model. The details of the perceptron are shown in Fig. 5.2.1.


\includegraphics[width=0.4\textwidth]{perceptron.PNG}  \textbf{Fig. 5.2.1} Perceptron
<center>
[[Image:Perceptron.PNG]]
<br>
'''Fig. 5.2.1''' Perceptron
</center>


In the current work, we employ a multi-layer perceptron model with a single hidden layer.
In the current work, we employ a multi-layer perceptron model with a single hidden layer.


\includegraphics[width=0.5\textwidth]{neuralnetwork_structure.PNG}  \textbf{Fig. 5.2.2} Three Layer Neural Network Structure
<center>
[[Image:neuralnetwork_structure.PNG]]
<br>
'''Fig. 5.2.2''' Three Layer Neural Network Structure
</center>


Increasing the number of neurons in the hidden layer or adding more hidden layers to the network allows the network to deal with more complex functions. Cybenko's theorem states that, "A feed-forward neural network with a sufficiently large number of hidden neurons with continuous and differentiable transfer functions can approximate any continuous function over a closed interval.". [9] The weights in MLP's are updated using the back-propagation learning algorithm [6], which is discussed in detail in the coming sections.
Increasing the number of neurons in the hidden layer or adding more hidden layers to the network allows the network to deal with more complex functions. Cybenko's theorem states that, "A feed-forward neural network with a sufficiently large number of hidden neurons with continuous and differentiable transfer functions can approximate any continuous function over a closed interval.". [9] The weights in MLP's are updated using the back-propagation learning algorithm [6], which is discussed in detail in the coming sections.
Line 328: Line 352:
Inputs to the perceptron are individually weighted and then summed. The perceptron computes the output as a function <math>\textstyle F</math> of the sum. The activation function, <math>\textstyle F</math> is needed to introduce nonlinearities into the network. This makes multi-layer networks powerful in representing nonlinear functions. There are 3 main types of activation function -tan-sigmoid, log-sigmoid and linear [10]. Different activation functions affect the performance of an ANN.
Inputs to the perceptron are individually weighted and then summed. The perceptron computes the output as a function <math>\textstyle F</math> of the sum. The activation function, <math>\textstyle F</math> is needed to introduce nonlinearities into the network. This makes multi-layer networks powerful in representing nonlinear functions. There are 3 main types of activation function -tan-sigmoid, log-sigmoid and linear [10]. Different activation functions affect the performance of an ANN.


\includegraphics[width=0.7\textwidth]{activation_functions.PNG}  \textbf{Fig. 5.2.3} Activation Functions
<center>
[[Image:activation_functions.PNG]]
<br>
'''Fig. 5.2.3''' Activation Functions
</center>
 


The output from the perceptron is
The output from the perceptron is
Line 385: Line 414:
This Pendulum GUI is a friendly graphical user interface for the BGCE Inverted Pendulum Project. You can easily switch into Classical controller, Fuzzy controller or Neural network by choosing the different Tab of this GUI, also can change between Simulation or Real-time. By default, the Classical controller mode. (Fig. 6.1)
This Pendulum GUI is a friendly graphical user interface for the BGCE Inverted Pendulum Project. You can easily switch into Classical controller, Fuzzy controller or Neural network by choosing the different Tab of this GUI, also can change between Simulation or Real-time. By default, the Classical controller mode. (Fig. 6.1)


\includegraphics[width=0.9\textwidth]{GUI_Classical.PNG}  \textbf{Fig. 6.1} Default Pendulum GUI (Classical controller mode)
<center>
[[Image:GUI_Classical.PNG]]
<br>
'''Fig. 6.1''' Default Pendulum GUI (Classical controller mode)
</center>
 


===Classical Controller Tab===
===Classical Controller Tab===
Line 403: Line 437:
-'''Real-time System'''  <br />Same as Classical Tab.
-'''Real-time System'''  <br />Same as Classical Tab.


\includegraphics[width=0.9\textwidth]{GUI_Fuzzy.PNG}  \textbf{Fig. 6.2.1} Fuzzy controller simulation
<center>
[[Image:GUI_Fuzzy.PNG]]
<br>
'''Fig. 6.2.1''' Fuzzy controller simulation
</center>
 
<center>
[[Image:GUI_State_Variables.PNG]]
<br>
'''Fig. 6.2.2''' State Variables
</center>


\includegraphics[width=0.9\textwidth]{GUI_State_Variables.PNG}  \textbf{Fig. 6.2.2} State Variables
<center>
[[Image:GUI_Membership_functions.PNG]]
<br>
'''Fig. 6.2.3''' Membership Function of Fuzzy Rules
</center>


\includegraphics[width=0.9\textwidth]{GUI_Membership_functions.PNG}  \textbf{Fig. 6.2.3} Membership Function of Fuzzy Rules


===Neural Networks Controller Tab===
===Neural Networks Controller Tab===

Revision as of 14:50, 18 January 2009

Introduction

An inverted pendulum is a pendulum which is attached to a cart. (Fig. 1.1)


Error creating thumbnail: Unable to save thumbnail to destination
Fig. 1.1 Inverted Pendulum

Even though a regular inverted pendulum has a point mass attached to its rod, our hardware consists of a cart which is free to move horizontally and a rod attached to it. An inverted pendulum is inherently unstable, and must be actively balanced in order to remain upright, either by applying a torque at the pivot point or by moving the pivot point horizontally as part of a feedback system. [1]


In control theory and classical dynamics the inverted pendulum is considered to be a classic problem which is used as benchmark for testing of the control algorithms. As some examples of the control algorithms we used the inverted pendulum system to experiment with PID controller, fuzzy controller and lastly neural networks.

Besides its theoretical importance the inverted pendulum system has also seen action in real life. An inverted pendulum-like system is used during the take-offs of the rocket to keep the rocket in balance. Moreover, the shipping cranes in the seaports use a similar idea. Last but not the least, a self-balancing transportation device called Segway[2] uses same working principle as it is in an inverted pendulum.

BGCE Project Scope

The classical approach of control theory is to develop a mathematical model for the system and then to develop a corresponding controller so that the closed loop is stable (PID- controller). A second approach is the use of a so-called fuzzy-controller, which doesn’t need an explicit model of the system. Another interesting possibility is to use self-learning controllers that learn automatically how to control the system. Techniques such as neural networks can be used for this task. In the scope of this project, these different approaches will be studied. The focus is not only on the controllers themselves, but also on their visualization and demonstration via an interactive graphical user interface.

Classical Controller

Classical Controller tries to solve the physical equations governing the system in order to find the trajectory of the rod from the stable equilibrium position at rest to the unstable equilibrium position.

To achieve this goal we first have to find the mathematical representation of the system, meaning , we will model the system at first and then we try to find the relation between the output of the system which is the current state as feed back and the next input which hopefully helps us get closer to the unstable equilibrium position.[3]

Classical Model

The purpose of system modeling is to provide an accurate mathematical description of the system. Once this description is obtained, the numerical constants of the system will be substituted into the equations to provide a working representation of the system. From there this model can be simulated and manipulated to obtain gain values on which the state feedback control is based.

This section will derive two sets of mathematical models of the system. The first model is a set of nonlinear differential equations. The second model is a set of linearized differential state equations.

Due to the difficulty level of nonlinear control and the scope of this project, the nonlinear equations will not be used for control calculations. However, the linearized equations provide a good estimate of the system under conditions mentioned in this chapter, and will be used for all control calculations.

Since the inverted pendulum is a complex system, the more accurate one wants to be the more complex the model gets and the slower the controller.

So having this fact on mind , we tried to use the most important terms and leave away the parts where we thought wouldn't be much of importance but of course doing this we moved away from a complex model to an easier to solve one in cost of accuracy.

The physical model of the inverted pendulum on a moving cart is seen in figure 1. The inverted pendulum system is free to move only in the X-Y plane. The symbolic descriptions are shown in table 3.1.

Using the physical model of the inverted pendulum from Fig. 1, we can now derive the differential equations that describe the system as seen in the following section. [3]

Error creating thumbnail: Unable to save thumbnail to destination
Table 3.1.1 Parameters of the Model


Error creating thumbnail: Unable to save thumbnail to destination
Fig. 3.1.1 Inverted Pendulum Model

Nonlinear Dynamical Model

The equations describing the center of gravity of the pendulum rod with respect to the origin on the Cartesian axis of reference can be written as [4]

<math>\textstyle x_g = x+l\sin\theta</math>,

<math>\textstyle y_g = l\cos\theta</math>.

The balance of forces of the rod in the vertical direction with respect to its center of gravity is given by

<math>m\frac{d^2}{dt^2}(l\cos\theta)=V-mg. </math>

Completing the differentiation above gives

<math> mg-ml\ddot{\theta}\sin\theta-ml\dot{\theta}\cos\theta=V. </math> (1)

The balance of forces of the rod in the horizontal direction with respect to its center of gravity is given by [4]

<math> m\frac{d^2}{dt^2}(x+l\sin\theta)=H, \ m\ddot{x}+ml\ddot{\theta}\cos\theta-ml\dot{\theta}^2\sin\theta=H. </math> (2)

The balance of forces of the cart in the x direction is described by

<math> M\frac{d^2}{dt^2}x=F-H \Rightarrow m\ddot{x}=F-H. </math> (3)

The balance of rotational motion of the pendulum rod around its center of gravity is given by

<math> l\ddot{\theta}=Vl\sin\theta-Hl\cos\theta. </math> (4)

The nonlinear dynamical equations are found by substituting (2) into (3), and (1) into (4) as follows

<math> (M+m)\ddot{x}+ml\ddot{\theta}\cos\theta-ml\dot{\theta}^2\sin\theta=F, </math> (5)
<math> (l+ml^2)\ddot{\theta}+ml\ddot{x}\cos\theta-mgl\sin\theta=0. </math> (6)

Therefore, the nonlinear equations (5) and (6) mathematically describe the inverted pendulum on a cart. [3]

Linearization of the Dynamical Equations

To be able to apply a linear controller to the inverted pendulum system for stabilization, we need to linearize the dynamical equations (5) and (6).

Under stabilization conditions of the pendulum we assume the angle of the rod, <math>\textstyle \theta</math>, is small. By assuming the angle of the rod is always small, the dynamical equations may be linearized by applying the following mathematical rules. For small values of <math>\textstyle \theta</math>:

<math>\dot{\theta}\approx 0, \sin\theta = \theta, \cos\theta=1. </math>

By applying the above rules for small values of <math>\textstyle \theta</math>, equations (5) and (6) transform to

<math> (M+m)\ddot{x}+ml\ddot{\theta}=F, </math> (7)
<math> (l+ml^2)\ddot{\theta}+ml\ddot{x}-mgl\theta=0. </math> (8)

Therefore, the linearized equations (7) and (8) mathematically describe the inverted pendulum on a cart for small values of <math>\textstyle \theta</math>.

Real System Controller

in progress...

Simulation Controller

Control Force / Electro-Mechanical System Equations

The control force, <math>\textstyle F</math> , of the system is delivered by a DC-motor mounted on the cart. The control input to the motor is measured in voltage, <math>\textstyle V</math>, while the control force delivered is in Newtons. The control force, <math>\textstyle F</math>, must be related to the input voltage, <math>\textstyle V</math>, of the motor attached to the cart. This involves deriving the electro-mechanical equations of the motor and solving these with respect to the control force and the motor voltage.

Assuming negligible armature inductance, the mathematical model of the motor is given by

<math> V=R_AI_A+K_m\omega_m </math> (9)

where <math>\textstyle V</math> is the input voltage to the motor, <math>\textstyle R_A</math> is the armature resistance of the motor, <math>\textstyle I_A</math> is the armature current drawn by the motor, <math>\textstyle K_m</math> is the motor torque constant, and <math>\textstyle \omega_m</math> is the motor speed. The mechanical equation relating the motor torque to the input armature current is given by

<math> \tau_m=K_mK_gI_A. </math> (10)

where <math>\textstyle \tau_m</math> is the torque produced at the output shaft of the motor, and <math>\textstyle K_g</math> is the gear ratio of the gear head on the motor if present.

The linear force applied to the cart by the motor can be described by

<math> F=\frac{\tau_m}{r} </math> (11)

where <math>\textstyle r</math> is the radius of the output gear.

The angular velocity of the output shaft relates to the linear velocity of the cart by

<math> \omega_m=\frac{\dot{x}}{r}K_g </math> (12)

where <math>\textstyle x</math> is the linear velocity of the cart.

We may now combine (11) into (10) and solve for <math>\textstyle I_A</math> obtaining the following

<math> I_A=\frac{Fr}{K_mK_g}. </math> (13)

Finally, combining (12) and (13) into (9) we obtain an equation relating the input motor voltage V to the linear force F applied to the cart given by

<math> F=\frac{K_mK_g}{rR_A}V-\frac{K^2_mk^2_g}{r^2R_A}\dot{x}. </math> (14)

State Space Representation

Now that we have the linearized dynamical equations and the control force equation relating the motor voltage to a linear force, we can substitute (14) into (7) and rearrange to solve for the linear acceleration <math>\textstyle \ddot{x}</math> as follows

<math> \ddot{x} = \frac{K_m K_g}{(M+m)R_A r} V -\frac{K^2_m K^2_g}{(M+m)R_A r^2} \dot{x} - \frac{ml}{(M+m)}\ddot{\theta}. </math> (15)

Similarly, we may rearrange (8) to solve for the angular acceleration <math>\textstyle \theta</math> as follows

<math> \ddot{\theta} = \frac{mgl}{(I+ml^2)}\theta - \frac{ml}{(I+ml^2)} \ddot{x}. </math> (16)

Now we will define the state variables as <math>\textstyle x_1 = \theta, x_2 = \dot \theta , x_3 = x, x_4 = \dot{x}</math>, where <math>\textstyle \theta</math> is the angular position of the rod, <math>\textstyle \dot\theta</math> is the angular acceleration of the rod, <math>\textstyle x</math> is the linear position of the cart, and <math>\textstyle \dot x</math> is the linear acceleration of the cart.

We may now define our state vector as <math>\textstyle X=(\theta , \dot \theta , x , \dot x )^T</math> . The state space representation is obtained using state equations (15) and (16) as follows

<math> \dot X = AX+BV </math>
<math> y=CX </math>

where

<math>

A = \begin{bmatrix} 0 & 1 & 0 & 0 \\ \frac{(M+m)gml}{(M+m)I+mMl^2} & 0 & 0 & \frac {K_{g}^2 K_{m}^2 ml }{r^2 R_a (MI+mI+mMl^2)} \\ 0 & 0 & 0 & 1 \\ \frac{-gm^2 l^2}{(M+m)I+mMl^2} & 0 & 0 & \frac{-l^2mK_{g}^2 K_{m}^2 - IK_{m}^2 K_{g}^2}{r^2 R_a (MI+mI+mMl^2)}

\end{bmatrix},</math>

<math>

B= \begin{bmatrix} 0 \\ \frac{-K_g K_m ml} {rRa (MI+mI+mMl^2)} \\ 0 \\ \frac {ml^2 K_g K_m r +K_g K_m Ir}{r^2 Ra (MI+mI+mMl^2)} \end{bmatrix}, </math>

<math> C= \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \end{bmatrix}.
</math>

Controller Design

The self-erecting inverted pendulum has a control design for the swing up, and a separate control design for the stabilization. The open loop swing up controller brings the pendulum upright close to the unstable point of equilibrium. Once the angular position has reached a software adjustable capture range, the closed loop stabilization controller takes over.

Open Loop Swing up Control Design

Swinging the pendulum rod upright using minimal energy is achieved when the oscillating control input frequency is the natural frequency <math>\textstyle \omega_n</math> of the rod. To determine the natural frequency of the rod we must first obtain an equation of motion for the pendulum rod as follows

<math> I_0 \ddot \theta + \frac{1}{2} mgl \sin \theta =0, I_0 = \frac{1}{3} ml^2 </math>
<math> \Rightarrow \ddot\theta + \frac{3g}{2l} \sin\theta =0 </math> (17)

Comparing (17) with the characteristic equation for a second order system, we obtain the natural frequency equation as

<math> \omega_n = \sqrt{\frac{3g}{2l}} (rad/s) </math> (18)

The open loop control function for the simulation is given by

<math> V=A\sin(\omega_n t). </math> (19)

The control function of (19) has two software adjustable values, the natural frequency <math>\textstyle \omega_n</math> and the gain <math>\textstyle A</math>. The gain <math>\textstyle A</math> of the control function adjusts the amplitude of the sine wave function. Since the motor voltage is software limited to \pm7.5 V during swing up, any value of <math>\textstyle A</math> above this value will be saturated.

Closed Loop Stabilization Control Design

The stabilization control design is based on linear quadratic regulator (LQR) design with a tracking controller. The objective of this controller is to stabilize the pendulum rod in the upright unstable point of equilibrium while maintaining a software adjustable linear set point position. The LQR design will effectively return the state feedback gains needed to ensure stability of the system. However, to bring the steady state error of the linear position to zero, a tracking controller is added by integrating the error of the cart position, relative to the linear set point, over time. The gain adjustment of the integration result allows control over the zero steady state error convergence time.

\includegraphics[width=0.7\textwidth]{control_design.PNG} \textbf{Fig. 3.5.2.1} Simulink Control Design Block Diagram

From the block diagram it can be seen that the control design uses state feedback. The gain values for the state variables are denoted by <math>\textstyle K_i</math> , a 1x4 matrix, and are the desired values to achieve stabilization. The gain block for the integration of the linear position error is denoted by <math>\textstyle K_i</math> and is also the desired value to achieve zero steady state linear position error.

The saturation block is necessary to represent the experimental system as accurately as possible. Since <math>\textstyle V(t)</math> , the calculated motor voltage into the system, may reach voltages higher than acceptable values for the motor, a saturation function is embedded in the software clipping the motor voltage signal to \pm6 Volts.

The control law to be implemented is given by

<math> V(t)= -KX(t)+K_i \int^{t}_{0} (x_d - x) dt. </math> (20)

To solve for <math>\textstyle K_i</math> we must define <math>\textstyle xi</math> as the integral of the linear position error as follows

<math> \xi = \int^{t}_{0} (x_d - x) dt </math> (21)

where <math>\textstyle x</math> is the linear position given by <math>\textstyle CX</math>. Differentiating (21) and subbing in <math>\textstyle CX</math> for <math>\textstyle x</math> yields the linear position error given by <math>\textstyle \dot \xi</math> as follows

<math> \dot \xi = x_d -CX </math> (22)

The state space representation of the system is now given by

<math> \dot X = AX +BV, \dot \xi = x_d - CX, y=CX </math> (23)

Now, we can rewrite (23) to include <math>\textstyle \dot\xi</math> as follows

<math> \dot X = A^{'} X + B^{'} V , y=CX, </math> (24)

where

<math>A^{'} = \begin{bmatrix} A & 0 \ -C & 0 \end{bmatrix}, B^{'} = \begin{bmatrix} B \ 0 \end{bmatrix} </math>

We may now rewrite the control law given in (20) as follows

<math> V(t)= -KX(t)+K_i \xi. </math> (25)

(25) may be further reduced to achieve

<math> V(t)= - K^{'} X^{'} </math> (26)

where

<math> K^{'} = [K,-K_i], X^{'} = \begin{bmatrix} X \ \xi \end{bmatrix}. </math>

Using the LQR method of design, the state feedback gain matrix <math>\textstyle K^{'}</math> must be determined so the system state variables converge to zero ensuring system stability, and to minimize the performance index <math>\textstyle J</math> given by

<math> J= \int^{\infty}_0 (x^{'T} Q X^{'} + V(t)^T Ru)dt. </math> (27)

The matrix <math>\textstyle Q</math> represents the energy in the state variables. The vector <math>\textstyle R</math> represents the energy in the control. The two variables may be adjusted to obtain the desired performance of the system. Once appropriate values of <math>\textstyle Q</math> and <math>\textstyle R</math> are chosen, matrix <math>\textstyle P</math> must be determined by solving the Ricatti equation given by

<math> PA^{'} + A^{'T}P-PB^{'}R^-1 B^{'T}P+Q=0. </math> (28)

Now, the state feedback gain matrix <math>\textstyle K^{'}</math> may be determined by

<math> K^{'} = R^{-1} B^{'T} P. </math> (29)

Fuzzy Controller

Introduction

Instead of the mathematical modeling and writing differential equations describing the characteristics of the inverted pendulum system another controller technique named "Fuzzy Controller" is introduced initially to mimic human behavior in robotics. Since the human body is perfect in keeping its balance, the scientists came up with the inverted pendulum system to represent the human-like balancing as closest as it could be. To actualize this idea the fuzzy logic and fuzzy controllers are used to stabilize the inverted pendulum with its rod kept upright.

Fuzzy Logic

Fuzzy logic (FL) is a form of multi-valued logic derived from fuzzy set theory to deal with reasoning that is approximate rather than precise. Just as in fuzzy set theory the set membership values can range (inclusively) between 0 and 1, in fuzzy logic the degree of truth of a statement can range between 0 and 1 and is not constrained to the two truth values {true (1), false (0)} as in classic predicate logic.[3]

FL provides a simple way to arrive at a definite conclusion based upon vague, ambiguous, imprecise, noisy, or missing input information. FL's approach to control problems mimics how a person would make decisions, only much faster.

Distinctive Properties of Fuzzy Logic

FL incorporates a simple, rule-based IF X AND Y THEN Z approach in order to a solve control problem rather than attempting to model a system mathematically. The FL model is empirically-based, relying on an operator's experience rather than their technical understanding of the system. For example, rather than dealing with terms such as exact values (x=100 or 50<x<100), terms like "IF (x is too big) AND (x is getting smaller) THEN (push the cart)" etc. These terms are imprecise and yet very descriptive of what must actually happen. Similar style is used while describing the inverted pendulum system.

Fuzzy Logic in Inverted Pendulum

In the inverted pendulum system we defined four state variables: position of the cart (s), velocity of the cart (sp), angular velocity of the rod(phip) and angle of the rod(phi_oben). Those state variables play a big role when the subcontroller "stabilizer" kicks in to keep the pendulum stable in the neighborhood of the 0 degree. Each state variable is divided into several membership functions shown as in the Fig. 4.4.1.

<math>\textstyle phip</math> and <math>\textstyle phi\_oben</math> are divided into 7 states categorized as: <math>\textstyle negative\_big</math>, <math>\textstyle negative</math>, <math>\textstyle negative\_small</math>,<math>\textstyle zero</math>, <math>\textstyle positive_small</math>, <math>\textstyle positive</math>, <math>\textstyle positive\_big</math>. Each category is associated with a range of values. The ranges were:

Angle: [-0.3, 0.3]

Angular Velocity: [-4, 4]

Position: [-0.4,0.4]

Velocity: [-0.5, 0.5]

At each time step those four state variables are computed and a fuzzy rule corresponding to that specific state of the system will become active. Thus, it makes the cart move in one direction as it is specified in that fuzzy rule.

Error creating thumbnail: Unable to save thumbnail to destination
Fig. 4.4.1 Membership Function Example

In Fig. 4.4.1 above, we can see five membership functions made up by triangles (except the left-and rightmost areas).

Error creating thumbnail: Unable to save thumbnail to destination
Fig. 4.4.2 Simulink Model Diagram of the Stabilizer

The erector swings the rod like a sine-wave and aims to bring the rod close to the region (<math>\textstyle +/- 0.3^\circ</math>) so that the stabilizer can kick in. Fig. 4.5.4 above depicts the inside of the stabilizer. The membership functions are defined in "zugehörigkeiten" block whereas the fuzzy rules are defined inside the S-Function builder called "fuzzy_stabilisator".

Results

The fuzzy controller (FC) has produced during our implementation better results than the initial implementation. When the project started, we had a version of a fuzzy controller. The main problem with that FC was that the swinger part was slow and it took too much time for till the stabilizer kicked in. Our main focus was to implement a better swing-up controller and to improve the current set of fuzzy rules. However, our experiments even with new fuzzy rules did not improve the stabilizer. Hence, we kept the old fuzzy rules defined in the beginning of the project.


In our trials, we implemented Gaussian membership functions to get a smoother fuzzy controller acting on the inverted pendulum. Yet, we did not see any significant gain in terms of speedup and robustness of the pendulum system. That is why we decide rolled back those membership functions to their initial states where they are represented as triangles.

Neural Networks

The characteristics of the inverted pendulum make identification and control more challenging, as we have seen from the above sections. This can be circumvented by using a neural network based identification-control approach [4],[5],[6]. This would involve first, developing an accurate model of the inverted pendulum system using neural networks – System Identification. Then, develop a neural network controller which determines the correct control action to stabilize the system.

Artificial Neural Networks

The science of artificial neural networks is based on the neuron. In order to understand the structure of artificial networks, the basic elements of the neuron should be understood. Neurons are the fundamental elements in the central nervous system. Fig. 5.1 below depicts the components of a neuron [7].

Error creating thumbnail: Unable to save thumbnail to destination
Fig. 5.1 Components of a Neuron

A neuron is made up of 3 main parts -dendrites, cell body and axon. The dendrites receive signals coming from the neighbouring neurons. The dendrites send their signals to the body of the cell. The cell body contains the nucleus of the neuron. If the sum of the received signals is greater than a threshold value, the neuron fires by sending an electrical pulse along the axon to the next neuron.

The following model is based on the components of the biological neuron. The inputs X0-X3 represent the dendrites. Each input is multiplied by weights W0, W3. The output of the neuron model, Y is a function, F of the summation of the input signals. (Fig. 5.2)

Error creating thumbnail: Unable to save thumbnail to destination
Fig. 5.2 Dentrides

The main advantage of ANN is they operate as black boxes. This avoids most of the complex modeling activities, and reduces the model to just a set of weights. But, this also would be a disadvantage since the rules of operation in neural networks are completely unknown. But the disadvantage is the amount of time taken to train networks. It can take considerable time to train an ANN for certain functions.

Neural Network Structures

There are 3 main types of ANN structures -single layer feed-forward network, multi-layer feed-forward network and recurrent networks [8]. In feed-forward networks the direction of signals is from input to output, there is no feedback in the layers. Other types of single layer networks are based on the perceptron model. The details of the perceptron are shown in Fig. 5.2.1.

Error creating thumbnail: Unable to save thumbnail to destination
Fig. 5.2.1 Perceptron

In the current work, we employ a multi-layer perceptron model with a single hidden layer.

Error creating thumbnail: Unable to save thumbnail to destination
Fig. 5.2.2 Three Layer Neural Network Structure

Increasing the number of neurons in the hidden layer or adding more hidden layers to the network allows the network to deal with more complex functions. Cybenko's theorem states that, "A feed-forward neural network with a sufficiently large number of hidden neurons with continuous and differentiable transfer functions can approximate any continuous function over a closed interval.". [9] The weights in MLP's are updated using the back-propagation learning algorithm [6], which is discussed in detail in the coming sections.

Inputs to the perceptron are individually weighted and then summed. The perceptron computes the output as a function <math>\textstyle F</math> of the sum. The activation function, <math>\textstyle F</math> is needed to introduce nonlinearities into the network. This makes multi-layer networks powerful in representing nonlinear functions. There are 3 main types of activation function -tan-sigmoid, log-sigmoid and linear [10]. Different activation functions affect the performance of an ANN.

Error creating thumbnail: Unable to save thumbnail to destination
Fig. 5.2.3 Activation Functions


The output from the perceptron is

<math>\textstyle y[k] = f (w [k].x[k])</math>.

ANN Learning

Neural networks have 3 main modes of operation – supervised, reinforced and unsupervised learning [10]. In supervised learning the output from the neural network is compared with a set of targets, the error signal is used to update the weights in the neural network. Reinforced learning is similar to supervised learning however there are no targets given, the algorithm is given a grade of the ANN performance. Unsupervised learning updates the weights based on the input data only. The ANN learns to cluster different input patterns into different classes.

5.4 Back-propagation Learning Algorithm

Back-propagation Learning Algorithm is a supervised learning method, and is an implementation of the Delta rule [6]. As the name itself suggests, the errors are propagate backwards from the output nodes to the inner nodes and therefore the learning. So back-propagation is used to calculate the gradient of the error of the network with respect to the network's modifiable weights. This gradient is almost always then used in a simple stochastic gradient descent algorithm to find weights that minimize the error. But, the term "back-propagation" is used in a more general sense, and refers to the entire procedure encompassing both the calculation of the gradient and its use in stochastic gradient descent. Back-propagation usually allows quick convergence on satisfactory local minima for error in the kind of networks to which it is suited. But, this also brings out its inherent drawback since it usually converges to the local minima, instead of the global minima.

There are two passes before the weights are updated. In the first pass (forward pass) the outputs of all neurons are calculated by multiplying the input vector by the weights. The error is calculated for each of the output layer neurons. In the backward pass, the error is passed back through the network layer by layer. The weights are adjusted according to the gradient decent rule, so that the actual output of the MLP moves closer to the desired output. A momentum term could be added which increases the learning rate with stability.

During the (second) backward pass, the difference between the target output and the actual output (error) is calculated

<math>\textstyle e[k]=T[k] - y[k]</math>.

The errors are back propagated through the layers and the weight changes are made. The formula for adjusting the weights is

<math>\textstyle w[k+1] = w[k]+\mu e[k]x[k].</math>

Once the weights are adjusted, the feed-forward process is repeated. The weights are adapted until the error between the target and actual output is low. The approximation of the function improves as the error decreases.

The Algorithm can be summarized as below:

  1. Present a training sample to the neural network.
  2. Compare the network's output to the desired output from that sample. Calculate the error in each output neuron.
  3. For each neuron, calculate what the output should have been, and a scaling factor, how much lower or higher the output must be adjusted to match the desired output. This is the local error.
  4. Adjust the weights of each neuron to lower the local error.
  5. Assign an inertial value for the local error to neurons at the previous level, giving greater responsibility to neurons connected by stronger weights.
  6. Repeat from step 3 on the neurons at the previous level, using each one's inertial value as its error.

System Identification

System identification is the process of developing a mathematical model of a dynamic system based on the input and output data from the actual process [11]. This means it is possible to sample the input and output signals of a system and using this data generate a mathematical model. An important stage in control system design is the development of a mathematical model of the system to be controlled. In order to develop a controller, it must be possible to analyze the system to be controlled and this is done using a mathematical model. Another advantage of system identification is evident if the process is changed or modified. System identification allows the real system to be altered without having to calculate the dynamical equations and model the parameters again. This circumvents most of the mathematically rigorous modeling activities involved in case of complex real systems. The mathematical model in this case is the black box, it describes the relationship between the input and output signals. The inverted pendulum system is a non-linear process. To adequately model it,non-linear methods using neural networks must be used. It can be seen from the literature that neural networks have been successful used in modeling a plethora of nonlinear systems.

As universal approximators, neural networks have found widespread application in nonlinear dynamic system identification.[12][13]. The most common method of neural network identification is called forward modeling. During training both the process and ANN receive the same input, the outputs from the ANN and process are compared, this error signal is used to update the weights in the ANN. This is an example of supervised learning-the teacher (pendulum system) provides target values for the learner (the neural network).

\includegraphics[width=0.5\textwidth]{supervised_learning.PNG} \textbf{Fig. 5.5.1} Supervised Learning

This training/identification can also be done off-line, having collected the input-output data from the inverted pendulum system. In the current work, for the input-output data for the identification of the model the non-linear pendulum model along with a classical feedback LQR controller(discussed in previous sections), is used.

Specifics of the ANN Training

The quality of the neural model is tested by calculating the MSE (mean squared error). The MSE gives a good indication of the accuracy of the model. The MSE between the model and the process should be low. A model could have a low MSE but not predict any of the dynamics of the pendulum system. The output from the model and process is plotted to compare the dynamics. Basically, we want to see whether the model predicts the movement of the inverted pendulum. Increasing the number of hidden layer neurons allows for more complex functions to be modeled. During testing, neural networks with a range of hidden layer neurons were simulated. It was expected that as the number of hidden neurons increased the more accurate the model would become.

Results

In progress..

Graphical User Interface

This Pendulum GUI is a friendly graphical user interface for the BGCE Inverted Pendulum Project. You can easily switch into Classical controller, Fuzzy controller or Neural network by choosing the different Tab of this GUI, also can change between Simulation or Real-time. By default, the Classical controller mode. (Fig. 6.1)

Error creating thumbnail: Unable to save thumbnail to destination
Fig. 6.1 Default Pendulum GUI (Classical controller mode)


Classical Controller Tab

The "Classical" tab consists of Cart Visualization panel, Control panel and State Variables panel.

-Simulation
First, type the required simulation time into Sim Stop Time text box, then click the Run Simulation button to start the simulation. The visualization of the pendulum will be showed in the Visualization axes. After the simulation is done, click the Show Values button in the State Variables panel, the plot of 4 state variables will be showed in the State Variables axis.

-Real-time System
Click the \textbf{Run Real-time System} button to start the real-time system by the pre- complied .wcp file.

Fuzzy Controller Tab

The layout of Fuzzy Tab based on the classical tab but added a Fuzzy rule table panel. (Fig. 6.2.1)

-Simulation
Same as Classical Tab. Because of the features of fuzzy controller, one can also control the fuzzy rules by press/depress the toggle buttons of the Fuzzy rule table. There are tool tips for all the toggle buttons, implies the rule of each button. All the rules are activated by default, deactivate the rule by pressing the related button(turn red), activate by depressing(turn green). The membership function of the fuzzy rules will also be plotted in the sub-GUI during the simulation.

-Real-time System
Same as Classical Tab.

Error creating thumbnail: Unable to save thumbnail to destination
Fig. 6.2.1 Fuzzy controller simulation

Error creating thumbnail: Unable to save thumbnail to destination
Fig. 6.2.2 State Variables

Error creating thumbnail: Unable to save thumbnail to destination
Fig. 6.2.3 Membership Function of Fuzzy Rules


Neural Networks Controller Tab

-Simulation
Same as Classical Tab.

-Real-time System
Same as Classical Tab.


References

[1] "Wikipedia, The Free Encyclopedia",(2008). Available:http://en.wikipedia.org/wiki/Inverted_pendulum

[2] "User Manual",(2008) Available:http://www.segway.de

[3] "Fuzzy Sets and Applications: Selected Papers by L.A. Zadeh", ed. R.R. Yager et al. John Wiley, New York,(1995).[4]

[5] "Neural Networks for Control",W. T. Miller, R. S. Sutton, and P. J. Werbos,Cambridge, MA: MIT Press,(1990).

[6] "Neural Networks for Identification, Prediction and Control",D.Pham,X. Liu, Springer Verlag,(1995).

[7] "Neural Controller based on back-propagation algorithm",Saerens M., Soquet A., IEEE Proceedings UF, Vol. 138, No.1, pp 55-62, (1991).

[8] "Neural Networks",E. Davalo, P. Naim, Palgrave Macmillan (1991).

[9] "Neural Network Toolbox Users Guide",The Mathworks Inc (1998).

[10] "Approximation by superposition of a Sigmoidal Function, Mathematics of Control, Signals and Systems",Cybenko,G,Vol 2, No. 4, pp 303-314, (1989).

[11] "System Identification-Theory for the user",Ljung. L, Prentice Hall (1999).

[12] "Non-linear system identification using neural networks"S. Chen, S. A. Billings, and P.M. Grant,Int. J. Contr., vol. 51, no. 6, (1990).

[13] "Identification and control of dynamical systems using neural networks",K. S. Narendra and K. Parthasarathy, IEEE Transactions on Neural Networks, vol. 1, no. 1, (1990).