Docstoc

new Voltage

Document Sample
new Voltage Powered By Docstoc
					Table of Contents

Table of Figures.............................................................................. 1
Table of Tables ............................................................................... 1
1 Introduction ................................................................................. 2
2 Background ................................................................................. 2
  2.1 Direct Digital Controllers ......................................................................................... 3
  2.2 PID Controller ........................................................................................................... 3
  2.3 Cohen and Coon Tuning ........................................................................................... 5
  2.4 Dahlin and Kalman Z Controller .............................................................................. 6
3 Equipment ................................................................................... 6
4 Method ......................................................................................... 7
  4.1 D/A A/D Converter Calibration ................................................................................ 7
  4.2 Black Box Process Identification .............................................................................. 8
  4.3 PID Controller ........................................................................................................... 8
  4.4 Dahlin and Kalman Z Controller ............................................................................ 10
5 Results and Discussion ............................................................. 13
  5.1 D/A A/D Converter Calibration .............................................................................. 13
  5.2 Black Box Process Identification ............................................................................ 14
  5.3 PID Controller ......................................................................................................... 16
  5.4 Dahlin and Kalman Z Controller ............................................................................ 20
  5.5 PID Compared Against Z Controller ...................................................................... 27
6 Recommendations ..................................................................... 31
7 Conclusions ................................................................................ 32
8 References .................................................................................. 33
9 Appendix .................................................................................... 34
  9.1 Code Compilation ................................................................................................... 34
     9.1.1 Datatake.c Program ......................................................................................... 34
     9.1.2 PID.C Code ...................................................................................................... 39
     9.1.3 StepResponse.c Program ................................................................................. 41
  9.2 Z Transform Manual Calculations on Paper ........................................................... 46




                                                                                                                                0
Table of Figures
Figure 1: Direct Digital Controller Block Diagram [1] ...................................................... 3
Figure 2: PID Controller Block Diagram [2] ...................................................................... 4
Figure 3: PID Controller Equation (Basic) [1] ................................................................... 5
Figure 4: Cohen and Coon Tuning Tables [1] .................................................................... 5
Figure 5: Dahlin Controller Model Formula [3] ................................................................. 6
Figure 6: Step Response Transfer Function [4] .................................................................. 8
Figure 7: Velocity Equation (PID) [1] ................................................................................ 9
Figure 8: Delta MV [1] ....................................................................................................... 9
Figure 9: PID Controller Pseudo Code [1] ....................................................................... 10
Figure 10: Controller Equation [3] ................................................................................... 11
Figure 11: Hold Function (s domain) [4] .......................................................................... 11
Figure 12: Transfer Function (s domain) [1] .................................................................... 11
Figure 13: Specified System Performance [1] .................................................................. 11
Figure 14: Difference equation Transformation [1].......................................................... 12
Figure 15: Kalman Transformation Equation [4] ............................................................. 12
Figure 16: Sub-Step for Kalman Transformation [4] ....................................................... 12
Figure 17: Step Response Black Box................................................................................ 15
Figure 18: Step Response Modeling Example .................................................................. 16
Figure 19: PID Response with Tuning Parameters ........................................................... 17
Figure 20: Optimal Kc Tuning using ISE ......................................................................... 18
Figure 21: Optimal Tau D Tuning using ISE.................................................................... 18
Figure 22: Optimal Tau I Tuning using ISE ..................................................................... 19
Figure 23: PID System Response after Tuning................................................................. 20
Figure 24: One Second Sample Time Dahlin Controllers ................................................ 21
Figure 25: Five Second Sample Time Dahlin Controllers ................................................ 22
Figure 26: Eight Second Sample Time Dahlin Controllers .............................................. 23
Figure 27: Kalman Controller with One Second Sampling Time..................................... 24
Figure 28: Kalman Controller with Five Second Sampling Time .................................... 25
Figure 29: Kalman Controller with Eight Second Sampling Time................................... 26
Figure 30: Dahlin Disturbance Test .................................................................................. 28
Figure 31: Kalman Disturbance Test ................................................................................ 28
Figure 32: PID One Second Sample Time Disturbance Tests .......................................... 29
Figure 33: PID Controller with 8 second Sample Time and 2V Disturbance .................. 30
Figure 34: PID Controller with 5 second Sample Time and 2V disturbance ................... 30
Figure 35: PID Controller 0.5 Second Sample Time ........................................................ 31

Table of Tables
Table 1: Calibration Results using external and computer input to D/A Converter ......... 14
Table 2: Step Response Transfer Function Numbers ....................................................... 16
Table 3: Cohen and Coon Tuning Constants .................................................................... 16
Table 4: One Second Sample Time: Lamba vs. ISE ......................................................... 21


                                                                                                                              1
Table 5: Five Second Sample Time: Lamba vs. ISE ........................................................ 22
Table 6: Eight Second Sample Time: Lamba vs. ISE....................................................... 23
Table 7: Kalman Sample Times vs. ISE .......................................................................... 26


1 Introduction
        The direct digital controller is a pivotal part of control systems that utilize
technology to assist in monitoring control systems. The precision and absolute control
over digital controllers makes them far superior to analog controllers for a lot of modern
applications. The various aspects of a control system can now be implemented into one
central microcontroller for a cost effective approach to system control procedures. These
controllers have a vast array of applications ranging from industrial use, aircraft control,
power generation, chemical containment and mixing, to most control situations available
in modern society.

        For the purpose of the Digital Process Control Design lab the important aspects of
inspection are the implementation of a PID controller, which is the industry standard, the
process identification of a black box system (unknown components inside), and the
design of a Dahlin and Kalman Z Controller. The processes used in industry control
design and the knowledge from class are intended to be followed and applied to our
specific lab scenario to show how they work and give us an new perspective on
controlling systems digitally. For our purposes our controller would be created using a
computer, Digital to analog converter, and a black box (the actual system). The computer
would act as the control center that manages the black box system. The converter simply
acts as a link between the digital computer and the analog black box system. The system
will be simulated and tested by us to secure information on the black box system, as well
as instruct us on the advantages and disadvantages of the control systems to be designed.

        The important processes presented in this lab demonstration are that of designing
and tuning a system for various applications in the specific field of study. Different
applications are going to require different characteristics from the controllers they are
using. These characteristics, when kept constant moving between applications, will have
adverse effects on the manipulated system. The knowledge accumulated from the
processes this lab teaches is the most important part of tuning and designing systems and
will benefit us greatly in our endeavors within any area of system control work outside
our academia.

2 Background
        The digital processing control systems implemented in this lab begin with a basic
black box, or unknown component, system that needs to be identified. Generally systems
would be built at one point then a controller would be designed at a later point to make
the system functional for everyday use. The equipment calibration is a necessary step to
familiarize with the current system and ensure everything is working as it should be. For
our purposes a direct digital controller is being designed as the foundation for the future


                                                                                                                2
controller systems. The direct digital controller will be altered for each new sub system
that will be inserted. Once this base system is built, the PID and Z controllers can simply
be inserted into the controller block that controls the overall system. In the following
sub-sections of the background each aspect of the controller designs will be discussed in
further detail pertaining to initial setup information and some of the theory behind the
controllers used in this lab as well as processes used to tune the controllers.

2.1 Direct Digital Controllers

        The direct digital controller acts as a basis for the controllers that will be
implemented later in the lab. The basic idea of the system is that the computer monitors
the system, for our cases, as it relays data to and from the black box. A simple block
diagram depicting a sample layout of a direct digital controller can be seen in Figure 1
below.




                                           Figure 1: Direct Digital Controller Block Diagram [1]



The information to and from the computer is converted between analog and digital data
so that the respective equipment can read the proper values. The process variable is
constantly changing as the feedback control on the system adjusts the set point based
upon error readings from the process. This digital control process forms the skeleton for
the upcoming two controller types, PID controller and Z controller.

2.2 PID Controller




                                                                                              3
         The PID (Proportional Integral Derivative) Controller is the industry standard that
is fairly easy to implement and gives excellent results for a wide array of applications.
The PID controller is essentially comprised of three different systems to control various
aspects of a process. The intended function of the controller is to maintain a desired set
point using an error correction method. The feedback PID system is constantly passing
an error value back to the controller to process and adjust the system as necessary. The
block diagram in Figure 2 demonstrates a general PID feedback system to control a
process.




                                                    Figure 2: PID Controller Block Diagram [2]



The error is used in each of the three PID components to adjust the system based upon its
characteristics. The intended set point to be maintained subtracts the process variable
from itself to calculate the error. This deviation, after being passed through the PID
portion of the block diagram results in a tuning number to attempt to bring the set point
back to its desired position. The PID controller plays a large part in ensuring the process
and set point are controlled properly.
         To further understand the PID‟s involvement it is necessary to break down the
