Embedded Control Laboratory
Ball on inclined plane
                    Report of lab exercise 2
WS 2017/18
Group 04
1454316            Jigar Malani
1454390            Hiren Patel
1449996            Pratik Sondkar
Date: 07.12.2018
                                               1
# Exercise 2:
1) Create a Xcos model and consider the following points and questions
   •   Build a subsystem for the ball on inclined plane model (BoiP) with Xcos blocks. Find
       the position x as the output from angle 𝛽 as the input (Refer to Exercise 1).
   •   Create a closed loop according to Figure 1.
   •   Simulate the closed‐loop control:
           ▪ With start position 1.0 and reference value 0.0 (midpoint of the plane).
           ▪ With start position ‐1.0 and reference value 0.0 (midpoint of the plane).
   •   Tune the parameters in the PID block. Start with P=0.7, I=0.2 and D=0.4. Indications
       of a good tuning result include:
           ▪ Short rising time
           ▪ Small or no overshoot
           ▪ Short settling time
           ▪ No steady‐state error of the system response.
2) Replace the continuous PID block with a discrete PID block using state variables. To
implement the discrete PID controller
   •   Use DLR blocks in “Discrete time systems” to form transfer functions in Z‐domain.
   •   Use a “Sampling and hold” block to sample your signals at specified time stamps.
   •   A simple low‐pass filter can be used to reduce the noise of the derivative term.
3.) Questions:
   •   What are the expected responses of the controlled system when P, I, and D‐controllers
       are individually tuned?
   •   Why is it important to limit the input signal (angle 𝛽) to the controlled system? How
       can it be done? What should be the limitation?
   •   Why and where do you use limited integrals in the controlled system? What are the
       limits?
   •   Add a jumping reference for the system that randomly picks a new reference value from
       [0.3; 0.5; 0.7] and [‐0.3; ‐0.5; ‐0.7] every 10s alternatively. An example may be [0.3; ‐
       0.5; 0.7; ‐0.3; 0.5; ‐0.3; ……]. Plot the desired ball positions and the actual ball
       positions for 10 jumps. What time period makes sense for the simulation interval? Can
       the system keep up? Why and why not?
                                                                                              2
                                                        Table of Contents
1     Objective ..............................................................................................................................
2     Introduction on PID Controller ...................................................................................... 5
    2.1      Closed Loop System ............................................................................................................... 5
    2.2      PID Control ............................................................................................................................. 6
    2.3      Parameters Involved................................................................................................................ 8
3     Criterion and Stipulations ............................................................................................... 9
4     BOIP Super Block .......................................................................................................... 10
    4.1      C1 Super Block ..................................................................................................................... 11
    4.2      Gamma1 Super Block ........................................................................................................... 11
    4.3      Alpha Super Block ................................................................................................................ 12
    4.4     Alpha1 Super Block ....………………………………………………………………………………………………………13
    4.5     Beta2 Super Block ……………………………………………………………………………………………………………13
    4.6      Position Super Block............................................................................................................. 14
5     Discrete System ............................................................................................................... 14
    5.1      PID Super Block ................................................................................................................... 14
    5.2      Discrete System Output ........................................................................................................ 15
6     Discrete Jumping Reference .......................................................................................... 17
7     Statement 1 ...................................................................................................................... 18
8     Statement 2 ...................................................................................................................... 18
                                                                                                                                                      3
List of figures
 Sr. No.   Description                                                        Page No.
    1      Typical Closed Loop System                                         5
    2      Algorithm of a PID Control System                                  6
    3      Response of a typical PID closed loop system                       8
    4      BOIP Super Block                                                   10
    5      C1 Super Block                                                     11
    6      γ1 Super Block                                                     11
    7      α Super Block case 1                                               12
    8      α Super Block case 2                                               12
    9      α1 Super Block                                                     13
   10      β2Super Block                                                      13
   11      Position Super Block                                               14
   12      BOIP Discrete System-XCOS                                          14
   13      PID controller Super Block                                         15
   14      Output Response of PID for Initial Set Values                      15
   15      Output Response of PID for Final Iterated Value                    16
   16      Discrete Jumping Reference                                         16
   17      Output Response of Discrete Jumping PID for Final Iterated Value   17
List of Tables
 Sr. No.   Description                                                        Page No.
 1         Impact of Kp ,Ki ,Kd on Parameters                                 9
 2         Given Constant Parameters                                          9
 3         Iterated Values based on Parameters involved                       16
                                                                                         4
