engi-5969 degree project ball and beam...

43
ENGI 5969. Ball and Beam Balancer. Page 1 of 43 Group members: Shuba Ambalavanar Hamed Mohamed Moinuddin Andrey Malyshev ENGI-5969 Degree Project Ball and Beam Balancer April 3, 2006 Professor: Dr. Xiaoping Liu Department of Electrical Engineering Lakehead University

Upload: vobao

Post on 29-Apr-2018

276 views

Category:

Documents


8 download

TRANSCRIPT

Page 1: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 1 of 43

Group members:

Shuba Ambalavanar

Hamed Mohamed Moinuddin

Andrey Malyshev

ENGI-5969

Degree Project

Ball and Beam Balancer

April 3, 2006

Professor: Dr. Xiaoping Liu

Department of Electrical Engineering

Lakehead University

Page 2: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 2 of 43

1.0 ABSTRACT Our group has built and tested a beam that balances a 1.5’’ diameter steel ball to a desired

reference position. Much of the difficulty has been encountered throughout the project such as

lack of theoretical information and the poor performance of the mechanical system. The

system was tested from extreme initial conditions when the ball is completely removed and

then replaced at opposite end of the beam, small disturbance where a ball was pushed to one

side, and also position referencing where the ball was controlled all along the length of the

beam. The system performed well, but oscillations were very noticeable due to presence of the

backlash in the gearbox of the motor as well as the friction of the motor. A better system can

be built with a digital controller that would automatically account for these imperfections.

Page 3: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 3 of 43

TABLE OF CONTENTS

1.0 ABSTRACT.......................................................................................................................................... 2

2.0 INTRODUCTION................................................................................................................................. 4

3.0 BACKGROUND................................................................................................................................... 5

4.0 THEORY............................................................................................................................................... 5

4.1 MATHEMATICAL MODEL ........................................................................................................... 6 4.1.1 BALL AND BEAM SYSTEM ................................................................................................. 6

4.1.2 DC MOTOR MODEL.............................................................................................................. 8 4.1.3 OVERALL SYSTEM MODEL ............................................................................................. 12

4.2 CONTROL DESIGN .................................................................................................................... 13

4.2.1 LINEARIZATION OF THE DYNAMICAL EQUATIONS.................................................. 13 4.2.2 LQR CONTROL DESIGN WITH INTEGRATOR FEEDBACK ...................................... 13

4.3 SIMULATION................................................................................................................................ 14 4.3.1 NON-LINEAR DYNAMIC MODEL OF THE SYSTEM .................................................... 14

5.0 HARDWARE...................................................................................................................................... 18

5.1 MECHANICAL COMPONENTS ................................................................................................ 18 5.2 ELECTRICAL COMPONENTS.................................................................................................. 19 5.2.1 SENSORS ............................................................................................................................. 19

5.2.1.1 ANGLE SENSOR .......................................................................................................... 19 5.2.1.2 POSITION SENSOR .................................................................................................... 21

5.2.2 DC SERVO MOTOR ............................................................................................................ 23 5.2.3 ANALOG CONTROL CIRCUIT .......................................................................................... 23 5.2.3.1 ELECTRONIC COMPONENTS .................................................................................. 24 5.2.3.2 DESCRIPTION OF THE ANALOG CIRCUIT ........................................................... 26 5.2.3.2.1 POSITION SENSOR CIRCUIT............................................................................ 27 5.2.3.2.2 ANGLE SENSOR CIRCUIT ................................................................................. 28 5.2.3.2.3 ANALOG DIFFERENTIATOR.............................................................................. 29 5.2.3.2.4 ANALOG INTEGRATOR CIRCUIT..................................................................... 30 5.2.3.2.5 ANALOG SUMMER............................................................................................... 30 5.2.3.2.6 FULL WAVE PRECISION RECTIFIER .............................................................. 31

6.0 PROBLEMS ENCOUNTERED ......................................................................................................... 32

7.0 FUTURE RELATED WORK............................................................................................................. 33

8.0 CONCLUSION ................................................................................................................................... 34

9.0 ACKNOWLEDGEMENT .................................................................................................................. 35

10.0 REFERENCES.................................................................................................................................. 36

APPENDIX A – MATLAB COMPENSATOR DESIGN CODE............................................................ 37

APPENDIX B - SAMPLE RUN OF THE MATLAB CODE .................................................................. 39

APPENDIX C - DATASHEETS .............................................................................................................. 43

Page 4: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 4 of 43

2.0 INTRODUCTION

The ball and beam balancer is a common controls problem that is generally linked to

horizontally stabilizing an airplane during landing and in the turbulent air flow. The system is a

two degrees of freedom 2DOF (ball position and beam angle) system controlled by the voltage

input to the motor. The beam is mechanically mounted at the centre to the shaft of the gearbox

of the motor. The beam is composed of two parallel hollow tubular rails that constrain the

motion of the ball to a single dimension so that it can only roll up and down the beam. With

applied voltage, the motor rotates and the beam swings taking the ball with it. The objective is

to stabilize the ball on the beam at its unstable equilibrium point. Once the stability is achieved,

the ball must return to the desired reference point rejecting all outside disturbance such as

people pushing the ball or swinging the beam. This objective requires precise measurement of

the angle of the beam and the position of the ball. Any non-linearity in the measurements

contributes to the error. It is also important to minimize the friction in the system that

contributes non-linearity.

Page 5: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 5 of 43

3.0 BACKGROUND The ball and beam system is one of the most popular and perhaps one of the most important