PID into three separate sections, similar to in Figure 1. The P, or Proportional, aspect of
the PID controller is used to strengthen the response and rise time of the system when it
initially starts. The P value, or Kp, is essentially a gain and is multiplied by the error to
help adjust the output, relative to the input (error). A simple Proportional (P) controller
can be utilized in some situations but it generally results in an offset between the desired
and actual value for the output. To reduce the impact of this error, an Integral aspect can
be added to the system. The integral component of the PID controller attempts to reduce
the aforementioned offset in values. By using the integral of the errors over time the
system can reduce steady state errors over periods of time to help the system settle on the
desired set point. Unfortunately this does not help the settling time of the system. To fix
the settling time and overshoot of a system, the Derivative term needs to be introduced.
The D control term helps to reduce the overshoot caused by the P controller and reduces


                                                                                            4
the settling time. The dynamic response is slightly affected by changing the D term.
These three aspects make the PID controller the complete function that it is, and help to
make tuning systems correspond to any applications that may be required. The resulting
basic PID equation can be described as in Figure 3 below.




                                 Figure 3: PID Controller Equation (Basic) [1]


         A more detailed explanation of a better PID equation to solve problems inherent
in this equation will be further discussed in the Method section of the report.

2.3 Cohen and Coon Tuning

        Tuning is an important part of the PID Controller process. Cohen and Coon
Tuning provides an estimate for the Kc, Taui, and Taud values, which are taken from the
gain, time constant and dead time. The later three variables will be discussed further in
the Method section as part of the process identification procedures.

         The Cohen and Coon tuning variables are taken from a pre-defined set of rules
that is necessary for all Cohen and Coon calculations. These rules can be observed in
Figure 4 below.




                                                   Figure 4: Cohen and Coon Tuning Tables [1]


       The Kc, Taui, and Taud values are the result of the three equations in the PID
row. In the equations D is the dead time, Tau is the time constant, and Kp is the gain,
which are found from the step response graph of the black box. These resulting tuning
parameters model a first order plus dead time system. These are by no means the optimal



                                                                                            5
performance settings but they give an excellent start position to avoid having to test a
massive array of values to find a decent system characteristic.

2.4 Dahlin and Kalman Z Controller

        Z transforms introduce a way to compensate for a long delay or dead time in the
process section of the controller. Using a first order plus dead time model at lower levels
of the system, then at higher levels more complex models a decent system response can
be obtained. The basic way to achieve a faster set point alteration in the event of a
sudden set point change is to use a dead beat controller. The dead beat controller
sacrifices control of the system, for the best possible response. In a lot of cases this is
unreasonable and a new method is needed. The Dahlin controller, which uses the first
order plus dead time model, will give more exacting control of the system, as the expense
of a slower system response. The Dahlin controller takes the form of the following
equation in Figure 5.




                                   Figure 5: Dahlin Controller Model Formula [3]


        These two models produce a lot of ringing in the initial stages of the system,
which can wear on a mechanical system. Kalman proposed a method where a best case
scenario system was found, and then the old system was compensated to reach that
scenario. The Kalman approach resulted in less ringing in the process variable, which
makes for a smoother transition in the process. Kalman‟s formula slightly modifies the
Z[H(s)G(s)] part of the Dahlin equation to make the slightly different system controller.
These two methods will be further discussed in the Method and Discussion sections of
the report where it will become clearer as to the purpose of these controllers.


3 Equipment
    There was a minimal amount of equipment required for this lab as most of the
computation was done through the computer to the black box system. The components
of the system are as follows:

      A/D and D/A Converter with 12 bit resolution
      Black Box System
      Computer with link to A/D box
      DC Power Supply
      Voltmeter
      Wires
      Potentiometer



                                                                                            6
A/D and D/A Converter

        The converter used was connected to the personal computer so data could be sent
to and from the computer and be converted properly for its designated source. The
converter contains only 12 bits as a part of its conversion ability. A maximum of 9 V and
a minimum of -10 V were used due to the resolution of the system. Values outside these
bounds could not be sent to the converter due to hardware and software restrictions.
More detailed information on the specifics of the converter can be found in the D/A
converter calibration section under method and results.

Black Box System and DC Power Supply


        The black box system was an unknown system that required a transfer function to
be extracted using calibrations and tests. A step response is used to extract vital
information about the black box‟s transfer function. The black box has inputs and
outputs so that various voltages can be applied to the system and produce a certain
output. The DC Power box supplied power to the black box system, through a -15V to
15V range, as well as a grounding output.

Voltmeter, Wires, Potentiometer and the PC

        These three components allow for interaction between the various system pieces
with the computer acting as a hub for information. The PC would run the compiled C
code in Visual Studios and execute it. The voltmeter was used to test various voltages at
inputs and outputs of the box, as well as monitor the process variable for the capacitance
to drain before starting the system. The potentiometer was used to measure minute steps
in voltage to test for a step size of the converter mentioned above. It allowed for a larger
voltage to be scaled down so that the user could move at computer sized intervals.


4 Method
4.1 D/A A/D Converter Calibration

        The D/A A/D converter needed to be tested for various inputs to assess how
accurate the resulting data was compared to the input data. Data could be sent from the
computer through one to two of the converters outputs or it could be sent in to the
computer from one to four inputs. For the purposes of the converter calibration two
different voltage input methods will be used. In one trial voltages from the computer will
be sent to the converter, and in the other trial voltages from a power supply will be sent to
the converter to test the tolerances. The computer output trial has a serial connection
running from the computer to the converter to send the necessary data. The converter
takes the digital data and manipulates it into analog data. The datatake.c program was
used to record all of the values of from the input and output connections on the converter


                                                                                           7
and display them on the screen. The datatake.c program can be found in the appendix
under Appendix 9.1.1 for specifics on how the computer interacted with the converter
box. The processes here are relatively simple but provide necessary information for
future work ensuring that data is within a low tolerance.

4.2 Black Box Process Identification

        The black box had an unknown configuration inside the enclosure that needed to
be analyzed in order to extract a transfer function for numerical interpretation. The setup
of the system was fairly simple in its design because only one input and one output
channel needed to be used. A step test was used to produce a response that could be
graphically interpreted. A step test is emulated by waiting for a specific amount of time
before sending a 1 V signal to the black box and plotting the output values obtained. The
setup of the system required only four wires. One wire went from an output on the
converter (Channel 0) to an input on the black box. A second wire went from the black
box output to a converter input (Channel 0). The third and fourth wires grounded the
converter and black box ports. To achieve the desired processes to make the step
function work the datatake.c program had to be slightly modified, adding in the step
output as well as a small delay of 0 V outputs to regulate when the step response was
occurring, with respect to sample time. In the step test, the controller is not part of the
system, making the system open loop. This process allows for the system response to be
untouched and natural. The step test was one of two possible testing scenarios, with the
other being a sine wave testing. Due to the complete and accurate results obtained from
the step testing process the sine wave testing was not needed. For a further explanation
behind the choice to only use step testing and other result oriented information see the
results section pertaining to the process identification. The results from this section are
compiled together and the important data is extracted to form the transfer function in
Figure 6.




                        Figure 6: Step Response Transfer Function [4]
       Where: Kp = gain, Td is dead time, and the Tau value in front of the s is a time
constant.

      The values for the transfer function are interpreted from the step response graph
which will be presented and discussed in the results and discussion section.

4.3 PID Controller

        The PID controller uses the results from the step response tests to form a PID
controller equation. The hardware system is set up in the same manner as in the step test
response experiment. The computer goes to the A/D D/A converter then to the black box
and then back through the converter to the computer again. This forms the feedback loop


                                                                                          8
required to keep monitoring the system. The software section of the PID controller is
where the majority of the work is implemented.

         Recalling section 2.2 PID Controller within the background section of the report,
Figure 3 is an important starting point for the PID controller. This basic PID equation
works well for some situations but for the purpose of the lab a more robust PID control
system was required. The direct digital control scheme allows for the PID to be
improved upon by fixing three common hindrances with an analog PID control system.
Transfer bumps occur when the controller is taken from a manual operation mode to an
automatic operation mode. This change in states causes overshoot and can mess with the
stability of the system. Integrator windup occurs when an error is constantly increasing
or out of control during the runtime of the system. The error would continue to be large
and the system would have a hard time correcting it. Derivative fighting is experienced
when a large offset or bump occurs and the derivative value of the PID attempts to
correct it. This in itself is fine, but during the recovery stage the derivative action will
oppose large changes, thus it affects the controller‟s ability to head back towards set
point. These three problems can be fixed by introducing the velocity equation for the
PID controller. The velocity equation takes the form in Figure 7 below.




                                                            Figure 7: Velocity Equation (PID) [1]
