You are on page 1of 34

2023-2024

Control System Design

Design of a controller for the plant


The Ball and Beam

GROUP 34 Professor :
FONTEYN Martin GARONE Emmanuele
KHALIL Kassem Teaching assistant :
NGUYEN VAN BINH Julien BUSSIOS Maxime

2023-12-01
Contents

1 Introduction 1
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

2 Plant 2
2.1 Plant description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.1.1 Static characteristic of the DC motor . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Instrumentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.3 Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.4 Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

3 White box modelling 5


3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.2 Angular velocity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.3 Angle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.4 Position . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

4 Black box modelling 10


4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.2 Angular velocity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.2.1 Control of the DC Motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.3 Angle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.3.1 Control of the angle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.4 Position . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5 Outside loop controller 16
5.1 PD Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.1.1 Without a controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.2 Phase lead controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.2.1 Theoretical design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.2.2 Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
5.2.3 Discretization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
5.2.4 Difference equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
5.2.5 Sampling time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
5.2.6 In practice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
5.3 Final results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
5.4 Bonus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
5.4.1 Real time regulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
5.4.2 Sinusoidal input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

6 Conclusion 25
6.1 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

7 Appendix 26
Introduction
1
1.1 Introduction

This report provides a detailed overview of what has been done during the laboratory sessions.
The goal was to analyse and control a plant, considering some requirements and specifications,
with a model-based approach. The studied plant is a ball and beam problem, where the position
of the ball has to be regulated. This system can be divided into subsystems, each of which is thor-
oughly studied, modelled and validated with practical tests. At the end, a controller that meets the
specifications is presented, as well as some possible points of improvements.

1
2
Plant

2.1 Plant description

The project deals with a problem known as the ball and beam system.

Figure 2.1: Real plant

A ball is placed along a gutter, and its position can be influenced by varying the angle of the gutter.
The beam is connected to a roller support at one end, and to a slider at the opposite end. This
slider is capable of vertical movement along a linear guide using a ball screw drive. The screw is
powered by a DC motor driven by a current. The ultimate goal of the lab is to maintain the ball at

2
CHAPTER 2. PLANT 3

any chosen position along the beam.

2.1.1 Static characteristic of the DC motor

A static characteristic refers to the relationship between the input and output of a system when
it is in a steady-state condition. In the context of a DC motor, the static characteristic shows a
deadzone, a region where a change in the input does not result in an immediate change in the
output. This deadzone is typically attributed to friction that needs to be overcome. Linearization
of this deadzone is therefor crucial to be able to linearize the system around a current of 0A.
The static characteristic of the DC motor was given, but the deadzone was still verified at the
beginning of each lab session, as this is a parameter that can change overtime. This deadzone
exists between −1.05A and 2.05A, which means the motor is not moving when I ∈ [−1.05, 2.05]. It
can be linearized by adding an offset depending on the output of the controller. If the output is
positive, u = û + 2.05, else u = û − 1.05 where û is the output of the controller and u is the current
sent to the plant.

Figure 2.2: Static characteristic of the DC motor


CHAPTER 2. PLANT 4

2.2 Instrumentation

The system has 3 sensors :

• a tachometer generator measuring the velocity of the DC motor

• a potentiometer measuring the angle of the beam

• an infrared distance sensor measuring the position of the small along the beam

The only actuator is the DC motor, which makes the slider move vertically. There is access to a
computer, whose link with the analog computer is already configured.

2.3 Specifications

The basic requirements state the the controller has to be able to stabilize the ball at any available
position. The more advanced requirements state that the controller should be able to

• Switch between two different points with a maximum of 1cm overshoot.

• Switch between two different points with a maximum of 0.5cm overshoot in maximum 10s

Note that it doesn’t specify the kind of reference to follow (step, ramp, etc), nor the difference in
distance between the start and end point.

2.4 Control

Cascade control was selected from the beginning. This control concept involves incorporating
loops to regulate intermediate variables that are accessible. Therefore, the controller will utilize
angular velocity and angle, rather than solely focusing on position. In principle, incorporating
more information is always advantageous.
Another benefit is that inner loops represent simple Single Input Single Output (SISO) systems,
thereby transforming a multivariable control problem into a series of SISO controls. These inner
loops should operate significantly faster than the outer loop, allowing them to be neglected to
simplify the control law design. It is a good thing that the outer loop can be slower, because the
choice of anti-aliasing filters is limited.
White box modelling
3
3.1 Introduction