1   Objective
This document mainly focuses on how to Build systems and subsystems with SCILAB/Xcos
by creating a new model window and adding function blocks with input and output signals and
a specific behaviour from the different libraries with different functions such as Math
Operations, Time continuous systems, scopes and constants. Also, it deals with how to create
our own discrete PID controller with the following conditions.
    •   To Create a Closed loop with a discrete PID block using state variables, by
        implementing the discrete function of a PID Controller.
           ▪ Sampling and hold blocks to sample the signals at specified time stamp.
           ▪ Simple Low pass filter to reduce noise of derivative term.
    •   To build a subsystem for BOIP.
    •   To simulate the closed loop control with start position ±1.0 and reference value of 0.0.
    •   To find out good working parameters for PID controller.
2   Introduction on PID Controller
The basic idea behind a PID controller is to read a sensor, then compute the desired actuator
output by calculating proportional, integral, and derivative responses and summing those three
components to compute the output. Before we start to define the parameters of a PID controller,
we shall see what a closed loop system is and some of the terminologies associated with it.
2.1 Closed Loop System
Control system in which the output has an effect on the input quantity in such a manner that
the input quantity will adjust itself based on the output generated is called closed loop control
system. Open loop control system can be converted in to closed loop control system by
providing a feedback. This feedback automatically makes the suitable changes in the output
due to external disturbance. In this way closed loop control system is called automatic control
system. Figure below shows the block diagram of closed loop control system in which feedback
is taken from output and fed in to input.
                             Figure 1: Typical Closed Loop System
                                                                                               5
A feedback is a common and powerful tool when designing a control system. Feedback loop
is the tool which take the system output into consideration and enables the system to adjust its
performance to meet a desired result of system.
In any control system, output is affected due to change in environmental condition or any kind
of disturbance. So one signal is taken from output and is fed back to the input. This signal is
compared with reference input and then error signal is generated. This error signal is applied
to controller and output is corrected. Such a system is called feedback system. When feedback
signal is positive then system called positive feedback system. For positive feedback system,
the error signal is the addition of reference input signal and feedback signal. When feedback
signal is negative then system is called negative feedback system. For negative feedback
system, the error signal is given by difference of reference input signal and feedback signal.
2.2 PID Control
The PID circuit is often utilized as a control loop feedback controller and is very commonly
used for many forms of servo circuits. The letters making up the acronym PID correspond to
Proportional (P), Integral (I), and Derivative (D), which represents the three control settings of
a PID circuit. The purpose of any servo circuit is to hold the system at a predetermined value
(set point) for long periods of time. The PID circuit actively controls the system so as to hold
it at the set point by generating an error signal that is essentially the difference between the set
point and the current value.
The three controls relate to the time-dependent error signal; at its simplest, this can be thought
of as follows: Proportional is dependent upon the present error, Integral is dependent upon the
accumulation of past error, and Derivative is the prediction of future error. The results of each
of the controls are then fed into a weighted sum, which then adjusts the output of the circuit,
u(t). This output is fed into a control device, its value is fed back into the circuit, and the process
is allowed to actively stabilize the circuit’s output to reach and hold at the set point value. The
block diagram below illustrates very simply the action of a PID circuit. One or more of the
controls can be utilized in any servo circuit depending on system demand and requirement (i.e.,
P, I, PI, PD, or PID).
                           Figure 2: Algorithm of a PID Control System
                                                                                                     6
Through proper setting of the controls in a PID circuit, relatively quick response with minimal
overshoot (passing the set point value) and ringing (oscillation about the set point value) can
be achieved.
The output of the PID control circuit, u(t), is given as
where
Kp= Proportional Gain
Ki = Integral Gain
Kd = Derivative Gain
Error Signal e(t) = Set Point (SP) – Process Variable (PV(t))
From here we can define the control units through their mathematical definition and discuss
each in a little more detail. Proportional control is proportional to the error signal; as such, it is
a direct response to the error signal generated by the circuit:
Larger proportional gain results is larger changes in response to the error, and thus affects the
speed at which the controller can respond to changes in the system. While a high proportional
gain can cause a circuit to respond swiftly, too high a value can cause oscillations about the SP
value. Too low a value and the circuit cannot efficiently respond to changes in the system.
Integral control goes a step further than proportional gain, as it is proportional to not just the
magnitude of the error signal but also the duration of the error.
Integral control is highly effective at increasing the response time of a circuit along with
eliminating the steady-state error associated with purely proportional control. In essence
integral control sums over the previous error, which was not corrected, and then multiplies that
error by Ki to produce the integral response. Thus, for even small sustained error, a large
aggregated integral response can be realized. However, due to the fast response of integral
control, high gain values can cause significant overshoot of the SP value and lead to oscillation
and instability. Too low and the circuit will be significantly slower in responding to changes in
the system.
                                                                                                    7