Where; MV = Manipulated Variable
      Kc, Taui and Taud = tuning parameters
      En values = errors at different time steps
      Delta t = sample time

        This equation allows for a more stable PID system that is more responsive to
errors with a much smaller tolerance for the errors. The delta MV value mentioned in the
background section is important because that is what is being sent to the black box
controller. The equation in Figure 8 combined with the equation in Figure 7
demonstrates why deltaMV is required.



                                   Figure 8: Delta MV [1]
        The velocity equation looks at a difference between two values, thus the MV
output to the black box needs to be a summing situation to compensate for the velocity
equations bounds. Using the Cohen and Coon tuning method proposed in section 2.3 of
the background section the tuning variables from Figure 7 are calculated. These tuning
variables are an initial estimation at the optimal tuning parameters based upon the
system‟s characteristics. With all of the information calculated from the step response
and with the knowledge gained about the mathematical aspects of the PID controller a
programming routine was attempted to run the actual PID system. The general pseudo



                                                                                                    9
routine implemented was supplied in class and followed throughout the lab. Figure 9
below outlines the process.




                                                       Figure 9: PID Controller Pseudo Code [1]


         The errors are tracked backwards by two time steps because the velocity equation
requires that bound of numbers. The PV (Process Variable) is what is being read in from
the black box system. The initial error is the difference between the actual set point and
the current PC, which should be approaching the set point in the early stages of a PID
system. The bi-directional path in the middle of the code is essentially where the system
decides whether the system will use a PID or a PI controller. The system should run
under the PI controller for the majority of the time unless there is a larger error that needs
correcting. The deltaMV value is obtained because of the aforementioned reasons, and
then sent out to the black box to alter the state of the system. The max and min bounds in
the „if‟ statements are to stabilize a large error if it is attempting to move outside the
operating boundaries of the system. This process is repeatedly looped as the controller
runs and attempts to stabilize. This is the basic operation of a PID controller and if tuned
properly should become closer and closer to a step input graph, which is just an
immediate rise to set point then a maintained stability.

4.4 Dahlin and Kalman Z Controller




                                                                                            10
        Two different Z Controllers were designed an implemented to compare against
the results of the industry standard PID controller. The basic setup on the programming
side of this controller scenario consists mainly of the PID.c code that was used from the
previous step. The PID.c code sent a delta MV (manipulated variable) to the black box
system, which was a sum of the MV variables computed at each sample step. The ability
of the Z-Transform to keep track of previous changes and work without requiring a
summing negated the delta MV variable and instead sent the simple MV value resulting
from the Z transform equations. The MV formulas were found using Z transforms
similar to those in assignment 2. The transfer function from the black box step tests
(second part of the lab) were used along with a hold function to result in the formula in
Figure X below.




                             Figure 10: Controller Equation [3]


       The z-k term is the same as the process variable divided by the set point. This is
the base Z transform equation that is used for all of the Dahlin calculations. The first
component on the right side of the equals sign are transformed into Z equations from the
s-domain transfer function and s-domain hold function which are represented in Figure 7
and Figure 8 below.




                           Figure 11: Hold Function (s domain) [4]




                         Figure 12: Transfer Function (s domain) [1]


The second component of the right side equation is represented as,




                         Figure 13: Specified System Performance [1]


Where; PV = Process Variable
      SP = Set Point


                                                                                       11
        This equation is the desired output you want from your system and will fix the
output given from the other half of the equation in Figure 6. The transformation of the s
domain functions into z domain functions are done using the Z transform tables supplied
by Prof. Hayward in his notes on page 54 [1]. The mathematics for our various tests can
be found in the appendix under Appendix 9.2. The Laplace transform for 1/(s(s+a)) was
used once the s domain functions were simplified into the proper format to be able to take
a z transform. Once a function D(z) equation is produced it can be transformed using the
equation in Figure 10.




                      Figure 14: Difference equation Transformation [1]


        The resulting equation takes the controller equation and transforms it into an
equation that can easily be programmed using C code. The D(z) equation should have a
numerator and a denominator, thus your cross multiply and isolate for a single MV
variable which becomes the equation for the manipulated variable that will be sent to the
black box system (instead of the deltaMV value, as in the PID methodology). The final
value of this process is the Dahlin controller equation that was used in place of the PID
controller. The second alternative tested in the lab procedures was the Kalman controller,
which is a slightly modified alternative to Dahlin. In Figure 11 below, the transformation
equation is extremely simple to go from a Dahlin to Kalman controller.




                       Figure 15: Kalman Transformation Equation [4]


       The Q(z) and P(z) equations are taken from a sub-section of the Dahlin controller
equation. The equation in Figure 12 shows the section of the equation that is equal to the
P(z) and Q(z) parts.




                     Figure 16: Sub-Step for Kalman Transformation [4]


       The P and Q values are subbed into Figure 11 and solved through. Once the
function is in its lowest form, it needs to be normalized. Normalizing turns all of the
numbers in the equation into new numbers that are representative of the normalizing
value. This makes the two coefficients in the numerator add up to one, which is a
necessary step in order to produce a functioning, stable controller. The function obtained


                                                                                        12
after normalization is the Kalman controller, and can be solved for a computer
representation using Figure 10, the same way used for the Dahlin controller. As
mentioned earlier there are all of the worked out scenarios for the Z controllers in the
appendix. They go through various sampling times and lamda values, which will be
discussed in a technical manner in results and discussion.

5 Results and Discussion
5.1 D/A A/D Converter Calibration

        Table 1 below provides the information for both of the voltage tests. The values
are not graphed as it is easier to see discrepancies from the numbers provided.

 Voltage             Channel 0      Channel 1            Channel 2     Channel 3
 Voltmeter
 Input
                 0              0                    0             0            0
             -4.99         -4.995               -4.995        -4.995       -4.995
              4.99          4.995                4.995         4.995        4.995
              5.03          5.029                5.029         5.029        5.029
              5.01           5.01                 5.01          5.01         5.01
                 5              5                    5             5            5
              5.02           5.02                 5.02          5.02         5.02
              4.98          4.976                4.976         4.976        4.976
              4.97          4.971                4.971         4.971        4.971
              4.95          4.956                4.956         4.956        4.956

             0.005          0.005              0.005           0.005       0.005
             0.006          0.005              0.005           0.005       0.005
             0.007            0.01               0.01           0.01        0.01
             0.008            0.01               0.01           0.01        0.01
             0.009            0.01               0.01           0.01        0.01
              0.01            0.01               0.01           0.01        0.01
             0.011            0.01               0.01           0.01        0.01
                     Calibration of D/A converter with voltage supplied
                     externally.

 Computer
 Input               Output Ch 0    Computer Input       Output Ch 1
                 1          1.002                    1         1.002
              1.05          1.051                    2         2.003
                 2          2.003                    3         2.999
                 3          2.999                    4         3.999
                 4          3.999                    5             5
                 5              5                    6             6
                 6              6                    7             7
                 7              7                    8             8
                 8              8                    9             9



                                                                                           13
              9                9                   10           9.99
             10               10                    0          0.001
           10.5               10                   -1         -0.995
              0            0.001                   -2         -1.996
             -1           -0.995                   -3         -2.992
             -2           -1.996                   -4         -3.993
             -3           -2.992                   -5          -4.99
             -4           -3.993                   -6          -5.99
             -5            -4.99                   -7          -6.99
             -6            -5.99                   -8          -7.99
             -7            -6.99                   -9          -8.99
             -8            -7.99                  -10          -9.99
             -9            -8.99                -10.5          -9.99
            -10            -9.99                 10.5   N/A
          -10.5        -9.99
          1.001            1.001           1.001         1.002
          1.002            1.001           1.002         1.002
          1.003            1.001           1.003         1.002
          1.004            1.006           1.004         1.007
          1.005            1.006           1.005         1.007
          1.006            1.006           1.006         1.007
          1.007            1.006           1.007         1.007
          1.008            1.006           1.008         1.007
          1.009            1.011           1.009         1.012
             -2           -1.996              -2        -1.996
              2            2.002               0         0.001
                                               2         2.003
                                               0         0.001
                  Voltage applied from computer program

                  All of the values are in Volts(V)
                  The 1.001 and on values are a fine interval.
     Table 1: Calibration Results using external and computer input to D/A Converter


        Looking at the results obtained from the calibration tests it can be seen that that