White box modeling involves a detailed examination and analysis of the underlying electro-mechanical
equations governing the system dynamics. This approach seeks to derive the explicit mathemat-
ical relationships that describe the interactions within the system, and not just the relationship
between the input and output. The exact coefficients in these equations will never be exact due
to the inherent complexity of real-world systems. This complexity often implies necessary sim-
plifications to make the analysis easier. Despite the approximations, white box modeling offers
valuable insights by revealing the order of the system, including the number of zeros and poles,
which are important parameters.

3.2 Angular velocity

Finding a suitable equation that relates the motor current to its angular velocity is difficult due to
the complexity of the system. By making some assumptions, like neglecting the dynamic of the
velocity sensor, one can find a suitable equation representing the DC motor.
The relationship between the current (I ) and the angular velocity (ω) can be described by the
electro-mechanical equations of the motor.
The electrical equation :
di
V = I · Ra + L a + Kb · ω (3.1)
dt

Where :

• V is the applied voltage

• i is the armature current

5
CHAPTER 3. WHITE BOX MODELLING 6

• R a is the armature resistance

• L a is the armature inductance

• K b is the back emf constant

The mechanical equation :


T = Kt · i − B · ω (3.2)

Where :

• T is the motor torque

• K t is the motor torque constant

• B is the viscous friction coefficient

• ω is the angular velocity

Remembering that T = J · ddωt (J being the moment of inertia), the transfer function can be
derived by substituting some expressions and taking the Laplace transform :


J· = Kt · i − B · ω
dt
Laplace domain :

V (s) = I (s) · R a + L a · s · I (s) + K b · Ω(s)

J · s · Ω(s) = K t · I (s) − B · ω(s) (3.3)