models for teaching control applications to engineering students. One of the main reasons it is

widely used is due to the fact that it is a mathematically simple system to understand.

However, the controlling technique covers a broad model design methods.

Since the ball and beam is open loop unstable it requires a compensator to control the position

of the steel ball rolling on the top of the beam. An important property of controlling an unstable

system is the feedback which is essential to make the system operate.

Understanding this concept is important since the majority of modern industrial and

technological processes is open loop unstable and requires basic controls knowledge.

4.0 THEORY The theoretical background is essential to successful completion of the project. The physical

concepts behind the set up of the system must be understood in order to design a better

controller. There are two distinct approaches that can be used to model the ball and beam

system: the Lagrange equations and the Newton balance of forces approach. The Lagrange

method is based on the kinetic and potential energy contained within the system. The

Lagrange method produces the following set of equations:

ballbeam

ball

JJmx

xmxmgx

mR

J

gxx

++

−−=

+

−=

••

••

2

..

2

2..

2cos

1

sin

θθτθ

θθ

(4.A)

This set of equations is derived for a round rigid body in motion on top of a frictionless surface

tilted by a DC motor. It includes velocity and angular velocity terms which maybe considered

negligible. If sophisticated computation software is used for control, no such neglect is

necessary.

The other approach is to balance out all forces acting on the ball in motion on top of the beam.

This method is more specific, more orderly and more easily understood. The Newton balance

of forces method is described in greater detail below.

Page 6: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 6 of 43

4.1 MATHEMATICAL MODEL

The mathematical model of the system is obtained by balancing out all of the forces acting on

the ball as it rolls down the beam. Secondly, all torques acting on the beam are summed in

order to isolate the input variable - Voltage.

4.1.1 BALL AND BEAM SYSTEM

Consider the following sketch

Figure 4.1: Rolling ball on a beam free-body diagram

The inclination is considered the x-coordinate.

Let acceleration of the ball be denoted as

••

= xdt

xd2

2

(4.1)

The force due to translational motion is then

••

= xmFtx (4.2)

The torque developed through ball rotation is determined by the force at the edge of the ball

multiplied by the radius of the ball:

Page 7: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 7 of 43

( )