Derivative control attempts to reduce the overshoot and ringing potential from proportional
and integral control. It determines how quickly the circuit is changing over time (by looking at
the derivative of the error signal) and multiplies it by Kd to produce the derivative response.
Unlike proportional and integral control, derivative control will slow the response of the circuit.
In doing so, it is able to partially compensate for the overshoot as well as damp out any
oscillations caused by integral and proportional control. High gain values cause the circuit to
respond very slowly and can leave one susceptible to noise and high frequency oscillation (as
the circuit becomes too slow to respond quickly). Too low and the circuit is prone to
overshooting the SP value. However, in some cases overshooting the SP value by any
significant amount must be avoided and thus a higher derivative gain (along with lower
proportional gain) can be used.
2.3 Parameters Involved
Some of the important parameters involved in the PID System are as follows.
Rise Time is the amount of time the system takes to go from 10% to 90% of the steady-state,
or final, value. Percent Overshoot is the amount that the process variable overshoots the final
value, expressed as a percentage of the final value. Settling time is the time required for the
process variable to settle to within a certain percentage (commonly 5%) of the final value.
Steady-State Error is the final difference between the process variable and set point.
                     Figure 3: Response of a typical PID closed loop system
The table below explains the effects of increasing the gain of any one of the parameters
independently.
                                                                                                 8
    Parameter        Rise Time      Overshoot          Settling     Steady-State     Stability
    Increased                                           Time           Error
          KP         Decrease         Increase          Small        Decrease         Degrade
                                                       Change
          KI         Decrease         Increase         Increase       Decrease        Degrade
                                                                    Significantly
          KD          Minor            Minor            Minor        No Effect      Improve (for
                     Decrease         Decrease         Decrease                      small Kd)
                           Table 1: Impact of Kp ,Ki ,Kd on Parameters
3     Criterion and Stipulations
The Table 2 shows all the constants of the Mathematical Model.
 Symbol                            Description                            Value         SCILAB
                                                                                         Value
      D        horizontal distance between the centre of inclined        105 mm         105 e-3
                              plane and servo motor
      H         vertical distance between the centre of inclined          19 mm          19 e-3
                              plane and servo motor
    l = a2              half the length of inclined plane                 118.72       118.72 e-3
    r = a1                 length of servo motor arm                      18 mm          18 e-3
    c = b2                   length of the black rod                    36.22 mm       36.22 e-3
                               Table 2: Given Constant Parameters
hk = 17 mm
lk = 117.5 mm
γ = tan-1 (h/d) = tan-1 (19/105) = 10.25˚
δ = tan-1 (hk/ Ik) = tan-1(17/117.5) = 8.23˚
b1 = √ (d2 + h2) = √ (1052 + 192) = 106.70 mm
Also we know, a = (5/7) . g .sinα
x = ʃ v . dt = ʃʃ a . dt2 = (5/7). g . sinα . t2 + C
The maximum roll time of the ball is given by next formula with angle α at maximum value
i.e. ± 10 degrees. Acceleration and Speed at start time are both zero, so the integration
constant C is zero.
                                                                                                 9
∴ 2* l = (5/14) . g . sinα . tmax2
∴ tmax = √ ((28 * l)/(5 * g * sinα))
Maximum velocity can be calculated by putting value of maximum time i.e. tmax.
Vmax = (5/7). g . sinα . tmax
Vmax ≈ 1.12 m/s.
Also from data provided, we know
Case1: When angle β is greater than angle – γ
α = α1 + β2 - δ – γ
γ1 = π - β - γ
Case 2: When angle β is lesser than angle – γ
α = α1 - β2 + δ + γ
γ1 = π - β + γ
Note: Here, we have considered only the magnitude of β and α but not the direction.
4    BOIP Super Block
The BOIP is modelled by using the XCOS, which consists of all the constants as shown in the
Section 3. The equations which includes these constants are represented in the form of blocks
as shown in the Figure 4.
                                     Figure 4: BOIP Super Block
                                                                                          10
4.1 C1 Super Block
                         Figure 5: C1 Super Block
4.2 Gamma1 Super Block
                         Figure 6: γ1 Super Block
                                                    11
4.3 Alpha Super Block
Case 1: When angle β is greater than angle – γ
                                 Figure 7: α Super Block case1
Case 2: When angle β is lesser than angle – γ
                                 Figure 8: α Super Block case 2
                                                                  12
4.4 α1 Super Block
                       Figure 9: α1 Super Block