hysteresis bounds the values between a maximum of 9 V and a minimum of -10 V. This
is due to the resolution of the converter box. The system saturates at the aforementioned
maximum and minimum values to ensure that a proper boundary of values is upheld.
There is minimal noise on the numbers presented as most of the input voltages match the
output voltage with a 0.01 V offset in values being the largest. Examining the fine
intervals used to determine step size it can be seen that there is a 0.005 V step. As the
voltage increases from 1.3 V to 1.4 V the output value plateaus at 1.006 V, whereas it‟s
original value was 1.001 V. These results indicate that the equipment is running with
minimal noise and will produce optimal results for the given application.

5.2 Black Box Process Identification



                                                                                         14
        The general transfer function and methodology of the black box process
identification is presented in the method section of the report. The sine wave testing was
not required because the step response was accurate enough to safely proceed on to the
PID phase. The sine wave tuning would be necessary if the step response was unstable or
had actions that could not be explained. Once these initial stages were complete the
actual transfer function of the box could be calculated using the graph of the step
response, seen in Figure 17 below.


                                           Step Response of Black Box
                      2.5


                        2

                                                                          Step Response
 Output Volatge (V)




                      1.5
                                                                          Step Input


                        1                                                 Tangent Line Before Fitting

                                                                          Tangent Line of Step
                      0.5                                                 Response



                        0
                             0   10   20       30       40   50    60

                      -0.5
                                           Sample No.

                                                                  Figure 17: Step Response Black Box


        With respect to Figure 17, the red line represents the step response of the system
to the 1 V step input, denoted as the purple line. The blue line represents the fitting
tangent line before it was applied to the response. This line was found using the y = mx
+ b general equation for a line where m is the slope, b is the y intercept and x and y are
points on the graph. Once a decent line was calculated, the y intercept value was found
which matched the line to the response curve, exemplified by the black line. The slope
for the straight line was found using the point of inflection on the response curve. An
average of a few points was taken around the point of inflection (highest slope value on
response curve) and that was used in the straight line curve. Using the outline presented
in Figure 18 the values needed for the PID controller and tuning could be extracted from
the step response graph.




                                                                                                    15
                                                    Figure 18: Step Response Modeling Example
        Where; Kp or Process Gain = Bu / Step Input is needed to find all of the necessary
transfer function information.

        The table below outlines all of the values read off the step input graph, or
calculated using slope from the tangent line.

Process Gain       Dead Time          Time Constant      Slope (m)          Ultimate
(KP)               (Td)               (Tau)                                 Response (Bu)
2.2461             2s                 14.3191            0.1569 V/s         2.2461 V
                                            Table 2: Step Response Transfer Function Numbers


      These values are used to implement the Cohen and Coon tuning presented in the
PID Controller section next. The code for the step response program can be found in the
appendix under Appendix 9.1.3.


5.3 PID Controller

        Using the values obtained from the previous section (5.2 Black Box Process
Identification) the Cohen and Coon tuning procedure is simply plugging numbers into
pre-defined formulas (indicated in the background section) and calculate the three tuning
constants. The three resulting tuning constants were:

                                  Kc      Tau I      Tau D
                                4.3424   4.82849   0.733303
                          Table 3: Cohen and Coon Tuning Constants
        These values allow for an initial starting point for the task of tuning the PID
system. When these results were plugged into the PID code the graph in Figure 19 was
the resulting response.




                                                                                          16
                                                  PID Response with Tuning Parameters

                                  2.5


                                    2
           Process Variable (V)



                                  1.5


                                    1                                                           PID Response



                                  0.5


                                    0
                                         0   10   20    30     40     50    60    70     80

                                  -0.5
                                                         Sample Time (s)


                                                               Figure 19: PID Response with Tuning Parameters



         The result of this trial is not an ideal result but it gives an initial starting point.
The ringing in the initial 30 seconds needs to be removed, and well as the overshoot,
which is almost 2.5 V higher than the desired set point. One positive feature of the graph
is the excellent settling error once it eventually reaches the set point. There is very little
variation off the 1 V set point. The PID controller is stable which helps to further tune
the system. The next phase was to initiate manual tuning using the ISE error function.
The ISE, or Integral Squared Error, was used because it helps to tune the initial response
of the system. The ISE value is more concerned with the rise time, initial response and
errors within the beginning stages of the PID. The tuning parameters resulted in a fairly
stable response with respect to steady state error, thus it was concluded that the ISE error
would benefit the experiment the most. The three figures on the following two pages
illustrate the results of using the ISE error to try and improve upon the three tuning
parameters for the PID system.




                                                                                                                17
                                      Optimal Kc Value
          3

      2.5

          2
ISE




      1.5                                                                         ISE vs KC

          1

      0.5

          0
              0             0.5             1             1.5             2
                                           Kc

                                                    Figure 20: Optimal Kc Tuning using ISE




                                     Optimal Tau D Value
      3


  2.5


      2
ISE




  1.5                                                                             ISE vs Tau D

      1


  0.5


      0
          0       0.002   0.004   0.006   0.008    0.01   0.012   0.014   0.016
                                          Tau D



                                                  Figure 21: Optimal Tau D Tuning using ISE




                                                                                                 18
                           Optimal Tau I Value
       2.36
       2.35
       2.34
       2.33
       2.32
 ISE




                                                                    Tau I vs ISE
       2.31
        2.3
       2.29
       2.28
       2.27
              0           5                10               15
                                Tau I

                                        Figure 22: Optimal Tau I Tuning using ISE


         The clear minimum values are taken as the tuning constants for use in the PID
equation. The tuning procedures used in this lab after the Cohen and Coon tuning were
not as extensive as they could have been. A range of values were tested initially to get an
idea of where a good starting point for ISE testing would be. The ranges of ISE testing
were small intervals to try and find the best value. The trial and error tuning method used
initially is not the most precise but it allowed for knowledge to be gained on how the
graphs were affected by changes in the tuning parameters. In the recommendations
section a more precise method is discussed.

       The tuning numbers resulting from these tests were Kc = 1.4, Tau I = 11, Tau D =
0.009. Graphically the results of these tuning variables on the PID system can be seen in
Figure 23 on the following page.




                                                                                        19
                                          PID After Tuning Procedures

                          1.4

                          1.2


                            1
   Process Variable (V)




                          0.8

                          0.6                                                                 PID Response

                          0.4

                          0.2

                            0
                                 0   20   40         60          80       100       120
                          -0.2
                                               Sample Time (s)


                                                                 Figure 23: PID System Response after Tuning


        The graph is larger to better show the characteristics of the final PID results. The
improvements in the graph are immense, when compared against the Cohen and Coon
testing results. The ISE error calculated for this final PID tuned graph was 2.297375.The
steady state error is slightly higher, but only by an extremely small percentage as you can
see a small 0.001 V rise off the 1 V set point. The overshoot is a maximum at a value of
1.18 or 18% of the set point. The PID system settles at an approximate value of 23
seconds which is a moderate settling time. The small 0.2 V undershoot occurs because
the overshoot value is so low for our system variables. I could not get rid of the
undershoot, but with rigorous self tuning it would more than likely become much closer
to a step input. The rise time of the system is extremely fast with minimal error. In
approximately 8 seconds the system has reached the maximum overshoot which is
relatively good for a system with some undershoot. The manual tuning greatly improved
upon the Cohen and Coon settings which was expected. Cohen and Coon tuning is
normally used as an initial starting point, not an end means for PID optimal functionality.
With regards to the sampling time of the PID that will be discussed in the upcoming
section 5.5 when the PID is compared against the Z controller.

5.4 Dahlin and Kalman Z Controller

       The results of the Z controller are significant in the sense that they provide a new
way of tuning the controller system. In the Z controllers the lamda and sampling time are
the two main tuning variables used, as opposed to the three variables used for PID



                                                                                                               20
controlling. Three different tests were conducted with respect to sampling times.
Sampling times of one, five and eight seconds were tested for a range of lamda values (a
time constant). The graph in Figure 24 below graphically depicts the trends of altering
the lamba value.


                                  One Second Sample Time Dahlin Controllers

                        1.2

                         1
  Process Variable(V)




                        0.8
                                                                                           Lamda 5s
                        0.6                                                                Lamda 10s
                                                                                           Lamda 15s
                        0.4
                                                                                           Lamda 20s
                        0.2

                         0
                              0      20              40             60             80
                   -0.2
                                             Sample Time(s)

                                                      Figure 24: One Second Sample Time Dahlin Controllers


        As lamba increases, the response of the output slows down drastically from a
