You are on page 1of 4

PID ALGORITHM/ Mathematical model

The Algorithm is based on the following configuration of proportional, integral and derivative
action to achieve PID action. The advantage of using this configuration is that we can have
separate controls to vary KP and KD (not possible in any of the other design).

The complete difference equation algorithm that provides the PID controller is obtained by
adding the three terms to obtain [we use x (kT) = x (k)]

u(k) = KP x(k) + (KD/T) [x(k) – x(k – 1)]

We have chosen the manipulated output to comprise of 8 bits which translates to 255 discrete
levels. The limit is applied for both positive and negative PID values. If the PID value is greater
than 255 then it limits it to 255 If lesser than -255 then limits it to -255, whether positive or
negative, exceeds a value greater than +/- 255, it is truncated and considered as only +/- 255.
This removes integral windups that occur due to the integral action.[3] We send a single byte at
a time as the PWM signal to the servo motors. After that, the scaling is carried out for
manipulated output in order to get both the clockwise and anticlock wise rotation of actuators.
[3][4] As the maximum value for 8-bit processing is 255 so we used half of it 0-128 for
clockwise and 128-255 for anticlockwise motion of actuators as

Anticlockwise motion = 128 + (manipulated output/0.5)

Clockwise Motion = 128 - (manipulated output/0.5).


For sir jillani reference

The mathematical method for tuning the pid controller is based on Ziegler- Nichols method
which is described as below

They proposed two methods but we have used only closed loop method

Ziegler-Nichols closed-loop tuning method

The Ziegler-Nichols closed-loop tuning method allows you to use the ultimate gain value, Ku,
and the ultimate period of oscillation, Pu, to calculate Kc . It is a simple method of tuning PID
controllers and can be refined to give better approximations of the controller. You can obtain the
controller constants Kc , Ti , and Td in a system with feedback. The Ziegler-Nichols closed-loop
tuning method is limited to tuning processes that cannot run in an open-loop environment.

Determining the ultimate gain value, Ku, is accomplished by finding the value of the
proportional-only gain that causes the control loop to oscillate indefinitely at steady state. This
means that the gains from the I and D controller are set to zero so that the influence of P can be
determined. It tests the robustness of the Kc value so that it is optimized for the controller.
Another important value associated with this proportional-only control tuning method is the
ultimate period (Pu). The ultimate period is the time required to complete one full oscillation
while the system is at steady state. These two parameters, Ku and Pu, are used to find the loop-
tuning constants of the controller (P, PI, or PID). To find the values of these parameters, and to
calculate the tuning constants, use the following procedure:

Closed Loop (Feedback Loop)

Remove integral and derivative action. Set integral time (Ti) to 999 or its largest value and set
the derivative controller (Td) to zero.

Create a small disturbance in the loop by changing the set point. Adjust the proportional,
increasing and/or decreasing, the gain until the oscillations have constant amplitude.

Record the gain value (Ku) and period of oscillation (Pu).

Figure 1. System tuned using the Ziegler-Nichols closed-loop tuning method


4. Plug these values into the Ziegler-Nichols closed loop equations and determine the necessary
settings for the controller.

Table 1. Closed-Loop Calculations of Kc, Ti, Td

Advantages

Easy experiment; only need to change the P controller

Includes dynamics of whole process, which gives a more accurate picture of how the system is
behaving

Disadvantages

Experiment can be time consuming

Can venture into unstable regions while testing the P controller, which could cause the system to
become out of control

Motor specifications

Futaba s3003

Control System: +Pulse Width Control 1520usec Neutral


Required Pulse: 3-5 Volt Peak to Peak Square Wave
Operating Voltage: 4.8-6.0 Volts
Operating Temperature Range: -20 to +60 Degree C
Operating Speed (4.8V): 0.23sec/60 degrees at no load
Operating Speed (6.0V): 0.19sec/60 degrees at no load
Stall Torque (4.8V): 44 oz/in. (3.2kg.cm)
Stall Torque (6.0V): 56.8 oz/in. (4.1kg.cm)
Operating Angle: 45 Deg. one side pulse traveling 400usec
360 Modifiable: Yes
Direction: Counter Clockwise/Pulse Traveling 1520-1900usec
Current Drain (4.8V): 7.2mA/idle
Current Drain (6.0V): 8mA/idle
Motor Type: 3 Pole Ferrite
Potentiometer Drive: Indirect Drive
Bearing Type: Plastic Bearing
Gear Type: All Nylon Gears
Connector Wire Length: 12"
Dimensions: 1.6" x 0.8"x 1.4" (41 x 20 x 36mm)
Weight: 1.3oz. (37.2g)
Motor control

The servomotors have built-in stops that limit the angular motion of the rotors to any value
equal to or less than 180 degrees. For our purpose, the maximum angular displacement of the
motors has been limited to 30 degrees. The servomotors use metallic gear combinations which
allow them to bear loads requiring up to 4.1 kg/cm of torque. These two servo motors are
connected to arm linking mechanisms which are exactly perpendicular to each other. One
servomotor tilts the plate in ‘X-axis’ and the other in ‘Y-axis’. Position of servomotor is
controlled by the duty cycle. The rotors of the servomotors measure 3cm from the motor axis to
the axis of the linkage rods.

Pulse width duty / ms Angle / degrees


0.5 0
1.0 45
1.5 90 (center)
2.0 135
2.5 180

GUI

The GUI is based on the principle of position sensing like hyper terminal. We have interlinked
our PID controller based on C# language to our GUI which is also in C#. We input the values
being extracted from the touch screen controller i.e a 13 bit code representing the coordinate of
the ball on screen.

Whenever there is a mouse event a program code in the background calculates that event’s
displacement from the mid point of the screen and on the screen you can see the graphical ball
moving from its mean position towards the mouse event and it traces the event throughout the
process in which the controller is shifting the plate so that the ball is balanced at the mean
position.

The angle generated by PID controller is also shown on our GUI. This is achieved by outputting
the values simultaneously to the motor controller and to the GUI code which converts that string
value into a number representing an angle.

You might also like