Manual
Manual
February 2023
1 Introduction
The goal of this session is to control the position of a ball on a V-shaped beam using a PID controller. The beam is deflected using a
servo motor to make the ball roll back and forth on the beam. The computer is used as the controller and a microcontroller is used
to drive the servo motor. A USB connected webcam is used as a feedback sensor to read the position of the ball. Performing different
measurements and analyzing the measured data will help to understand the various aspects of the practical implementation of the PID
controller.
2 PID-Controller
PID controller is a part of a feedback control system. In a feedback control system, the output of the system, also known as process
variable, is measured by a sensor and used to compare with the desired value, also known as set-point. The difference between the
desired value and process variable is known as error signal. The main role of the controller is to manipulate the error signal in such a
way that the actuator drives the process variable towards the desired value, and the error will ultimately converge to zero. PID stands
for Proportional, Integral and Derivative, respectively.
2.1 Algorithm used to design the controller
There exist several types of representation of PID algorithm. Series representation, standard representation and parallel representation
are widely known representations. Because of convenience, the algorithm of the ideal/ standard representation is used to design the
controller for this setup. This representation (Figure 2) is compatible for manual tuning as well as the different available tuning
techniques like Ziegler-Nichols-open -and closed loop tuning. This is the main reason that ideal representation of PID controller has
also been used in the exercise sessions of the course. In the proportional branch of a PID controller the error signal is multiplied with
𝐾 gain. Integral controller keeps averaging the gained error with 𝑇 time constant. In the derivative branch the rate of change of the
error signal is multiplied with the gain times time constant 𝑇 time constant. The faster the error signal is changing the larger the
output of the derivative path.
1
Figure 3: Derivative controller without -and with low-pass filter. Left: Transfer characteristic of an ideal D controller. Right: Transfer characteristic of an
ideal D controller with a low pass filter.
3.2 Derivative kick
While controlling a system, a reference value is set and the controller drives the process variable towards reference value. Throughout
this process the reference value is constant and plays no role in derivative controller. But if the reference value is set to new value than
there will be a sudden change which triggers the derivative path to react to this sudden change abnormally. In the derivative, this is
called derivative kick. To avoid this derivative kick, derivative path can be subjected to the measured signal instead of the error signal
as error signal is the difference between the reference value and measured value.
2
4 Introducing the measurement setup
4.1 Acquiring the position of the ball using camera and computer.
The open-source library, opencv2, is used in python to track the ball by detecting the color of the ball. The color of the ball is
represented in HSV (Hue, Saturation and Value) color space which is widely used in computer vision and image analysis. Hue
represents the dominant color observed through the eye. Saturation indicates the amount of the white light mixed with Hue. Value
represents the darkness of the color the lower the value the darker the color. Once the HSV color range of the ball is known, the ball
moving on the beam can be tracked.
4.2 Using the computer as a controller
Once the actual position of the ball and the desired position of the ball is known, the error signal is calculated and used as the input to
the controller. There are various options available to activate the different path of PID controller.
4.3 Using the Arduino as the driver
The Arduino is used to take the value from the serial port and sent it to the servo motor as it is straightforward to drive servomotor.
With the help of the servo library of Arduino, it is possible to send the desired angle to the servo motor using one of the PWM pin of the
Arduino.
4.4 Servomotor as an actuator
The servomotor is used to tilt the beam up and down to let the ball move back and forth. A servo works as an integrator. This means
that the servo motor integrates the input signal. If the input signal of the motor is position, the output signal will be displacement.
If the desired output is for instance position than the input signal should be the derivative of the position.
Figure 6: Position as an input signal to servo motor gives displacement as output signal (above). Derivation of position as an input signal to the servo
motor results in position output due to the integrator nature of the servomotor (below).
4.5 Signals throughout the closed loop
The reference value is given by the user which will obviously be in the unit of length: cm. The position of the ball is measured in
pixels by the camera. The length of the beam should be measured in cm and it should be used to convert the unit of position of the
ball in cm. As both reference value and process variable are in cm the error signal will be in cm. The error signal is fed to the controller
and the controlled output will be in cm as well. The controller output should be fed to the actuator. Here the servomotor is the
actuator thus the signal in the unit of length should be converted into the angle of the servo arm (°). When the signal is position and
fed into the actuator, it should be differentiated (see Figure 6). This should be done because the servo motor works as an integrator.
3
5.2 Calibrating the camera
1. Click on camera calibration button to open a new window to connect the camera. Input for the camera number is an index
number of the camera, starting from 0. Using the next step (6.1.3), find out what is the right camera index (start with 0, then 1,
etc.)
2. Click on Open HSV window. This will open the window where there are six sliders on the top of the window and three frames at
the bottom of the window. The goal is to find the HSV color range of the ball. By sliding the slider of H, S and V for lower and
upper bound you should try to eliminate all colors except the color of the ball. Only the ball should be white on the left frame
and only the ball should be seen on the right frame. First of all, try to find the range of the color seen by our eyes. This is done
by sliding L-H slider and U-H slider. The lightness and darkness can be than adjusted by slider L-S,U-S and slider L-V,U-V
respectively. Once this is done, click on X button to close the window. This will save the determined HSV value to a file which
will be accessed by the program while connecting camera on further steps.
Figure 8: GUI showing the position of the ball[cm] after camera calibration.
The system is now ready to start. The goal is to find the tuning parameters by using different methods. There are nine sliders
available to change the reference point, deadband for error, K, τI, τD, τF , maximum deflection angle, deadband for the angle and
dead time for servo motor respectively from left to right. Dead time for the servo motor means the time between two signal sent by the
controller to the Arduino to drive the servo motor. Servo typically takes 0.1 sec to rotate about 60° angle. Thus, estimate a suitable
dead time based on the range of the operating angle that you calculated while calibrating the system. Different buttons are available
which act as switches to connect or disconnect any branch. There is also a drop-down box available with various options from
which you should be able to choose the right one. There is also a button called record data available to save the data as a .csv file
which can later be used to make necessary calculations. There is an Overview of the GUI available on the teaching website which
gives an overview of different objects used on the GUI.
The goal of this session is to understand the role of each blocks representing the part of the closed loop by analyzing the signal flowing
through it. For example, what happens when the signal flows through ideal derivative controller and what happens when the LPF is
activated.
4
5.3 Manual tuning
Manual tuning is performed by changing the controller parameters and observing the response of the system. Some practical
observations:
1. Proportional controller multiplies the error signal with some constant K. When the error is large, the output signal from the
proportional controller is also large but when the error gradually degrade the output signal is also small. The system comes to
an equilibrium with some static error. Increasing the gain decreases the static error but the overshoot increases and the
stability of the system decreases.
2. Integral controller is used to eliminate the static error from the system. It is done by summing up the error over time which
accumulates the signal. Thus, even the tiniest error presence in the system will eventually force the con- troller to correct it. On
the other hand, the integral controller will cause an overshoot and the stability of the system decreases.
3. Derivative controller reacts to the rate of change of the error. Thus, increasing the parameter τD will help to decrease the
overshoot.