lamda of five to a lamda of ten, then slower as lamda increases from there. It is taking
longer to reach a set point as lamda increases, as well as producing a steady state error.
The SS error means that the actual set point is dropping below the desired set point,
which is not acceptable for a Z controller. It is safe to say that the lamda value is not
only affecting the initial rise time of the system, but it also shifts the settling time to the
right(longer time periods). The optimum lamda value at this point occurs at a value of
five, which gives a settling time of approximately 60 seconds, and a moderate rise and
response time. The ISE errors for the four curves above are supplied in Table 4 below.


                                               All for a 1s Sample Time
                                  Lamda         5          10        15          20
                                   ISE      3.442591 6.035512 7.136953        10.80619
                                          Table 4: One Second Sample Time: Lamba vs. ISE


        The ISE errors are increasing by a relatively large amount as lamda increases by a
factor of five. The largest error occurs between a lamda of five and ten because the


                                                                                                        21
system is the most responsive within those bounds. None of these equations have ringing
poles, which makes them stable for their sample time boundary. The step from a one
second sampling time to a five second sampling time produces interesting results,
illustrated graphically in Figure 25.



                                Five Second Sampling Time Dahlin Controllers
                         1.2

                           1
  Process Variable (V)




                         0.8

                         0.6                                                                  Lamda 5s
                                                                                              Lamda 10s
                         0.4                                                                  Lamda 15s
                                                                                              Lamda 20s
                         0.2

                           0
                                0    50      100       150       200        250       300
                         -0.2
                                             Sample Time (s)

                                                       Figure 25: Five Second Sample Time Dahlin Controllers


       The responses of the five second sampling time are a lot cleaner and have much
quicker rise times when compared against the one second sample time controllers. The
curves all meet the required set point within a decent time. The lamda of 5s contains
some noise before settling, but it never shoots over the set point like the PID controller
did. The best way to compare the graphs is to examine the ISE error chart presented in
Table 5 below.

                                                All for a 5s Sample Time
                                     Lamda      5           10        15         20
                                      ISE    1.69792 3.702812 6.421218        8.775309
                                          Table 5: Five Second Sample Time: Lamba vs. ISE
       The error increases as lamda increases which is expected according to the one
second sample time results. The main thing to notice is that the lamda of five produces
the minimum error, just like in the previous test. The error this time that is inherent in the
system is almost half that of the one second sampling time trial. This is because of the
quicker rise time and reduced area in the initial stages of the graph, as that is what ISE
measures. The Dahlin model is holding up at these values as there is zero overshoot


                                                                                                          22
within any of the models, which is a prime characteristic of the Dahlin approach. The
final sample time test was produced at eight seconds, with the results being plotted in
Figure 26 below.


                                      Eight Second Sampling Time Dahlin Controllers

                           1.2


                            1


                           0.8
   Process Variable (V)




                           0.6
                                                                                                     Lamda 5s
                                                                                                     Lamda 10s
                           0.4


                           0.2


                             0
                          -10    10      30      50        70      90       110     130      150
                          -0.2
                                                   Sample Time (s)


                                                         Figure 26: Eight Second Sample Time Dahlin Controllers


        The eight second sampling time results settles faster than the previous sample
times but the tradeoff is overshoot. There are fewer oscillations at the lamda of five
response but the overshoot finally peaks above the set point. The lamda of ten produces a
sluggish response, which is not great for a lot of applications. The ideal situation is to
have the response reach the set point as soon as possible. The decay on the lamda (five)
function is approximately 50% as the function reaches a settling point. Looking at the
errors in Table 6 below will tell a better overall story of the systems performance.

                                                           All for a 8s Sample
                                                                   Time
                                                 Lamda         5          10
                                                  ISE      1.851797 3.967421
                                        Table 6: Eight Second Sample Time: Lamba vs. ISE


        The error is still relatively low in the lamda (five) and lamda (ten) when compared
against all of the previous trials, but give is still the best result for a sample time of eight
seconds. Compared against the best result up until now, the lamda of five at eight
seconds is slightly worse than the previous trial. The small overshoot is not a desirable


                                                                                                                23
outcome, when there isn‟t much difference between the functions. A machine would
have to work a bit harder for a lamda of five and a sampling time of five but it would be
worth it in most cases to obtain the best response.

        The overall theory is that a larger lamba will result in a sluggish system response
and a slow rise to the set point, while a lamba that is too small will result in an unstable
system with ringing. A lamba between these values is ideal to maintain a stable,
responsive system for industry use.

        To reduce some of the problems found in the Dahlin controllers, Kalman
proposed a theory that would reduce the ringing, thus causing wear and tear on parts, in
the system functionality. Kalman calculated the desired output and matches that against
the calculated output to be given an equation that helps to remove ringing in the system.
At a one second sampling time the system is constantly ringing, and unstable. This is
because the poles lie on the unit circle and thus are unusable. The phenomenon of
ringing can be seen in Figure 27 below.


                                     Kalman Controller with One Second Sampling Time

                          4.5

                            4

                          3.5
                            3
   Process Variable (V)




                          2.5

                            2
                                                                                             Kalman Response
                          1.5

                            1

                          0.5

                            0
                                 0     20     40         60          80     100       120
                          -0.5

                           -1
                                                   Sample Time (s)

                                                    Figure 27: Kalman Controller with One Second Sampling Time


        The Kalman approach, as mentioned in the method section of the report, is tuned
by different sampling times, as a lamda value is not used in the system. To improve upon
the ringing poles a larger sampling time (five seconds) is introduced. The Kalman
controller with a five second sampling time can be seen in Figure 28.



                                                                                                            24
                                    Kalman Controller with Five Second Sampling Time

                          1.2


                           1
   Process Variable (V)




                          0.8


                          0.6                                                               Kalman Response



                          0.4


                          0.2


                           0
                                0    20      40         60        80       100       120
                                                  Sample Time (s)

                                                   Figure 28: Kalman Controller with Five Second Sampling Time


         The response in this system is exponentially better than that at a one second
sample time. The ringing present earlier is reduced immensely and even compared to the
Dahlin controllers the ringing is substantially lowered. This system has an excellent
response time, with a moderate settling time, and no overshoot. There is an initial bump
at the beginning but the system recovers and slowly makes its way to the set point. To
see how the system reacts to an even larger sampling time, an eight second time is used to
test the upper limits of the system. The graph for that system is represented in Figure 29
on the following page.




                                                                                                            25
                                   Kalman Controller with Eight Second Sampling Time

                         1.2


                          1
  Process Variable (V)




                         0.8


                                                                                              Kalman Response
                         0.6


                         0.4


                         0.2


                          0
                               0   20         40         60        80       100       120
                                                   Sample Time (s)

                                                    Figure 29: Kalman Controller with Eight Second Sampling Time


        Once a sampling time of eight seconds is introduced the system begins to
overshoot which is not an acceptable result for a Dahlin controller, let alone a Kalman
controller. The rise time is extremely quick and does not lag much at all. The decay ratio
on the oscillations is approximately one, with an even amount of overshoot and
undershoot occurring in the initial stages of oscillation. The settling time of
approximately 80 seconds is about 9 seconds slower than the settling time at a sampling
time of five seconds. Examining the errors of the system in Table 7, the Kalman
controllers can be compared against the previous Dahlin controllers.

                                                     Sample Time Used
                                                               1         5            8
                                                     Out of
                                        ISE          Control      1.369318        1.7064
                                              Table 7: Kalman Sample Times vs. ISE


       The error increases as the sample time increases but at the lower sampling times a
lower bound is found, as during the sample time of one the system becomes unstable and
ringing occurs. The ringing occurs because once again there are poles of the difference
equation on the unit circle. The magnitude of the error is extremely small because the
ringing was removed from the systems, for the most part. The five second sample time
Kalman controller actually scored a lower error than that of the five second sample time
Dahlin. I believe this is true due to the noise in the Dahlin controller response. Ideally
the Dahlin controller should be a better result but in this case since Kalman just removed


                                                                                                             26
the ringing on the Dahlin controllers, it will obviously score better since it‟s basically
running the same controller, minus the ringing. The next step in this process is to
compare the results of the Z controller against that of the PID controller since they are
performing similar operations.


5.5 PID Compared Against Z Controller

        The PID controller and the Z controller are attempting to perform the same task of