''/)/(2

2

xR

J

dt

RxdJ

dt

RvdJ

dt

dwJRFT bb

rxr ===== (4.3)

where

J = moment of inertia (for solid ball defined by J=2/5*mR2)

Wb=angular velocity of the ball

Vb= speed of the ball along x axis

The objective now is to have the equations re-arranged such that the final result is expressed

solely in terms of position or its derivatives as well as variables associated with the ball.

The rotational force is determined by dividing the rotational torque of the ball by its radius

''2 xRJ

RT

F rrx == (4.4)

The moment of inertia of a solid sphere is a physical constant which can be substituted into

(4.4) to yield

''5

2''5/22

2

mxxR

mRFrx == (4.5)

Summing all forces in the x-direction produces the following

α

α

α

sin''''5

2

sin''''5

2

sin

gxx

mgmxmx

mgFF txrx

=+

=+

=+

re-arranging for x’’ yields

''sin7

5 xg =α (4.6)

The equation (4.6) is the non linear description of the ball and beam system. The system can

be linearized using the approximation

αα =sin (4.7)

This approximation is good for angle values of44

παπ ≤≤− . This means that in radians, sine

of the angle is approximately the angle itself and the (4.6) becomes

Page 8: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 8 of 43

''7

5 xg =α (4.8)

taking Laplace transform of position with respect to angle yields

2

75

)(

)()(

s

g

s

sXsH x ==

θ (4.9)

The constant in the numerator was confirmed with manual measurements and matches the

theory well. Therefore the transfer function for the ball and beam system is

2

7

)(

)(

ss

sX=

θ

This system takes the angle as the input and outputs acceleration. The stepper motor is the

perfect actuator to employ for this system since the output of the stepper motor is angle. A

more complex control system results if the DC motor is used.

4.1.2 DC MOTOR MODEL

The output of the DC motor is the pivoting torque applied at the centre of the beam. The DC

motor subsystem can be modeled by considering the following sketch

Figure 4.2: Torque experienced by the beam

The diagram demonstrates how much torque will be contributed by the weight of the ball. This

torque must be countered by the motor to tilt the beam in the opposite direction. The equations

of interest are

α

( )αcosgmball

x

Page 9: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 9 of 43

EIRV

KE

K

IKT

AA

w

g

Amgmgearedmotor

+=

=

=

.

,

α

η

(4.10)

The DC motor supplies the torque to the beam which is amplified by the gearbox and reduced

by the efficiency of the gearbox and the motor. For the purposes of this project the efficiency is

assumed to be 70 percent, i.e. 7.0=gmη . The torque generated by the weight of the ball on the

pivot point can be derived from the free-body diagram shown in figure 4.2 as

αcosgxmT ballball −= (4.11)

The torque on the beam generated by the DC motor is a function of the input current

g

Am

gmgearedmotorK

IKT η=, (4.12)

The current may be expressed in terms of input voltage as follows

A

mmA

mmAA

AAA

R

wKVI

wKRI

ERIV

−=

+=

+=

(4.13)

The constants for (4.13) are

251

73.9

7.6

=

=

Ω=

g

m

A

K

V

sras

K

R

Page 10: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 10 of 43

The equation 4.13 is correct for the DC motor without the gearbox. The addition of the gearbox

redefines the angular velocity reducing it by a factor of Kg i.e. mgnew wKw = . This new variable

happens to be the angular velocity of the beam. Therefore, .

α=neww and A

mA

R

KVI

.

α−=

The motor torque delivered to the beam is amplified by the gearbox at the expense of slower

shaft rotation. The torque experienced by the beam can be expressed as

αηα cos..

, xmgK

IKJ

dt

dwJTTT

g

Am

gmbeambeamballgearedmotorbeam −===+= (4.14)

This easily rearranges to the angular acceleration of the beam as follows:

beam

ball

g

Amgm

J

gxmK

IKαη

α

cos..

= (4.15)

where Jbeam is a physical constant defined as

2

12

1beambeambeam LmJ = (4.161)

Therefore, the last differential equation becomes

2

..cos

12beambeam

ball

g

Amgm

Lm

gxmK

IKαη

α

= (4.17)

where,

mball=0.225kg

mbeam=0.5kg

Lbeam=1.5m

g=9.81m/sec2

Substituting (4.13) into (4.17) yields

1 Source: http://en.wikipedia.org/wiki/List_of_moments_of_inertia

Page 11: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 11 of 43

mgbeam

beambeam

ball

beambeamA

mgm

beambeamAg

mgm

wKw

where

xLm

gm

LmR

KV

LmRK

K

==

−−=

.

2

.

2

2

2

.. cos121212

α

αα

ηηα

(4.18)

The substituting numerical values into (4.18) yields

ααα cos54.233.1058.270...

xV −−= (4.19)

Equation 4.19 can be linearized by assuming that cosine alpha is approximately 1.

1cos ≈α (4.20)

This is a very rough estimate and the linearized dynamic model will breakdown if the angle or

the bandwidth becomes too high.

The linearized equation is

xV 54.233.1058.270...

−−= αα (4.21)

This forms the second differential equation of the ball and beam system controlled by a DC

motor. This equation can be completely avoided if a stepper motor is used to control the

system.

Page 12: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 12 of 43

4.1.3 OVERALL SYSTEM MODEL

The overall system model can now be obtained by combining (4.9) and (4.21) together.

[ ]

==

=

−−

=

=

+=

.

.

2

.

,0001

0

0

0

,

00

1000

07

500

0010

α

αx

x

xC

RJK

KnB

RJ

Kn

J

gm

g

A

Cxy

BuAxx

Abeamg

mgm

Abeam

mgm

beam

ball (4.22)

This system contains poles on the imaginary axis and the system is marginally stable. The

state space representation for the system is shown in (4.22). The rank of the controllability

matrix is 4 therefore the system is fully state controllable. However, for the purposes of this

project the only state variable of interest is the ‘x’ position of the ball. The integrator feedback

will also be applied in order to improve performance.

The numerical state-space representation is obtained by substituting the values into (4.22)

[ ]0001

8.270

0

0

0

,

3.1050054.23

1000

0700

0010

.

=

=

−−

=

=

+=

C

BA

Cxy

BuAxx

(4.23)

This is the state-space representation that forms the basis for the LQR controller design.

Page 13: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 13 of 43

4.2 CONTROL DESIGN

The compensator is designed using MATLAB. The code is shown in Appendix A.

4.2.1 LINEARIZATION OF THE DYNAMICAL EQUATIONS

The linearization of the system is performed by approximating all nonlinear variables of the

system model with their linear equivalents. Non linearities must be linearized before the

compensator can be designed because the applied control to the system is strictly linear state-

space feedback. The assumption is made that under steady state conditions the angle and the

position are zero. Equations (4.8) and (4.21) are the linear equivalents of the non-linear

system.

4.2.2 LQR CONTROL DESIGN WITH INTEGRATOR FEEDBACK

The ball and beam system is controlled with a compensator based on the LQR control law with

the integrator feedback. The angle and the position are the state variables that can be

measured directly using sensors while the angular speed of the beam and the speed of the ball

are the variables estimated using analog differentiator circuits. The control law can be

expressed using equation (4.24)

( ) τττ dxxKtKXtut

dI ∫ −+−=0

)()()()( (4.24)

The convergence of all state variables must be verified before a compensator can be

designed. The controllability condition can be verified by the rank of the controllability matrix Co

shown in (4.25)

[ ]BABAABBCo

32= (4.25)

The MATLAB calculates the rank of the controllability matrix of four which confirms that the

system is completely state controllable. The objective of the LQR controller is to stabilize the

ball at the reference position and reject all disturbances.

Page 14: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 14 of 43

Vertical concatenation of the A and –C matrices followed by horizontal concatenation of the

zeros 5x1 vector produce the new state space A matrix that will used for the compensator

design as shown in (4.26)

[ ] [ ]000010

0

8.270

0

0

0

0

,

00001

03.1050054.23

01000

00700

00010

0

0

==

=

=

−−

=

−=

CC

BB

C

AA

new

new

new

(4.26)

4.3 SIMULATION

Simulation is performed using the non-linear dynamic model in SimuLink, MATLAB.

4.3.1 NON-LINEAR DYNAMIC MODEL OF THE SYSTEM

The non-linear model of the system is shown in figure 4.3. The equations used to build up this

model are (4.6) and (4.19) that can be rewritten as

ααα

α

cos54.233.1058.270

sin7

5''

...

xV

gx

−−=

= (4.27)

There is a small amount of backlash that occurs inside the motor gear box. The mismatch in

gears directly affects the performance introducing approximately 2 to 3 degrees of backlash

when the direction of the rotation changes. To account for this, the backlash block is

incorporated into the model with a deadzone of 0.02 radians as shown in figure 4.3. The

system takes the voltage input and generates four outputs. These outputs are the state

variables:

Page 15: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 15 of 43

=

=

.

.

4

3

2

1

4

3

2

1

α

αx

x

out

out

out

out

x

x

x

x

The state variables can be fed back into the gain matrix K to generate the control voltage

‘u’=-Kx. This appears in the simulation diagram in figure 4.4.

Figure 4.3: Nonlinear ball and beam model

The block diagram of figure 4.3 can be made into a subsystem and further manipulated in

MATLAB to arrive at the final simulated model as shown in figure 4.4

Page 16: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 16 of 43

Figure 4.4: Non-linear ball and beam model with LQR compensator simulated in MATLAB

The –K and –Ki vectors are designed using the control law equation (4.24) with the LQR

command in MATLAB. The LQR command effectively returns the gain matrix K to ensure

system stability. The steady state error of the ball position can be brought to zero using the

tracking controller that integrates the error over time relative to the linear set point. Addition of

the integrator also reduces the overall system convergence time. The fifth value of the K matrix

is the Ki that can be automatically isolated in the software code and displayed separately. For

coding details on the LQR methods used for the compensator design in MATLAB, refer to

Appendix A and Appendix B.

The simulation of the designed parameters maybe performed in simulink using the non-linear

system model with the compensator gains designed in MATLAB. Selecting the Q matrix as a

5x5 identity matrix and the R=0.1 yields

[ ]

16.3

82.242.1754.61.7

−=

=

iK

K (4.17)

Here it is seen that the least emphasis is placed on the angular velocity which is the state

variable that is amplified the least. The simulation is configured with the following parameters:

1. Zero initial conditions

2. Small disturbance to the ball position occurs at t=1sec and dissipates at t=1.1sec

3. Reference position changes at t=5sec

4. Saturation block limits voltage input between 12 and -12.

Page 17: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 17 of 43

The results of the simulation may be seen in figures 4.5 and 4.6

Figure 4.5: Ball position simulation with disturbance and reference change

The simulated results show what happens if ball is moved 0.5 meters off centre and then

replaced back to centre 0.1 seconds later. The response of the system is stable and smooth.

In practice, oscillations will occur in the system. It is also seen that the position takes more

than 4 seconds to return back to zero. The R value can be further reduced in order to speed up

the system.

Page 18: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 18 of 43

Figure 4.6: Beam angle responding to position disturbance and reference change

The angle converges quickly staying within the linear range44

παπ ≤≤− . The angle responds

quickly to the disturbance and reference changes. The overall conclusion can be made that

system will work well under linear quadratic regulation.

5.0 HARDWARE The hardware for the project includes mechanical components as well as the electrical

components.

5.1 MECHANICAL COMPONENTS

The mechanical system consists of the two hollow tubular aluminum rails fixed side-by-side

with a combined weight of approximately 500 grams. The aluminum beam is rigidly attached to

a flat aluminum base plate in the middle of the beam. The base plate is mounted onto the

shaft of the gearbox of the DC motor. One side of the baseplate is attached to the DC servo

Page 19: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 19 of 43

motor while other side is attached to the potentiometer sensor that measures the angle of the

beam. The actual mechanical system is shown below in figure 5.1

Figure 5.1: Actual mechanical assembly of the system

5.2 ELECTRICAL COMPONENTS

The control of the system is performed by analog electronics and sensors linked with the

mechanical actuator – the DC servo motor. The array of electronic components used for the

project is described in greater detail below.

5.2.1 SENSORS

One of the main electronic components used in the project are the sensors. There are two

different kinds of sensors - the angle sensor and the position sensor.

5.2.1.1 ANGLE SENSOR

For angle measurement, an analog variable potentiometer is implemented. The variable

potentiometer is a 10KΩ, 0.5Watt, single turn, conductive plastic, Vishay, model 357 precision

potentiometer as shown in Figure 5.2

Page 20: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 20 of 43

Figure 5.2: Vishay Conductive Plastic Potentiometer used for measuring the angle

This device is a simple and inexpensive way of measuring the change of resistance as the

beam pivots clockwise or counterclockwise. The pot is mechanically mounted on the wall

beside the centre of the beam’s base plate and its shaft is directly opposite the gearbox shaft.

This way, the shaft of the pot rotates with the shaft of the gearbox. By feeding a +12V to one

side of this variable resistor and ground the other end, a variable voltage can be obtained

proportional to the actual angle of the beam. This means that the angle of the beam is

proportional to the measured voltage at the pot. The equation for the proportionality constant is

given by

The angel Ө = π212V

= 0.0333V/Degree

=1.90985V/Radian

Figure 5.3: Equivalent circuit diagram of the variable resistor

Here Pin 1 = +12V and Pin 3 = 0V while Pin 2 outputs the measured voltage corresponding to

the rotation of the beam either clockwise or counter clockwise. In addition, the pot reading is

Page 21: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 21 of 43

compared to the reference voltage of -6V to give a 0V reading at an angle of 0 о as per figure

5.3. Hence, this will make the measurement of the angle easier, since any deviation from the

0 о angle will give a voltage reading of either smaller or greater than 0V.

5.2.1.2 POSITION SENSOR

The position sensor is used to measure the distance that the ball travels away from the

reference point. In this system the pivot point at the centre of the beam is the reference point.

Hence, any deviation from the center will cause a variation in output voltage reading. Initially,

a light emitting device such as a Sharp GP2Y0A002 was used to measure the distance.

However, it proved to be unreliable device since the LEDs at the opposite ends of the beam

would cross interfere with one another. Using a single LED device also proved impractical

because of nonlinearity in the distance measurement.

The position sensor used in this project is a Nichrome 80 resistance wire alloy with a diameter

of 0.0100in and approximate resistivity of 6.511 ft/Ω

Each tubular beam rail is covered with a double layer of acrylic. The resistance wire is

attached on top of the acrylic tape with super glue. The opposite rail contains the return wire.

The ball rolls on top and samples the voltage along the resistance wire sensor. This voltage is

then returned to the control circuit via the return wire. The input impedance of the control circuit

is very high therefore the ball conducts only minimal amount of current. Minimal amount of

current flow through the ball leads to considerable reduction of noise in the reading and

improves measurement accuracy.

As the ball travels up and down the beam, the voltage reading will change between 0V and

0.1V. This is a small change, but since it contains very small amount of noise, it can be

amplified by the analog circuit to provide accurate readings. The mathematical model requires

that one meter difference in position is represented by 1V difference in potential. This is easily

achieved by an amplification factor of 12 which immediately follows after the sensor’s low pass

RC network. The resistance wire may be seen in figure 5.4

Page 22: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 22 of 43

Figure 5.4: Nichrome Resistance wire on the left, return wire on the right

By comparing the voltage reading to a reference voltage of -0.5V, a voltage of 0V is obtained

at the center of the beam. This 0V measures a zero millimeter distance at the center of the

beam. The equation for this proportionality is given by

The distance X = mm

V

1000

1

= 0.001V/millimeter

Page 23: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 23 of 43

5.2.2 DC SERVO MOTOR

The DC servo motor used for the project is a Japan Servo DFS-10G-05 originally used in

HP2686A/HP2686D laser printers as shown in Figure 5.5. The electrical specifications of the

motor are

Pout=13W

Vin=24V

Imax=0.54A

The approximate overall size of the motor is inchesinchesinches8

154

344

15 ×× .

The motor is mounted to a gear reduction box with 1:25 gear ratio; this reduces the speed of

the motor while providing more torque to lift the beam up in either direction.

Figure 5.5: DFS-10G-05 DC Servo Motor

5.2.3 ANALOG CONTROL CIRCUIT

Analog circuit is the brain of the ball and beam system since it controls the position of the ball

on the beam. There are many electronic components used in the analog compensator circuit.

These components combine together to form the controller of the system.

Page 24: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 24 of 43

5.2.3.1 ELECTRONIC COMPONENTS

The electronics components used for this are as follows:

1. Resistors :

Various resistors are used in the analog circuit to oppose the current flow

2. Capacitors:

Various capacitors are used for the purpose of filtering, as well as to build integrator and

differentiator circuit.

3. Diodes:

The switching diode 1N4148 used for the purpose of rectification

4. Op-Amps(LM-741) :

The common LM741 operational amplifiers are used for various purposes, such as

amplification, comparing, summing, differentiating, and integrating various signals

5. H-Bridge

LMD18200 H-Bridge is used to control the DC Servo Motor. This H-Bridge chip uses the PWM

(pulse width modulation) signal for speed control and a direction pin to change direction of the

motor rotation. Basically the higher the duty cycle from the PWM chip the faster the motor will

spin given either direction.

Page 25: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 25 of 43

6. Heat Sink

Heat Sink is used to remove the heat produced by the H-Bridge, since the LMD18200 chip

utilizes MOSFETs that dissipate heat due to the internal resistance.

7. PWM(Pulse Width Modulation)

TL-494 PWM modulator is used in this analog circuit to generate square pulses of 0 to 100%

duty cycle which is then fed to the H-Bridge.

8. Opto-Isolator

The main reason an Opto-Isolator is used in the circuit is for direction control and total isolation

of this circuit from rest. The total isolation is necessary since H-Bridge only takes logical High

or Low. This is feasible because the Opto-Isolater gives logical values of high (greater than 0)

or low (0) as the output for any input. This logic is then fed to H-Bridge direction pin which in

turn controls the motor direction depending on the logic value.

Page 26: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 26 of 43

5.2.3.2 DESCRIPTION OF THE ANALOG CIRCUIT

Below is the complete diagram of the circuit that controls the ball and beam.

Title

Size Document Number Rev

Date: Sheet of

1

Degree project 2006: Ball and Beam Control Circuit Diagram

A

1 1Monday , April 03, 2006

LM741

+

-

OUT

LM741

+

-

OUT

R25

1k

V5

-12Vdc

R27100K

R28

100K

U21LMD18200

OUT12

OUT210

BS11

BS211

DIR3

PWM5

BRAKE4

ISENSE8

TFLAG9

R29

100K

R30

100K

R31

390K

U22

TL494

C18

E19

C211

E210

In1+1In1-2

In2+16In2-15

OC13

RT6CT5

FBK3

DTC4

Ref Out14

Black wire from the angle pot

LM741

+

-

OUT LM741

+

-

OUT LM741

+

-

OUT

R4

680K

U11

OPAMP

+

-

OUT

U12

OPAMP

+

-

OUT

R5

100KR6

100K

R32

1k

R7

1.2MR8

12K

C6

1n

R9

560K

R34

1k

R35

10K

R10

0.33K

R11

15K

R36

10K

R37

2.2K

C10.15uF

R38

10K

R12

1k

OPAMP

+-

OUT

OPAMP

+

-

OUT

R39

1k

R40

1kR41

2K

R42

1k12

D2

1N639212

R13

560K

V2

+12Vdc

R43

5K

U15

OPAMP

+

-

OUT

U17

OPAMP

+

-

OUT

U18

OPAMP

+

-

OUT

C2

0.15uF

R44

1k

R46

1k

R47

5.6K

R1

100K

10K

C3

2.2uF

V6

-12Vdc

White Wire from the Beam

Gray Wire to the Beam

Gray Wire to the Beam

+12Vdc

C60.01uF

U6

LM741

+

-

OUTLM741

+

-

OUT

R2

2.2M

R3

220K

5.6K

R14

330K

R15

120K

R16

220K

C4

0.15uFR17

10K

R50

1k

R51

1k

10K

5.6K

V1

-12Vdc

10K

V3

+12Vdc

U19

A4N33

5.6K

LM741

+

-

OUT

R18

150KR19

120K

R47

5.6K

V8

5Vdc

C6

0.01uF

U9

LM741

+

-

OUT

R20

120K

C6

0.01uF

R21

120K

R22

120K

Black Wire going to the motor

Red wire going to the motor

R23

120K

PORTRIGHT-R

PORTRIGHT-R

R24

15K

C5

0.15uF

V4

-12Vdc

Figure 5.6: Complete analog circuit of the ball and beam system

The circuit consists of a combination of analog sub-circuits that work together to output the

desired result. Some of the most notable sub-circuits are described in greater detail below.

Page 27: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 27 of 43

5.2.3.2.1 POSITION SENSOR CIRCUIT

U1

LM741

+3

-2

V+7

V-4

OUT6

OS11

OS25

R3

1K

SET = 0.5

R4

0.33K

2

1

R5

100K

21

R6

1.2M

21

R7

100K

21

R8

680K

21

U2

LM741

+3

-2

V+7

V-4

OUT6

OS11

OS25

V1

+12Vdc

V2

-12Vdc

V3

+12Vdc

V4

-12Vdc

V5

-12Vdc

0

Gain = 12

Gauge 30 resistance wire

Figure 5.7: Position sensor configuration circuit

The position sensor circuit consists of two OP AMPs. The first OP-AMP supplies the power to

the resistance wire through the 330Ω resistance. The combined current through the resistance

wire is

mAK

KV

I wireceresis 525330

680

10012

tan =Ω+Ω

−=

Since the resistance wire will have different resistance at different points along its length, the

voltage reading along the wire would also be different. For example in the middle of the wire

the reading would be

VmAV beamofcentre 06.05.125 =Ω×=

This voltage is amplified in the second stage by a factor of 12 and becomes

VVV amplifiedbeamofcentre 72.01206.0, =×=

Page 28: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 28 of 43

5.2.3.2.2 ANGLE SENSOR CIRCUIT

The angle circuit operates identically to the position sensor circuit with the exception that the

reference voltage is directly summed with the reading to give zero output when the beam is

completely horizontal. The circuit is shown in figure 5.8

U1

LM741

+3

-2

V+7

V-4

OUT6

OS11

OS25

R7

100K

21

V1

+12Vdc

R3

10K

Reference Voltage Pot

Variable Pot R4

100K

2

1

R4

100K

2

1

V1

-12Vdc

V1

+12Vdc

V1

+12Vdc

Angle Reading

Figure 5.8: Angle sensor circuit principle

Page 29: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 29 of 43

5.2.3.2.3 ANALOG DIFFERENTIATOR

Figure 5.8: Analog Integrator and Differentiator principles

The differentiator circuit features the capacitor in series with input. The capacitor rejects the

DC-component of the input and passes only the change in voltage level. When the ball rolls

down the beam the voltage from the position sensor begins to change and capacitor begins

charging/discharging to a new level. This produces an output at the differentiator circuit. This is

the principle behind measuring state variables x’ and 'θ . The problem with this is that this

circuit will amplify all incoming noise therefore a low pass RC network must be included with a

fast time constant. Since the sensors feature only small amounts of noise, the poles of the RC

Page 30: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 30 of 43

filter networks were very far in the left-half plane (sfilter=-100 or farther) hence their effect was

not considered in the controller design.

5.2.3.2.4 ANALOG INTEGRATOR CIRCUIT

The analog integrator was used to integrate the error of the position of the ball. This circuit

functions by taking the average of the error voltage. If the capacitor has charged and the error

still exists, the integrator will output the amplified error to generate additional control effort. If

the error dies down, then the capacitor does not have enough time to charge and the output of

the integrator is zero.

5.2.3.2.5 ANALOG SUMMER

Figure 5.92: Analog summing circuit

The analog summing circuit is one of the crucial pieces of the project. This is the circuit that

combines all incoming amplified state variables and sums them to generate the control signal.

( )44332211 xKxKxKxKu +++−=

This control input ‘u’ is used to drive the direction pin3 of the LMD18200 H-bridge through a

comparator and an opto-isolator. This control input is also controlling the duty cycle of the

LMD18200 H-bridge through a TL-494 PWM modulator. Since the PWM accepts only positive

analog signal at the input to generate a variable duty cycle output, the control signal ‘u’ must

be rectified before feeding it into the TL494 PWM circuit.

2 http://www.ecircuitcenter.com/Circuits/opsum/opsum.htm

Page 31: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 31 of 43

5.2.3.2.6 FULL WAVE PRECISION RECTIFIER

U1

LM741

+3

-2

V+7

V-4

OUT6

OS11

OS25

R10

4.7K

SET = 0.5

Control Input 'U'

V3

+12Vdc

V1

-12Vdc

R5

2K

21

R9

1K

2 1

D3

D1N4148

D4

D1N4148

U1

LM741

+3

-2

V+7

V-4

OUT6

OS11

OS25

V3

+12Vdc

V1

-12Vdc

R8

1K

2 1

R91K

2 1

To PWM

Figure 5.10: Analog precision rectifier circuit

The precision rectifier above is a reliable but slightly noisy device that was used to rectify the

control signal ‘u’. This circuit takes the ‘u’ input which swings positive and negative depending

on the state-variables of the system. This input is then precisely rectified and the generated

output is only a positive analog signal. This output is used to drive the PWM modulator, which

in turn drives the H-bridge and the H-bridge controls the motor.

Page 32: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 32 of 43

6.0 PROBLEMS ENCOUNTERED

Over the course of this project numerous problems were encountered. The goal was to build

and test a beam that balances a 1.5’’ diameter ball to a desired reference position. Much of the

difficulty has been encountered throughout the project such as lack of theoretical information

and the poor performance of the mechanical system.

Initially to measure the ball position on the beam, we adapted a photo diode device. However,

this type of a device is non-linear. Using two such devices is possible but the error results

when each of these devices cross-interferes with one another. It proved extremely difficult to

obtain a laser beam distance sensor with linear characteristics and necessary specifications at

an affordable price.

Hence, an alternate solution to this problem was to adapt a Nichrome (NiCr) resistance wire to

measure the position of the ball. This type of measuring method introduces noise into the

system. By having constant current flowing through one wire and using the other wire to return

the signal the noise problem was reduced substantially.

Other major problem was due to the gear backlash and motor friction. The system was tested

from extreme initial conditions when the ball is completely removed and then replaced at

opposite end of the beam, small disturbance where a ball was pushed to one side, and also

position referencing where the ball was controlled all along the length of the beam. The system

performed well but oscillations were very noticeable due to presence of the backlash in the

gearbox. This type of a problem can not be eliminated from the system completely. The

friction of the motor also contributed to the noise in the system. However, a better system can

be built with a digital controller that would automatically account for these imperfections.

Other areas where problems were encountered are the delay times to receive the parts that

have been ordered and some of the electronic components that did not work mainly because

they burned out.

Page 33: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 33 of 43

7.0 FUTURE RELATED WORK

Definitely an improved system can be build for precision. Our future work on this project is to

improve the performance of the system. Some of the areas of improvement include building a

digital system which can sample very small analog signal and perform mathematical

computation.

Also, using an encoder for the angle measurement would be more precise since encoders can

automatically generate thousands of encoded feedback signals for a small change in angle.

Hence, this would provide better measurement and improve the overall performance of the

system.

Additionally a user friendly version can be built using a Visual Basic program that interfaces

with the digital system. This would provide live performance parameters of the system that

can be viewed on computer monitor.

Page 34: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 34 of 43

8.0 CONCLUSION Although a ball and beam balancer is simple to design and run simulation in theory, practical

implementation of the real circuit was difficult to match to the simulation results, since most of

the time simulations are related to near ideal situations.

There were many non-idealities that had to be considered when implementing the actual

circuit, such as by-passing, noise reduction and oscillations etc. Without correcting these

problems, it would not be possible to build a circuit that satisfies specific controlling needs.

This project was really a true learning curve and one can really apply these techniques when

implementing other projects. One of the greatest lessons learned was that hard problems can

be solved through dedication, determination and teamwork. One other critical element

pertaining to the project is time management. It is important to take the time and learn the

physical concepts and then apply them in practice according to the plan. In our case we did not

follow the plan all the way, which at the end became a very costly choice to make and we were

forced to rush towards completion of the project.

Page 35: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 35 of 43

9.0 ACKNOWLEDGEMENT

During this project there were a number of people who helped us to achieve our goal. First of

all, we would like thank Dr. Xiaoping Liu (Associate Professor of Electrical Engineering). Dr.

Liu, who was our supervisor during this project, helped and encouraged us to the very end to

finish this project. He was always there and willing to help us any way he could and without

him we would not able to complete this project on time.

We would also like to thank Dr. A. Tayebi (Associate Professor, Electrical Engineering), Dr. C.

Christoffersen (Assistant Professor, Electrical/Software Engineering) for their contribution by

answering questions without hesitation.

Next to the professors, we would also like to thank the Technologists for their contribution to

this project. For most, we would like thank Manfred Klein (Technologist, Electrical

Engineering) for his tremendous support in supplying the necessary electrical and electronic

parts to build and test the circuit and especially allowing us entry into his lab to perform the

necessary testing.

We would like to thank Kailash Bhatia (Technologist, Mechanical Engineering) for his excellent

design and work on the mechanical structure of the ball and beam system.

We would also like to thank Warren Paju (Technologist, Electrical Engineering) and Bruce

Misner (Technologist, Electrical Engineering) for their support and advice on the project.

Last but not least, we would like to thank Subodh Madiwale for his ideas in this project. Also,

gratitude goes out to Monish, Adam, Brian Manson, Darren Van Der Meer and Ryan for their

support in instructing us on how to program the PIC microcontrollers.

Page 36: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 36 of 43

10.0 REFERENCES - Digital ball and beam system built by Jeff Lieberman

http://www.bea.st/sight/rbbb/rbbb.pdf

- Lund University, Lab Manual, Ball and Beam

http://www.control.lth.se/~kurstr/Exercise5/BallandBeam.pdf

- Milwaukee School of Engineering, Lab Manual, Ball and Beam

http://people.msoe.edu/~saadat/9%20Ball%20and%20Beam.pdf

- Maastricht University, Lagrangian Equations for Ball and Beam

http://www.cs.unimaas.nl/p.spronck/Pubs/ICMLC04_IDxxx.pdf

- Wikipedia Online Encyclopedia, Standard List of Moments of Inertia

http://en.wikipedia.org/wiki/List_of_moments_of_inertia

- University of Michigan, State Space representation of the Ball and Beam

http://www.engin.umich.edu/group/ctm/state/state.html

- PIC programming tutorial by Rob Sonja

http://members.cox.net/sonjarob/TUTs/uP4Idiots.html

- Texas Instruments

http://www.ti.com/

- GOOGLE

http://www.google.com

- National Precision Ball

http://www.nationalball.com

Page 37: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 37 of 43

APPENDIX A – MATLAB COMPENSATOR DESIGN CODE

clc;

%****************************************************************%

% ENGI-5969 Ball and Beam Balancer controller gains

% Ambalavanar Shuba, Malyshev Andrey, Moinuddin Hamed

% April 2006, Lakehead University

%****************************************************************%

%-------------------

eff=0.7; %efficiency constant for motor and gearbox

Km=9.72; %motor constant

RA=6.7; %armature resistance

Kg=1/25; %gear constant

L=1.5; %beam length

mbeam=0.5; %mass of the beam

mball=0.225; %mass of the ball in kg

Jbeam=1/12*mbeam*(L^2); %moment of inertia of the beam

Kangle=1.91; %angle sensor constant

Kpos=1; %position sensor constant

tau=0.3; %average motor constant

g=9.81; %gravity constant

Kgain=10/2.2; %circuit multiplier for the Ki, K1 and K2 gains

Cbar=[0 0 1 0; 1 0 0 0]; %for isolating two outputs - angle and position

A=[0 1 0 0; 0 0 5/7*g 0; 0 0 0 1; -mball*g/Jbeam 0 0 -(eff*Km^2)/(Jbeam*RA)]

B=[0; 0; 0; eff*Km/(Kg*Jbeam*RA)]

C=[1 0 0 0]

Page 38: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 38 of 43

fprintf('Rank of controllability matrix: \n')

rank(ctrb(A,B)) %rank of the controllability matrix

Q=eye(5)*input('Enter Q identity matrix multiplier (integer value) \n') %any Q multiplier from the user

Q(1,1)=input('Enter energy for the position control \n')

R=input('Enter R value \n') % any R from the user

Abar=horzcat(vertcat(A, -C),zeros(5,1)) %generating the new A matrix with integrator

Bbar=vertcat(B,zeros(1,1)) %generating the new B matrix with integrator

[Kbar,S,E]=lqr(Abar,Bbar,Q,R) %calculating all LQR and integrator gains

K=[Kbar(:,1), Kbar(:,2), Kbar(:,3), Kbar(:,4)] %isolating the controller gains

Ki=[Kbar(:,5)] %isolating the integrator gain

Resistors=[0.1*Kbar(:,1)/Kgain, 0.1*Kbar(:,2)/Kgain, 0.1*Kbar(:,3)/Kangle, 0.1*Kbar(:,4)/Kangle, 0.1*Kbar(:,5)/Kgain]

fprintf('In megaohms \n')

Page 39: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 39 of 43

APPENDIX B - SAMPLE RUN OF THE MATLAB CODE A =

0 1.0000 0 0

0 0 7.0071 0

0 0 0 1.0000

-23.5440 0 0 -105.2894

B =

0

0

0

270.8060

C =

1 0 0 0

Rank of controllability matrix:

ans =

4

Enter Q identity matrix multiplier (integer value)

1

Q =

Page 40: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 40 of 43

1 0 0 0 0

0 1 0 0 0

0 0 1 0 0

0 0 0 1 0

0 0 0 0 1

Enter energy for the position control

1

Q =

1 0 0 0 0

0 1 0 0 0

0 0 1 0 0

0 0 0 1 0

0 0 0 0 1

Enter R value

0.1

R =

0.1000

Abar =

0 1.0000 0 0 0

0 0 7.0071 0 0

0 0 0 1.0000 0

Page 41: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 41 of 43

-23.5440 0 0 -105.2894 0

-1.0000 0 0 0 0

Bbar =

0

0

0

270.8060

0

Kbar =

7.0789 6.5367 17.4169 2.8174 -3.1623

S =

3.8981 1.6364 2.2930 0.0026 -2.0671

1.6364 1.2975 2.0932 0.0024 -0.7860

2.2930 2.0932 5.5673 0.0064 -1.0139

0.0026 0.0024 0.0064 0.0010 -0.0012

-2.0671 -0.7860 -1.0139 -0.0012 2.2660

E =

1.0e+002 *

Page 42: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 42 of 43

-8.6281

-0.0185 + 0.0186i

-0.0185 - 0.0186i

-0.0087 + 0.0050i

-0.0087 - 0.0050i

K =

7.0789 6.5367 17.4169 2.8174

Ki =

-3.1623

Resistors =

0.1557 0.1438 0.9119 0.1475 -0.0696

In megaohms

Page 43: ENGI-5969 Degree Project Ball and Beam Balancerflash.lakeheadu.ca/~amalyshe/5969/report-official.pdf · ENGI-5969 Degree Project Ball and Beam Balancer April 3, ... 4.1.1 BALL AND

ENGI 5969. Ball and Beam Balancer. Page 43 of 43

APPENDIX C - DATASHEETS