Kt
⇔ Ω(s) = · I (s)
sJ +B
Kt
⇒ V (s) = I (s) · R a + L a · s · I (s) + K b · · I (s)
sJ +B
Ω(s) Kb · Kt
⇒ G 1 (s) = =
I (s) (s J + B )(R a · J · s + R a · B + L a · R a · s + L a · B

The transfer function contains two poles. However, the time constant associated with the electri-
cal part is way lower than the mechanical part, meaning that it is possible to simplify it to only one
pole.
CHAPTER 3. WHITE BOX MODELLING 7

Figure 3.1: Diagram of the system

3.3 Angle

In order to compute the relation between the angle and the angular velocity, some variables can
be defined :

• d : Horizontal distance between the vertical axis of the slider and the roller support

• α : Angle formed by the beam and horizontal axis

• L: Height of the slider

• V : Velocity of the slider

This derivation considers that d is constant, which is a relatively good approximation.

Starting with simple trigonometry :


L
tan(α) = (3.4)
d

Which can be approximated for small angle :

L L̇
tan(α) ≈ α, α= , α̇ = (3.5)
d d

Knowing that :

V = R ·ω (3.6)

V is the derivative of the position l :

V = L̇, L̇ = R · ω ⇒ α̇ · d = R · ω (3.7)
CHAPTER 3. WHITE BOX MODELLING 8

Taking Laplace transform :

Ω(s) R
s · A(s) · d = Ω(s) · R, A(s) = · (3.8)
s d

The second subsystem is a simple integrator.

3.4 Position

Figure 3.2: Diagram of the system

Lastly, an equation linking the angle of the beam to the position of the ball is needed. The ball
is subject to gravity : P = m · g .
Here are the variables needed for the derivation :

• a : Acceleration of the ball

• x : Position of the ball on the beam axis

• F : Externals forces

• α : Angle of the beam

Starting from Newton’s second law (the mass is constant) :

X
F =m·a
(3.9)
= m · ẍ
CHAPTER 3. WHITE BOX MODELLING 9

The only external force is the weight of the ball, so the vector projection of the weight vector gives
this :

m · g · sin(α) = m · ẍ
(3.10)
⇔ g · sin(α) = ẍ

Using the small angle approximation and the Laplace transform again :

α · g = ẍ

A(s) · g = X (s) · s 2 (3.11)


g
X (s) = A(s) ·
s2

The third subsystems is a double integrator.


Black box modelling
4
4.1 Introduction

This section discusses black box modeling, which was conducted concurrently with white box
characterizations. The black box approach offers the advantage of speed and reliability but re-
quires coupling with the white box method to provide a physical explanation of the order of the
system.
The concept behind this modeling technique involves introducing a step at the input of the sys-
tem being characterized to excite all frequencies. By analyzing the step response and utilizing a
provided script (not applicable for integrators), the transfer function of the system can be approx-
imated.

4.2 Angular velocity

The first system that needs to be characterized is the DC motor. Its input is the armature current of
the motor, and the output is the angular velocity of the motor. It is easy to send a step as the input,
as there is a direct access to the current being sent. This step should start close to the regulation
settings, meaning at equilibrium. The goal is to have a stable system, so the input starts at the edge
of the deadzone, while the beam is at 0° and the ball is not moving.
In order to find the transfer function, it is best that the system reaches stead state, meaning con-
stant angular velocity. This proved to be a problem, as for normal current, the slider reaches the
limit switch way before a constant angular velocity is reached. To make it a bit easier, only the steps
making the beam move up were considered, as gravity helps slow things down. This wasn’t enough,
so two additional options were considered : to reduce the current to the minimum, meaning there
would be lots of friction, or to start with a beam slightly below 0°. It was chosen to reduce the
current to barely over the deadzone current (i.e. the maximum current before the beam moves).

10
CHAPTER 4. BLACK BOX MODELLING 11

Ultimately, this design choice didn’t matter much, as the inner loops are way faster than the outer
loop, the last one being the bottleneck.
Based on this step response, the transfer function for the first system was approximated using the

Figure 4.1: Step response of the velocity

provided IdentifySystem.m script :


2.764
G 1 (s) = (4.1)
0.9675s + 1

Figure 4.2: Comparison between theoretical output and actual output of the motor velocity

All the comparison graphs in this report consist of three steps, where the simulated output
from the transfer function (same transfer function for the three) is compared against the actual
CHAPTER 4. BLACK BOX MODELLING 12

output of the plant for each step.


It is obvious that there are significant differences between the theoretical and the simulated out-
put. It was chosen to approximate it by a first order denominator, as the derivative at the origin
wasn’t equal to zero. Furthermore, the white box modelling shows that a DC motor can be approx-
imated by a first order transfer function. Also, this first loop is way faster than the outer loop, so it
doesn’t really matter.

4.2.1 Control of the DC Motor

For the second system, whose input is the output of this system, the step will be required at the
angular velocity which means that this system needs to be controlled. A simple proportional con-
troller was chosen, as it is enough to fully impose the position of the single pole. It can be seen on
the root locus that the system is stable for any positive gain, and that the response will be faster
the greater the gain (a response is faster the more negative the real part of the poles is). In cascade
control, the inner loops should be as fast as possible, so the gain should be as high as possible.
It was however limited by the saturation, and it was determined in Simulink that a gain around 4
would be a good trade-off.

Figure 4.3: Root locus of G 1 (s)

4.3 Angle

The input of the second system is the angular velocity of the motor, and its output is the angle of
the beam. The starting position are the same as before (beam at 0°, angular velocity = 0 rad/s), the
difference being that the step is now the reference for the proportional controller controlling the
first subsystem.
CHAPTER 4. BLACK BOX MODELLING 13

Figure 4.4: Step response of the angle

It was found to be a simple integrator, just like the white box predicted it.

1.6547
G 2 (s) = (4.2)
s

Figure 4.5: Comparison between theoretical output and actual output of the beam angle

This time, the theoretical and actual output were much closer. Note that the input is not a
perfect step, but it doesn’t matter as this only affects the angle for a brief period, as it is a good
approximation of a step after half a second.
CHAPTER 4. BLACK BOX MODELLING 14

4.3.1 Control of the angle

For the same reason as for the DC motor, this system needs to be controlled before finding the third
transfer function. Again, the root locus shows that the system is stable for any strictly positive gain.
In Simulink, a gain of 6 was found to be a good tradeoff between speed and saturation.

Figure 4.6: Root locus of G 2 (s)

4.4 Position

The input of the last system is the angle of the beam, and its output is the position, which is the
signal that is eventually controlled. In this case, it would be optimal to start the experiment with
the ball in the middle of the beam, but it wasn’t possible as it required a controlled system. It was
decided that the ball would start furthest from the position sensor, so that for a positive step, the
ball would have to travel the whole beam before colliding and bouncing back. The amplitude of
the step has to not be too low, as the ball might not even move and friction would not be negligible.
It cannot be too high either, else the rise time of the angle step would not be negligible.
The transfer function was found to be a double integrator (like the white box moddeling pre-
dicted), but with a significant delay. This delay is probably due to friction stopping the ball from
moving before a certain angle (the ball sticks to one end of the beam), added to the fact that the
beam angle step takes some time to rise.

9 −0.4s
G 3 (s) = ·e (4.3)
s2
CHAPTER 4. BLACK BOX MODELLING 15

Figure 4.7: Step response of the position

Figure 4.8: Comparison between theoretical output and actual output of the ball position
Outside loop controller
5
5.1 PD Controller

Now that all the transfer functions have been found, and the inner loops have been controlled, it
is time to control the outer loop. The first idea was to use a PD controller. The proportional action
forces the position error to tend to zero, while the derivative action forces the speed to tend to zero
(stabilizing effect). This derivative action is particularly good when there are delays, which is the
case in this plant. A PD controller has been designed, and worked in simulation, but it didn’t in
practice. The next idea was to add a filter pole, to make a phase lead controller.

5.1.1 Without a controller

The Bode plot of G 3 (s) shows that while the low frequency gain is high (for a good reference track-
ing), and the high frequency gain is low (for a good attenuation of noise), the phase is lower than
-180° at any frequency, which means that it is unstable. This system needs a greater phase, to
achieve a sufficiently high phase margin. This is why a phase lead controller was chosen, whose
equation is :
1 + sT
C (s) = k c (5.1)
1 + sT α

5.2 Phase lead controller

5.2.1 Theoretical design

A good starting point are the specifications. The settling time is t s = 10s, and the overshoot is
1cm
Mp = 5cm = 20%. The value 5cm was arbitrarily chosen. Knowing the relationship between the

16
CHAPTER 5. OUTSIDE LOOP CONTROLLER 17

Figure 5.1: Bodeplot of G 3 (s)

overshoot and the damping factor ϵ, one can compute ϵ and the phase margin :

p−πϵ
M p = e 1−ϵ2
p π 2
µ ¶
⇔ϵ= 1 + 1 = 0.59 (5.2)
ln M p

P M ≈ 100◦ · ϵ = 60◦

It was decided that the point with the highest phase will be the frequency for which the gain equals
1
0 dB, to have the best phase margin. In other words, |C ( j ωc )G( j ωc )| = 1 where ωc = p
T α
for a
phase lead controller. It is possible to derive α, which represents the spacing between the zero and
the pole, from the maximal phase given by the controller :

φmax = 60◦
1−α
tan φmax = p (5.3)
2 α
⇔ α = 0.072

It was decided out of good practice to have a gain margin of 6 dB for the open loop OL( j ω):

9 · k c 1 + sT
OL(s) = ·
s 2 1 + sT α
G M = 6d B ⇔ |OL( j ω180◦ )| = 6d B, Ar g (OL( j ω180◦ )) = −180◦ (5.4)
∂Ar g (OL( j ω))
= 0 for ωc , |OL( j ωc )| = 0d B
∂ω
CHAPTER 5. OUTSIDE LOOP CONTROLLER 18

Translating this into equation :

1
ωc = p
T α
s
kc 1
|OL( j ωc )| = 1 ⇔ p · 9T 2 α = 1 ⇔ T = p
α 9k c α
(5.5)
Arg(OL( j ω180◦ )) = −180 ⇔ −0.4 · ω180◦ + Arg(1 + j ω180◦ T ) − Arg(1 + j ω180◦ T α) = −180
£ ¤

⇔ −180 − 0.4 · ω180◦ + tan−1 (ω180◦ T ) − tan−1 (ω180◦ T α) = −180


9 |1 + j ω180◦ T |
|OL( j ω180◦ )| = 0.5 = · k c ·
ω2 |1 + j ω180◦ αT |

In order to solve those equations to find T and k c , an optimization script (cf Appendix) was
developed. It minimizes Ar g (OL( j ω180◦ )) + 180◦ and G M − 6d B (as fminsearch only solves for a
solution equal to zero). It found these values for the phase lead/PD with filtering pole :

Phase lead PD with filtering pole

k c = 0.0531 K d = 0.0531
(5.6)
T = 2.7936 k p = 0.4752

α = 0.0718 T f = 0.2006

The resulting open loop bodeplot shows a gain margin of 6.02d B , and a phase margin of 29.4◦ .
The phase margin is lower than expected due to delay, which prevents one of saying that the phase
margin is the maximum phase of the controller. This phase margin was accepted, as trying to
make it bigger would mean either more measuring noise (α would need to be even smaller), either
a lower bandwidth (T would need to be greater). It is possible to derive the closed loop C L( j ω),
neglecting any filter dynamic :
OL(s)
C L(s) = (5.7)
1 + OL(s)

The corresponding bodeplot gives a cutoff frequency ωc = 3.33r ad /s.

5.2.2 Simulation

The simulation of this controller gave promising results, but it wouldn’t quite reach the specifica-
tions in practice. Note that a ZOH was omitted from the system for simplicity, as the delay of G 3 (s)
of 0.4s was an order of magnitude higher than any sampling delay. A saturation block was added,
to replicate the hard limit on the current sent to the motor.
CHAPTER 5. OUTSIDE LOOP CONTROLLER 19

Figure 5.2: Bodeplot of OL(s)

Figure 5.3: Bodeplot of CL(s)

Figure 5.4: Complete Simulink scheme


CHAPTER 5. OUTSIDE LOOP CONTROLLER 20

Figure 5.5: Simulation result for a 1V step

5.2.3 Discretization

In order to discretize the controller, Tustin’s approximation was used. With this technique, one
can say that if the continuous time controller C (s) is stable, its discretized version C (z) will also be
locally stable. The script to go from one to the other is in the Appendix.

5.2.4 Difference equation

This is the form of the discrete controller :

az − b
C (z) =
z −c (5.8)
az − b
⇔ U (z) = E (z)
z −c

Where U (z) is the output of the outer loop, and E (z) is the position error. The difference equa-
tion can be easily derived, and was implemented in the real time script.

az − b
U (z) = E (z)
z −c
⇔ U (z + 1) − c ·U (z) = a · E (z + 1) − b · E (z) (5.9)

⇔ U (z) = a · E (z) − b · E (z − 1) + c ·U (z − 1)

5.2.5 Sampling time

The available anti-aliasing filters are as follows :

• two filters with f c = 100H z


CHAPTER 5. OUTSIDE LOOP CONTROLLER 21

• two filters with f c = 40H z

• two filters with f c = 20H z

• two filters with f c = 10H z

It is obvious that a higher sampling frequency yields better results, and in order to avoid alias-
ing, the sampling frequency must be more than twice the cutoff frequency (technically way more
as the attenuation isn’t sufficient at the cutoff frequency). At the beginning, the three first fil-
ters were used, with a sampling frequency of T s = 0.005s meaning 200 Hz. However, when doing
the conversion from cm to volts and vice versa, it started to take too much time and the com-
puter was lagging behind (the conversion was needed to get the position error plot in centime-
ters). The sampling period was reduced to T s = 0.01s, and the chosen filters were as follows :
2 × f c = 40H z, 1 × f c = 20H z. The performance remained unchanged, as the delay of G 3 (s) is way
higher than the sampling time.

5.2.6 In practice

As the reference tracking with the theoretical values wasn’t quite meeting the specifications, fur-
ther hand tuning was done. It was observed that a higher K p meant a slightly faster response (the
settling time was mainly limited by the imposed saturation of the sensors), and meant more over-
shoot but helped to reduce the initial static error. In theory, there shouldn’t be any static error as
the outer loop system is a double integrator. However the static characteristic is not unique de-
pending on the position of the ball.
Increasing K d on the other hand made the system stable earlier, but slowed it a bit.
As previously mentioned, forced saturation of the motor was introduced, where the output current
was limited to I ∈ [−4, 7]A.
The final values for the controller were :

• K p = 0.1

• K d = 0.15

• T f = 0.1

5.3 Final results

While it exceeds by far the specifications, it is interesting to note that the results showed a signif-
icant static error when the reference was above 35 cm. It is probably a result of the linearization
CHAPTER 5. OUTSIDE LOOP CONTROLLER 22

Figure 5.6: Output of the plant for a step reference

Figure 5.7: Output of the plant for different steps

(the ball was always going straight to the sensor, and not going away from it), and also the sensor
noise at high distance.
One hypothesis was that the step was too high, so it was tried in two smaller consecutive steps and
still didn’t work.
It is easy to notice that there is a lot of noise in the output, even when the reference is constant
and reached. Several techniques were tried, such as readjusting the deadzones and adding a min-
CHAPTER 5. OUTSIDE LOOP CONTROLLER 23

Figure 5.8: Output of the plant for two consecutive steps, trying to reach 45cm

imal error below which there is no input, but those fixes eventually lead to worse performance.
The issue lied probably in the inner loop : reducing the inner loop gain of the first system lead to
way less output noise overall. Unfortunately, the plant stopped working that day, but it still can be
seen that the noise is way lower. It could also maybe explain why positions above 35cm weren’t
reachable, as those were reached easily after the inner loop gain was reduced.

Figure 5.9: Output of the plant with lower noise


CHAPTER 5. OUTSIDE LOOP CONTROLLER 24

5.4 Bonus

5.4.1 Real time regulation

Real time regulation was tried, where the reference is set by a human. The signal of a potentiometer
is scaled down by another potentiometer to be in the 0-10V range. It is then acquired by the analog
computer, just like the other signals. It allows for a relatively precise control of the plant. It worked
really well when the position was below 35cm. Unfortunately, the data of these experiments was
lost, and the plant stopped working before new tests could be conducted.

5.4.2 Sinusoidal input

A sinusoidal input was first simulated in Simulink, then tested on the system. While the closed
loop using the practical values for the controller give a ωc = 2.92r ad /s, suggesting that a sinusoidal
reference will be correctly followed up to that frequency, it was found experimentally that it was
the case up to f = 0.1H z, or ω = 0.63r ad /s.

Figure 5.10: Sinusoidal reference at f = 0.05H z


Conclusion
6
6.1 Conclusion

This report presents a comprehensive overview of the theoretical analysis and practical tests con-
ducted during the laboratory sessions. A deep analysis of the plant was conducted, starting with
the static characteristic of the DC motor. Its deadzone was verified and the static characteristic
was linearized. The system was divided into subsystems, each undergoing thorough study, mod-
eling, and validation through practical tests.

The transfer functions were determined using a black box approach, with comparisons made
to white box derivations. The rationale behind opting for cascade control was explained, mainly
because it mitigates the impact of linearizing the plant and allows to work with SISO systems. Dis-
cussions on proportional controllers for the inner loops were held, and a detailed examination of
the main controller was conducted.

The selection of a phase lead controller was explored, with analytical determination and prac-
tical refinement of the parameters. Testing with step references revealed satisfactory performance,
particularly when the requested position wasn’t too far from the sensor. The observed high output
noise and potential issues with the system’s response to distant position requests could possibly
have been addressed by reducing the inner loop gain. Unfortunately, the plant ceased to function
before a thorough exploration of this solution could be undertaken.

Various additional references, such as manual control and a sinusoidal reference, were tested
and found to be effective. In summary, the report concludes that accurate control of the ball’s
position on the beam was achieved.

25
7
Appendix

Listing 7.1: Conversion between volts and cm

%% Code used to convert volts to cm and vice versa

%% by approximating the given static characteristic

xs = 10 * [86/123 124/123 251/123 436/123 734/123];

ys = [9+43/53 7+32/53 5+22/53 3+15/53 28/56];

p_cm_to_volts = polyfit(xs, ys, 3);

p_volts_to_cm = polyfit(ys, xs, 3);

x1 = linspace(0, 60, 1000);

plot(x1, polyval(p_cm_to_volts, x1))

Listing 7.2: Discretization of the controller

Kp = 0.1;

Kd = 0.15;

Tf = 0.1;

Ts = 0.01;

C = tf(Kp, 1) + Kd * tf([1 0], [Tf 1]);

c2d(C, Ts, 'tustin')

Listing 7.3: Code to compute the controller

% Alpha

phi = @(a) atan((1−a)/(2*sqrt(a))) − 60*pi/180;

alpha = fzero(phi, 0.07);

26
CHAPTER 7. APPENDIX 27

% relation between T and kc

T = @(kc) sqrt(1/(9*kc*sqrt(alpha)));

% Argument of OL, −180 degrees

arg_OL = @(kc, omega) −0.4*omega + atan(omega*T(kc)) − atan(omega*T(kc)*alpha);

% Gain margin, −6 dB = 0.5

GM = @(kc, omega) (9/(omega^2))*kc*sqrt(1+(omega*T(kc))^2)/sqrt(1+(omega*alpha*

T(kc))^2) − 0.5;

% Function to solve

to_solve = @(x) arg_OL(x(1), x(2))^2 + GM(x(1), x(2))^2;

result = fminsearch(to_solve, [0.01, 1]);

kc = result(1);

omega = result(2);

alpha_found = alpha;

T_found = T(kc);

Kd = kc; % 0.0531

Tf = T_found * alpha; % 0.2006

Kp = (T_found − 1) * kc / (alpha * T_found); % 0.4752

Listing 7.4: Real time control code

%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Setup

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

openinout; %Open the ports of the analog computer.

Ts=0.01;%Set the sampling time.

lengthExp=20; %Set the length of the experiment (in seconds).

N0=lengthExp/Ts; %Compute the number of points to save the datas.


CHAPTER 7. APPENDIX 28

Data=zeros(N0,3); %Vector saving the datas. If there are several datas to save,

change "1" to the number of outputs.

DataCommands= zeros(lengthExp /Ts, 1)'; %Vector storing the input sent to the

plant.

% position reference (cm)

stable = 7;

first_step = 25;

second_step = 45.00;

step_in = [stable * ones(2/Ts, 1)' first_step * ones(8/Ts, 1)' second_step *

ones(8/Ts, 1)' stable * ones(2/Ts, 1)'];

cond=1; %Set the condition variable to 1.

i=1; %Set the counter to 1.

tic %Begins the first strike of the clock.

time=0:Ts:(N0−1)*Ts; %Vector saving the time steps.

%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Loop

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

prev_velocity = 0;

prev_angle = 0;

prev_position = stable;

prev_position_error = 0;

prev_position_output = 0;

Kp1 = 4;

Kp2 = 6;

Kp3 = 0.05;

Kd3 = 0.1;

min_position_err = 0.02; % in volts


CHAPTER 7. APPENDIX 29

min_output = 0.2;

u0 = 0;

positions_error = zeros(lengthExp /Ts, 1);

output_positions = zeros(lengthExp /Ts, 1);

delta_errors = zeros(lengthExp /Ts, 1);

while cond==1

% input=DataCommands(i); %Input of the system.

error_position = polyval(p_cm_to_volts, step_in(i)) − prev_position;

error_position_cm = step_in(i) − polyval(p_volts_to_cm, prev_position);

output_position = 1.509 * error_position − 1.501 * prev_position_error +

0.9048 * prev_position_output;

error_angle = output_position − prev_angle;

output_angle = Kp2 * error_angle;

error_velocity = output_angle − prev_velocity;

output_velocity = Kp1 * error_velocity;

% Linearizing the static characteristic

if output_velocity > min_output

u0 = 2.0;

elseif output_velocity < −min_output

u0 = −1.05;

else

u0 = 0;

end

output = output_velocity + u0;

% Adding saturation

if output > 7
CHAPTER 7. APPENDIX 30

output = 7;

elseif output < −4

output = −4;

end

DataCommands(i, 1) = output;

anaout(output,0); %Command to send the input to the analog computer.

[in1,in2,in3]=anain; %Acquisition of the measurements.

Data(i, :)=[in1,in2,in3]; %Save one of the measurements (in1).

prev_velocity = in1;

prev_angle = in2;

prev_position = in3;

prev_position_error = error_position;

prev_position_output = output_position;

% Debug

positions_error(i) = error_position_cm;

output_positions(i) = output_position;

t=toc; %Second strike of the clock.

if t>i*Ts

disp('Sampling time too small');%Test if the sampling time is too small

else

while toc<=i*Ts %Does nothing until the second strike of the clock

reaches the sampling time set.

end

end

if i==N0 %Stop condition.

cond=0;

end

i=i+1;
CHAPTER 7. APPENDIX 31

end

%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Plots

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

closeinout %Close the ports.

% save stuff

save("data5/regulation_example.mat");

figure

hold on;

plot(time, step_in);

plot(time, DataCommands(:, 1));

plot(time, Data(:,1));

plot(time, Data(:,2));

plot(time, polyval(p_volts_to_cm, Data(:,3)));

plot(time, positions_error);

legend('Reference position (cm)', 'Calculated output (1V = 1A)', 'Motor

velocity (1V = 300 RPM)', 'Beam angle (1V = 3 degree)', 'Ball position (cm)

', 'Position error (cm)');

You might also like