maintaining a steady set point around the desired set point. First examining the graphs in
each of their respective sections it can be seen that the Kalman controller has the lowest
ISE error. The PID error is 2.297375 (ISE) which would have been reduced significantly
with some self tuning or a more robust tuning procedure. The 1.369318 ISE error on the
Kalman controller is an excellent measure of the systems ability to correct ringing. The
1.69792 ISE error on the lamda five function at a sample time of five seconds is an
excellent response, considering it‟s ringing in its initial stage. Overall though, the results
are completely dependent on the desired applications of the controller. The PID
controller is probably the most well rounded response, with the slight oscillation at the
beginning, excellent settling time and a very quick rise time. The Dahlin controller
oscillates a lot more than the other controllers but the initial response is the fastest
overall. This would just mean that the system would require a lot of work initially, which
may not be the best for mechanical systems that could experience wear and tear. The
Kalman controller would be a better option for mechanical control since it oscillates
much less, and still has a decent response with respect to rise time. The Kalman never
rises over the set point, which would be ideal for any cooking situations where an
overshoot could burn the objects under control. Another aspect to examine is the
response of the systems at varied sample times, and with disturbances introduced into a
settled system. These tests help to show stability and can give a better point of
comparison for the two methods. The tests were done at sampling times of one, five and
eight so the systems could be fairly compared. An equal voltage was applied for a
disturbance between the tests, and it was instilled in the system at similar times in the
settling pattern. The best situations were compared, meaning that the sample time and
lamda of five case for Dahlin was used, with the five second Kalman used. Figure 30
below shows the response for a Dahlin controller operating at lamda five and sampling
time five when a five volt disturbance is introduced during a settled period. The sizes of
the graphs are reduced to see the comparison of the two graphs on one page.




                                                                                             27
                                         Dahlin Disturbance Test
                         4

                        3.5
 Process Variable (V)




                         3

                        2.5
                                                                             Lamda 5 Ts 5 5V
                         2                                                   Disturb
                        1.5

                         1

                        0.5

                         0
                               0   100        200          300        400
                                         Sample Time (s)

                                                           Figure 30: Dahlin Disturbance Test


        The five volt disturbance is measured as a 3.75 volt overshoot with a decay ratio
of the same value. The decay ratio is the same because the system reaches the set point
of one on its second bump and does not oscillate a second time. As can be seen, the
results from the disturbance test are not exactly desirable. The overshoot is much too big,
and the resulting correction to set point will cause even more wear on the mechanical
system. For a slightly better response Figure 31 below will show the exact same settings
applied to a Kalman controller.


                                         Kalman Disturbance Test
                          4
                        3.5
                          3
 Process Variable (V)




                        2.5
                          2                                                   Lamba 5 Ts 5 5V
                                                                              Disturb.
                        1.5
                          1

                        0.5
                          0
                               0   100         200          300        400
                        -0.5
                                         Sample Time (s)

                                                           Figure 31: Kalman Disturbance Test


       The Kalman results are basically the same with the main difference being the
undershoot value and the response back to set point after the disturbance. The one volt


                                                                                                28
undershoot is slightly smaller than the 0.75 volt undershoot from the Dahlin controller.
The key thing to notice is the response back to set point, which is much smoother than the
Dahlin controller, which experienced ringing. Unfortunately the resulting disturbance is
still really high, and not desired. The whole disturbance process affects a 75 second
period which would seem to be quite high, but when examining the original Dahlin and
Kalman graphs it is seen that the settling time is fairly large. To add a point of
comparison the tuned PID controller was giving disturbances of two volts, five volts and
nine volts with a sample time of one second. The results can be seen in Figure 32 below.


                                  PID One Second Sample Time Disturbance Tests
                        2.5


                         2
 Process Variable (V)




                        1.5
                                                                                       2 V Disturbance
                                                                                       5 V Disturbance
                         1                                                             9 V Disturbance


                        0.5


                         0
                              0               50                   100
                                             SampleTime (s)

                                                   Figure 32: PID One Second Sample Time Disturbance Tests


         The graph shows an excellent, stable, response to the disturbances input into the
system. For a 2v input the disturbance is measured at 0.19 V which is slightly higher
than the initial response. The 0.19 overshoot from a two volt input is an excellent result
to see. The whole process settles in approximately 25 seconds which is the same as the
initial settling time of the PID system. As the disturbance increases the overshoot and
undershoot also increase, but it‟s factored by a substantial amount. At the highest
disturbance value of 9v the system only experiences just over one volts of disturbance.
Comparing the 5V disturbance case against that of the Dahlin and Kalman controllers it
can be seen that the overshoot and undershoot are essentially halved. Another set of tests
are performed on the sampling time of the PID controller to compare it to those of the Z
controllers. In Figure 33, below, the sample time of eight seconds on the PID controller
with a 2V disturbance is shown.




                                                                                                         29
                                             PID Controller with 8 Second Sample Time and 2V
                                                                Disturbance

                                         10
                                             8
                  Process Variable (V)




                                             6
                                             4
                                                                                                 8 s Sample Time, 2V
                                             2                                                   Disturb.
                                             0
                                         -2 0             200         400        600     800
                                         -4
                                         -6
                                                               Sample Time (s)

                                                 Figure 33: PID Controller with 8 second Sample Time and 2V Disturbance


        The system is completely unstable with sustained oscillations. The eight second
sample time does not catchy any of the errors and the system is basically useless. This
exemplifies an upper limit on sampling time, thus a lower sampling time needs to be
tested. In the following graph a PID controller with a 5 second sample time and a 2V
disturbance is illustrated.


                                                      PID Controller 5s Sample Time with 2V
                                                                   Disturbance
                               2.5

                                         2
 Process Variable (V)




                               1.5

                                         1                                                      5s Sample Time with
                                                                                                2V Disturb.
                               0.5

                                         0
                                             0           100        200          300    400
                         -0.5
                                                               Sample Time (s)

                                             Figure 34: PID Controller with 5 second Sample Time and 2V disturbance


        The response of this system is a much better example of a working sample time.
Although compared to the final tuning of the PID controller at a one second sample time
the oscillation is unacceptable. The overshoot and undershoot are much more


                                                                                                                          30
pronounced and reads the 2V disturbance almost exactly. One positive feature of the
graph is the smooth steady state error once the system actually reaches set point. A final
test to try and improve upon the tuned PID controller is performed by running a sample
time of 0.5 seconds and comparing that against a one second sampling time. The graph
in Figure 34 shows the aforementioned situation.


                                    PID Controller 0.5s Sample Time

                         1.4
                         1.2
  Process Variable (V)




                           1
                         0.8
                                                                               0.5s Sample Time
                         0.6                                                   1s Sample Time
                         0.4
                         0.2

                           0
                                0    10        20          30           40
                         -0.2
                                          Sample Time(s)

                                                      Figure 35: PID Controller 0.5 Second Sample Time


       The one second sample time is included in this graph as a comparison point. The
one second PID has slightly more overshoot, but it compensates that with a quicker rise
time and faster settling time. The 0.5 second sample time results in a sustained
undershoot and a slightly slower response after about 0.4 V in the process variable.

        The PID proves that it is the industry standard for a reason, exhibiting excellent
results with a tuning process that was not as robust as it could have been. The Z
controllers are used in very specific cases where certain characteristics of a system need
to be reduced or improved upon. Ringing in the system can be aided by the Kalman
while the Dahlin offers a stable system that has an excellent initial response.

6 Recommendations
         The overall tuning of the PID is the main negative point in this experiment. I feel
like it could have been tuned better using self tuning, but it was beyond the scope that I
wanted to test. My tuning procedures resulted in an excellent graph, but still had some
features that were not desired. A decision had to be made concerning how far in depth I



                                                                                                    31
wanted to get into PID tuning, and I decided that it was best to leave it as it was, and just
describe how it could be better. I could spend another six months tuning this until it was
exactly as I wanted, but I wouldn‟t be learning much more from what I know at this point
in time. I was satisfied with a stable system that experienced minimal overshoot and
undershoot with relatively quick rise and response times. I could have tuned using the
conventional way of splitting the PID up and observing maximum oscillations to improve
the tuning procedure. The Z transforms were something newer to me and could probably
have had reduced ringing in the initial response stages. The Dahlin controller should
have shown a better response curve, in my opinion, but the math was done correctly, and
a stable system resulted using that equation. There are always many more tests you think
of after the fact that may contribute to the functionality of the system but at a certain
point you have to go with what you have and explain it with the knowledge you have
gained throughout the course. A larger evaluation of sampling times could have been
used to find a more precise, possibly decimal number for the final sample time, but using
a sample time of one for the PID controller allowed for simpler calculations and still gave
me the ability to observe trends in the system to gain an overall understanding of them.
Most of the problems came from tuning the various system, as mentioned above, which is
essentially a skill that develops over time as a knowledge base and experiences are built
up in the industry.

7 Conclusions
        The PID controller exhibited the optimal results when compared against the Z