4.5   β2 Super Block
                       Figure 10 : β2 Super Block
                                                    13
4.6 Position Super Block
                                 Figure 11: Position Super Block
5   Discrete System
                            Figure 12: BOIP Discrete System-XCOS
5.1 PID Super Block
A straightforward way to discretize this controller is to convert the integral and derivative terms
to their discrete-time counterpart. There are commonly 3 variations to do so, by means of
forward Euler, backward Euler, and trapezoidal methods. Among these we have considered
Backward Euler Equation for our model.
Integral Term
Where,
Ts is the Sampling Period
                                                                                                14
Derivative Filter
Where,
N is the Filter Co-efficient
An advantage of the Backward Euler method is that discretizing a stable continuous-time
system using this method always yields a stable discrete-time result. Any filter parameter
value N > 0 yields a stable result with this method.
                               Figure 13 : PID Controller Super Block
5.2 Discrete System Output
➢ Case 1: Initial Set values of P=0.7, I=0.2 and D=0.4
We have obtained the following results inputting the given values.
                    Figure 14 : Output Response of PID for Initial Set Values
                                                                                             15
➢ Case 2: Optimized Values of P, I, D
For arriving at the optimal values of PID Constants, various iterations have been carried and
the following table illustrates the changes in the system with respect to parameters involved
based on Section 2.3. Some of the important iterations are tabulated in the below table.
                Iteration    KP     KI     KD                  Observations
                    1       0.7     0.2    0.4        Settling time is very high (>10s)
                                                      Settling time is less compared to
                    2       0.8     0.3    0.5    previous iteration but we are observing a
                                                       relatively high steady state error
                                                      Settling time is around 7.5 s with
                    3       0.85    0.4    0.65
                                                      relatively small steady state error
                                                        Settling time is around 5 s with
                    4       0.85   0.55    0.55
                                                   relatively very small steady state error
                                                  Settling time is around 6s and overshoot
                    5       0.90    0.5    0.55
                                                         is same as previous iteration
                                                   Overshoot is less compared to previous
                    6       0.9    0.45    0.6
                                                    iterations, settling time is quite high
                    Table 3: Iterated Values based on Parameters involved
After Simulating different random values, it is evident from above table for the values Kp =
0.85, Ki =0.55 and Kd =0.55, the system is more stable and it takes to less time to settle down
when compared with other values. So, our BOIP system will use these working parameters.
The graph below depicts the output response of the above mentioned values.
                 Figure 15: Output Response of PID for Final Iterated Value
                                                                                              16
6   Discrete Jumping Reference
                         Figure 16: Discrete Jumping Reference
       Figure 17: Output Response of Discrete Jumping PID for Final Iterated Value
                                                                                     17
7    Statement 1
        Why and when do you use limited integrals? What are the saturations used?
The BOIP system uses integration in two stages (during the calculation of velocity and position
from acceleration). Limits of these integrations are defined by the angle α and the mechanically
predetermined length of the inclined plane. Since the total length of the plane is 0.23 m thus
the upper and lower limits for position will be +0.11872 and -0.11872 respectively. These limits
can be used in second integral block to get the position of the ball.
Maximum velocity of the ball can be found at α =±10, and starting position at one of the ends.
The limits for the velocity are upper limit = 1.12m/s and lower limit=-1.12 m/s. These integral
limits can be used to bound velocity at first integral block.
In order to include these limits, we mention it in the parameters of the integrator block in the
BOIP model.
β is saturated to the value of ±40 degrees. This can be modelled using saturation block with
upper limit as 40 degrees and lower limit as -40 degrees. The value of β needs to be saturated
as α is a linear function of β.
To prevent the output from exceeding specifiable levels, the Saturation function is selected and
the limits in the appropriate parameter fields are entered. This action causes the block to
function as a limited integrator. When the output reaches the limits, the integral action is turned
off to prevent integral wind up. The block determines output as follows: When the integral is
less than or equal to the Lower saturation limit, the output is held at the Lower saturation limit.
When the integral is between the Lower saturation limit and the Upper saturation limit, the
output is the integral. When the integral is greater than or equal to the Upper saturation limit,
the output is held at the Upper saturation limit.
8    Statement 2
          What time period makes sense for simulation interval?
Simulation Interval refers to the time interval between two consecutive computations. During
Simulation, the system has to compute values for infinite times. So, the simulation interval is
decided taking both time and accuracy into account. The settling time of our system with respect
to the reference value is in the range of around 5s. For observing if there are any changes or
error in the system, a simulation period of 10s with a time interval of 0.01s would be perfect as
it also allows more time to check if there are any further deviations from the desired position.
                                                                                                18