controllers. Although the Kalman had the lowest error it had more oscillations and a
slower response and settling time. The process of going from a black box step response
to a transfer function then to controllers was an interesting process that allowed me to
learn the fundamentals of controller design. The Z transforms optimal sample time was
five seconds with a lamda of five, from my general tests. As the lamda increased the
system became sluggish, but as the lamda became too small the system exhibited
overshoot and some instability. The sampling time had a similar effect where at a one
second sample time the poles of the system caused ringing and at higher sample times the
system was sluggish, once again, and would not respond well to system disturbances.
The Cohen and Coon tuning provided a decent starting point for PID control but had
ringing initially for my system. Tuning using the ISE (Integral Squared Error) values
was a quick way to find an optimal point for the tuning parameters. The resultant PID
controller was very efficient and provided an excellent controller environment. The PID
system results exemplify why the PID is still an industry standard controller.




                                                                                          32
8 References
[1] Hayward, Gordon L., “Computerized Control Systems in the Food Industry”,
    University of Guelph. 1997.
[2] Wikipedia . “PID Controller”, <http://en.wikipedia.org/wiki/PID_control>. 2007.
[3] Tham, M. “Design of Simple Digital Controllers”.
    http://lorien.ncl.ac.uk/ming/digicont/control/digital4.htm. 2007.
[4] Hayward, Gordon L. “4280 Digital Process Control Class Notes”. University of
    Guelph. 2007.




                                                                                      33
9 Appendix

9.1 Code Compilation

      All of the code used was based upon Alan K. Miller’s initial datatake.c
program.


9.1.1 Datatake.c Program

/*********************************************************************
*
* Program Name: AnlgInOut.c
*
* Author: A.K. Miller
*
* Date: 19 Dec 02
*
* Purpose: To create a starting program for ENGG*4280 using the NI PCI-6024E
* a 12 bit AD/DA card. This program uses AOonePoint.c and AIonePoint.c,
* provided by NI with the card, and Analog.c (1999) written by S.D. Smith
* from Analog.p (1996) written by Dr G.L. Hayward.
*
* Description:
* Output one or two channels, one point at a time, immediately.
* Read up to 4 channels, one point at a time, immediately.
*
* NI-DAQ Example Categorys:
* AO, AI
*
* NI-DAQ Example Task Types:
* 1PT, 1CH, IMMED, INTTIM
*
* List of NI-DAQ Functions used in this example:
* AI_VRead, NIDAQErrorHandler, AO_VWrite, NIDAQWaitForKey
*
* [NOTE: For further details on each NI-DAQ function, please refer
* to the NI-DAQ On-Line Help (NIDAQPC.HLP).]
*
* Pin Connection Information:
* The analog output signal will be available at AO channel DAC0OUT and
DAC1OUT.
* Connect your analog signal to AI channel ACH0, ACH1, ACH2, and ACH3.
* The default analog output and input mode for the DAQ device will be used.



                                                                                34
* The input and output values should be between - 10 and + 10 volts.
*
* [For further I/O connection details, please refer to your hardware
* User Manual.]
*
************************************************************************
/


/*
 * Includes:
 */

#include "nidaqex.h"
#include "iostream.h"
#include "stdio.h"
#include "string.h"
#include "time.h"
#include "sys/timeb.h"
#include "process.h"

FILE *stream;


/*
 * Input number of channels routine:
 */

int GetNumChan()
{
       /* Local Variable Declarations: */

       int            k = 0;                        /* place holder */
       int            ChnNm = 0;                    /* channel number */

       while ((ChnNm < 1) || (ChnNm > 4))
       {
               printf("\n Enter the number of channels you want to use. 1 to 4 \n");

               k = scanf( "%d", &ChnNm);

               if ((ChnNm < 1) || (ChnNm > 4))
               {
                       printf(" Illegal Input number must be between 1 and 4. \n");
               }
       }



                                                                                       35
       return (ChnNm);
}

/* End input channel routine */


/*
 * time routine
 */

double GettheTime ()
{
       /* Local Variable Declarations: */

       i32 Scnd = 0;                  // seconds
       i16 MiScnd = 0;                         // milliseconds
       f64 TheTime = 0.0;             // the time seconds . millidecomds

       struct _timeb tstruct;

       _ftime( &tstruct );
       MiScnd = tstruct.millitm;  // milliseconds
       Scnd = tstruct.time;       // Time in seconds since midnight January 1, 1970,
       TheTime = MiScnd / 1000.0 + Scnd;

       return (TheTime);
}

/* End of time routine */


/*
 * delay routine
 */

double DelayTime (f64 NxtTm )
{
       /* Local Variable Declarations: */

       f64 CrntTime = 0.0;

       do
       {
                  CrntTime = GettheTime();
       }



                                                                                   36
        while (CrntTime < NxtTm);

        return (CrntTime);
}

/* End of delay routine */


/*
 * Routine to input the voltages:
 */

double InVolt (i16 iChan)
{
  /* Local Variable Declarations: */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    i16 iGain = -1;
    f64 dVoltage = 0.0;
    i16 iIgnoreWarning = 0;

        iStatus = AI_VRead(iDevice, iChan, iGain, &dVoltage);
        iRetVal = NIDAQErrorHandler(iStatus, "AI_VRead", iIgnoreWarning);

        if (iStatus == 0)
        {
                 return (dVoltage);           /* send back the voltage */

        }
}

/* End of voltage input routine */


/*
 * Main:
 */

void main(void)
{
  /* Local Variable Declarations: */

        char   DtFlNm[40] = "";        /* the output file name */
        char   j = 0;                          /* place holder */



                                                                            37
int         Chan = 0;                      /* input channel counter */
int         NumChan = 0;          /* number of input channels counter */
    int             Samples = 0;           /* sample counter */
    int             NumSam = 0;                     /* number of samples */
double      Volts = 0.0;          /* input voltage */
    double StartTime = 0.0;       /* the time sampling started */
    float SampleTime = 0.0; /* the time since sampling started */
    double NextTime = 0.0;                 /* the time for the next sample */
    double NewTime = 0.0;                  /* the time for this sample */
    float Interval = 0.0;         /* the interval between samples */
    char CR = '\n';
    char Tb = '\t';
    printf("\n Enter your file name. eg c:\\341\\data\\4min.txt \n");

      j = scanf( "%s", &DtFlNm);

      stream = fopen(DtFlNm,"w");

      NumChan = GetNumChan();

      printf("\n Enter the number of samples you want to take. \n");

      j = scanf( "%d", &NumSam);

      printf("\n Enter the sample rate in seconds. \n");

      j = scanf( "%f", &Interval);

      StartTime = GettheTime();
      NextTime = StartTime + Interval;

      for (Samples = 0; Samples < NumSam; Samples++)
      {

             printf("\n %6.3f \t", SampleTime);
             fprintf(stream,"\n %f \t", SampleTime);

             for (Chan = 0; Chan < NumChan; Chan++)
             {
                    Volts = InVolt(Chan);
                    printf(" %d \t %6.3lf \t", Chan, Volts);
                    fprintf(stream, " %d \t %lf \t", Chan, Volts);
             }

             NewTime = DelayTime (NextTime);
             SampleTime = NewTime - StartTime;



                                                                                38
              NextTime = NewTime + Interval;
       }

       fprintf(stream,"\n");
       fclose( stream );
}

/* End of program */



9.1.2 PID.C Code
       I just posted the alteration to make the PID.c code. The datatake.c program was
used as the skeleton for all of the code from this point on.

       The Z transform code is exactly the same as the PID code except that the MV
equations for the PID are switched with the MV equations for the Z transform, and
anything to do with delta MV is removed.

/****** PID VARIABLES*********************/
      double error = 0, errorOld = 0, errorOld2 = 0;
      double sampleTime = 1;        /*CHANGE*/
      double PV = 0, setPoint = 1;
      double MV = 0, deltaMV = 0;
      double max = 9, min = -10;
      double Kc = 1.4, TauI = 11, TauD = 0.009;
      double num = 0;
      double tempError = 0,tempErrorOld = 0;
      double IAE = 0;
/*******************************************/

       OutVolt (0,0);

       printf("\n Enter your file name. eg c:\\341\\data\\4min.txt \n");

       j = scanf( "%s", &DtFlNm);

       stream = fopen(DtFlNm,"w");
       printf("\n How many times do you want the PID loop to run? \n");
       j = scanf( "%d", &countIn);

/***** PID CODE***********************/
       StartTime = GettheTime();
       NextTime = StartTime + sampleTime;

       while (count <= countIn) {


                                                                                         39
               errorOld2 = errorOld;
               errorOld = error;

               PV = InVolt(0);
               error = setPoint - PV;

               /*** Removed everything except the MV equation when Z transform is
               used**/

               if ( (error *(error - errorOld)) >= 0) {
                        /*Calc MV using PID*/

                        MV = Kc*((error - errorOld) + ((error*sampleTime)/TauI) +
(((error - (2*errorOld) + errorOld2)*TauD)/sampleTime));
                }
                else {
                        /*Calc MV using PI-ignore deriv. term*/

                       MV = Kc*((error - errorOld) + ((error*sampleTime)/TauI));
               }

               deltaMV = deltaMV + MV;

               if (deltaMV > max){
                        deltaMV = max;
               }
               else if (deltaMV < min) {
                        deltaMV = min;
               }

               OutVolt(deltaMV,0);
               /*if (count == 70) {                       /*Disturbance*/
                       OutVolt(2,0);
               }*/

               fprintf(stream, " %f \t %f \t %f \t \n", PV, deltaMV, error); /*%lf*/
               printf("%f \t %f \t %f \t \n", PV, deltaMV, error);
               count++;

//////////////////// Delay ////////////////////////////
                     NewTime = DelayTime (NextTime);
                     SampleTime = NewTime - StartTime;
                     NextTime = NewTime + sampleTime;

}
/******** END OF PID CODE************/



                                                                                       40
9.1.3 StepResponse.c Program

/*********************************************************************
*
* Program Name: AnlgInOut.c
*
* Author: A.K. Miller
*
* Date: 19 Dec 02
*
* Purpose: To create a starting program for ENGG*4280 using the NI PCI-
6024E
*     a 12 bit AD/DA card. This program uses AOonePoint.c and
AIonePoint.c,
*     provided by NI with the card, and Analog.c (1999) written by S.D.
Smith
*     from Analog.p (1996) written by Dr G.L. Hayward.
*
* Description:
*     Output one or two channels, one point at a time, immediately.
*     Read up to 4 channels, one point at a time, immediately.
*
* NI-DAQ Example Categorys:
*     AO, AI
*
* NI-DAQ Example Task Types:
*     1PT, 1CH, IMMED, INTTIM
*
* List of NI-DAQ Functions used in this example:
*     AI_VRead, NIDAQErrorHandler, AO_VWrite, NIDAQWaitForKey
*
*     [NOTE: For further details on each NI-DAQ function, please refer
*      to the NI-DAQ On-Line Help (NIDAQPC.HLP).]
*
* Pin Connection Information:
*     The analog output signal will be available at AO channel DAC0OUT
and DAC1OUT.
*     Connect your analog signal to AI channel ACH0, ACH1, ACH2, and
ACH3.
*     The default analog output and input mode for the DAQ device will
be used.
*     The input and output values should be between - 10 and + 10 volts.
*
*     [For further I/O connection details, please refer to your hardware
*      User Manual.]
*
***********************************************************************
*/


/*
 * Includes:
 */

#include "nidaqex.h"
#include "iostream.h"



                                                                      41
#include      "stdio.h"
#include      "string.h"
#include      "time.h"
#include      "sys/timeb.h"
#include      "process.h"

FILE    *stream;


    /*
     * Input number of channels routine:
     */

int GetNumChan()
{
      /* Local Variable Declarations: */

        int            k = 0;                        /* place holder */
        int            ChnNm = 0;              /* channel number */

      while ((ChnNm < 1) || (ChnNm > 4))
      {
            printf("\n Enter the number of channels you want to use. 1
to 4 \n");

                 k = scanf( "%d", &ChnNm);

                 if ((ChnNm < 1) || (ChnNm > 4))
                 {
                       printf(" Illegal Input number must be between 1 and
4. \n");
                 }
        }

        return (ChnNm);
}

/* End input channel routine */


/*
 * time routine
 */

double GettheTime ()
{
      /* Local Variable Declarations: */

        i32 Scnd = 0;                    // seconds
        i16 MiScnd = 0;                  // milliseconds
        f64 TheTime = 0.0;               // the time seconds . millidecomds

        struct _timeb tstruct;

        _ftime( &tstruct );
        MiScnd = tstruct.millitm;        // milliseconds




                                                                              42
      Scnd = tstruct.time;          // Time in seconds since midnight
January 1, 1970,
      TheTime = MiScnd / 1000.0 + Scnd;

      return (TheTime);
}

/* End of time routine */


/*
 * delay routine
 */

double DelayTime (f64 NxtTm )
{
      /* Local Variable Declarations: */

      f64 CrntTime = 0.0;

      do
      {
            CrntTime = GettheTime();
      }
      while (CrntTime < NxtTm);

      return (CrntTime);
}

/* End of delay routine */


/*
 * Routine to input the voltages:
 */

double InVolt (i16 iChan)
{
    /* Local Variable Declarations: */

    i16    iStatus = 0;
    i16    iRetVal = 0;
    i16    iDevice = 1;
    i16    iGain = -1;
    f64    dVoltage = 0.0;
    i16        iIgnoreWarning = 0;

      iStatus = AI_VRead(iDevice, iChan, iGain, &dVoltage);
      iRetVal = NIDAQErrorHandler(iStatus, "AI_VRead", iIgnoreWarning);

      if (iStatus == 0)
      {
            return (dVoltage);             /* send back the voltage */

      }
}




                                                                         43
/* End of voltage input routine */

void OutVolt (f64 OVolt, i16 OChnl)            /*changed*/

{
     /* Local Variable Declarations:   */

     i16   oStatus = 0;
     i16   oRetVal = 0;
     i16   oDevice = 1;
     i16   oIgnoreWarning = 0;

      //printf("\n Hit any key to output %6.3lf volts on %d channel.\n
\n", OVolt, OChnl);           /*removed*/
      //oRetVal = NIDAQWaitForKey(0.0);
      oStatus = AO_VWrite(oDevice, OChnl, OVolt);
      oRetVal = NIDAQErrorHandler(oStatus, "AO_VWrite",
oIgnoreWarning);
}

/* End of voltage output routine */

/*
 * Main:
 */


void main(void)
{
    /* Local Variable Declarations:    */

      char DtFlNm[40] = ""; /* the output file name */
      char j = 0;                         /* place holder */
    int           Chan = 0;               /* input channel counter */
    int           NumChan = 0;            /* number of input channels
counter */
      int         Samples = 0;            /* sample counter */
      int         NumSam = 0;             /* number of samples */
    double Volts = 0.0;             /* input voltage */
      double      StartTime = 0.0; /* the time sampling started */
      float SampleTime = 0.0; /* the time since sampling started */
      double      NextTime = 0.0;         /* the time for the next
sample */
      double      NewTime = 0.0;          /* the time for this sample
*/
      float Interval = 0.0;         /* the interval between samples */
      char CR = '\n';
      char Tb = '\t';
      char input;
      int count = 1;

    OutVolt (0, 0);                                  /*changed */

       printf("\n Enter your file name. eg c:\\341\\data\\4min.txt \n");

       j = scanf( "%s", &DtFlNm);




                                                                         44
stream = fopen(DtFlNm,"w");

NumChan = GetNumChan();

printf("\n Enter the number of samples you want to take. \n");

j = scanf( "%d", &NumSam);

printf("\n Enter the sample rate in seconds. \n");

j = scanf( "%f", &Interval);




while ((InVolt(0)) > 0.01) {

/*changed */
}


StartTime = GettheTime();
NextTime = StartTime + Interval;

for (Samples = 0; Samples < 10; Samples++)
{
      printf("\n %6.3f \t", SampleTime);
      fprintf(stream,"\n %f \t", SampleTime);

      for (Chan = 0; Chan < NumChan; Chan++)
      {
            Volts = InVolt(Chan);
            printf(" %d \t %6.3lf \t", Chan, Volts);
            fprintf(stream, " %d \t %lf \t", Chan, Volts);
      }

      NewTime = DelayTime (NextTime);
      SampleTime = NewTime - StartTime;
      NextTime = NewTime + Interval;
}


OutVolt(1,0);
printf("****%d ****\n",SampleTime);

for (Samples = 0; Samples < NumSam; Samples++)
{
      printf("\n %6.3f \t", SampleTime);
      fprintf(stream,"\n %f \t", SampleTime);

      for (Chan = 0; Chan < NumChan; Chan++)
      {
            Volts = InVolt(Chan);
            printf(" %d \t %6.3lf \t", Chan, Volts);
            fprintf(stream, " %d \t %lf \t", Chan, Volts);
      }




                                                                 45
               NewTime = DelayTime (NextTime);
               SampleTime = NewTime - StartTime;
               NextTime = NewTime + Interval;
       }

       fprintf(stream,"\n");
       fclose( stream );

       OutVolt (0, 0);                                                /*changed */

}

/* End of program */




9.2 Z Transform Manual Calculations on Paper

        The calculations begin on the following page. They were photocopied from my
lab partner since she had the original papers. The papers are all labeled according to their
lamda and sampling time. The Kalman equations are on the last two pages, also labeled.




                                                                                         46

				
DOCUMENT INFO