AN ARDUINO BASED PID FUZZY CONTROLLER FOR A ROBOT ARM PDF

Title AN ARDUINO BASED PID FUZZY CONTROLLER FOR A ROBOT ARM
Pages 7
File Size 316 KB
File Type PDF
Total Downloads 829
Total Views 892

Summary

Nguy n Hoài Nam và Đtg Tạp chí KHOA H C & CỌNG NGH 151(06): 179 - 185 AN ARDUINO BASED PID FUZZY CONTROLLER FOR A ROBOT ARM Nguyen Hoai Nam1, Dang Van Huyen2, Nguyen Viet Hung3 1 Hanoi University of Sciences and Technology, 2 College of Technology - TNU, 3 Electricity University SUMMARY In this ...


Description

Nguyễn Hoài Nam và Đtg

Tạp chí KHOA HỌC & CÔNG NGHỆ

151(06): 179 - 185

AN ARDUINO BASED PID FUZZY CONTROLLER FOR A ROBOT ARM Nguyen Hoai Nam1, Dang Van Huyen2, Nguyen Viet Hung3 1

Hanoi University of Sciences and Technology, 2 College of Technology - TNU, 3 Electricity University

SUMMARY In this paper, we design and implement an Arduino based fuzzy PID controller for a lab robot arm. A Sugeno fuzzy model will be used. The controller is based on the classical PID regulator, whose parameters, proportional, integral and derivative gains, are adjusted by fuzzy logic systems, separately. It is designed and executed on an Arduino Uno. A digital PID controller is also installed on the Arduino UNO to regulate the robot arm. The real time control result shows that the angular position of the link is closely equal to the setpoint and its characteristics are very good. The fuzzy PID gave better performances than the digital PID controller did. Keywords: Fuzzy, PID controller, Arduino, robot arm

Abbreviation PID PWM IMC Gas H∞ FLS Trimf

Proportional-Integral-Derivative Pulse Width Modulation Internal Model Control Genetic Algorithms H-infinity Fuzzy Logic System Triangular Membership Function

INTRODUCTION* Fuzzy theory was initially developed by Zadeh [1] in 1965. A decade later, the first fuzzy controller for a steam engine was proposed by Mamdani [2]. A novel fuzzy model was firstly introduced by Sugeno in 1985 [3]. This model gives an advantage on implementation of fuzzy logic system based on computer/microprocessor because of its easier defuzzification method. A typical example of Arduino based fuzzy controllers for a solar tracker can be found in [4]. In general, there are two types of fuzzy logic model: Mamdani and Sugeno. The latter will be used in this paper. There are a lot of different microcontroller families can be used to implement a fuzzy logic system, but Arduino family [5] proves to be a low-cost and open one. A brief introduction of the Arduino was presented in [6]. It is much easier to design and implement a PID controller when a mathematical model of *

Tel:

plant is availabe. Moreover, very good performances such as stability, fast setting time and less overshoot can be obtained. A PID controller was first invented by Nicholas Minorsky in 1922 [7, 8]. A tuning method for PID controllers [9] is proposed and examined by Ziegler and Nichols for the first time. Other methods of tuning PID controllers were also developed. Parameters of PID controllers were determined by using a fuzzy and neural network [10]. An optimal tuning of PID controllers method for a class of first order and time delay systems [11] was proposed. A design of PID controllers [12] was proposed for stable or unstable linear systems of arbitrary order with possible non-minimumphase and irrational characteristics and including significant time delay. A method of obtaining PID parameters [13] was proposed for general process models by approximating the feedback form of an IMC controller with a Maclaurin series in the Laplace domain. A PID controller tuning method [14] was proposed. This method was based on the fitting of the process frequency response to a particular second-order plus dead time structure. A review and new results of PID tuning rules [15] for second order plus dead time systems were presented. A tuning strategy [16] for robust PID controllers satisfying multiple H∞ specifications was proposed. A design of an optimal disturbance rejection PID controller [17] was presented by 179

Nguyễn Hoài Nam và Đtg

Tạp chí KHOA HỌC & CÔNG NGHỆ

using GAs. A share taken by PID controllers, estimated in [18], is more than 90%. A modern overview of functionalities and tuning methods in patents, software packages and commercial hardware modules was offered in [19]. An Arduino based PID controller [20] was much recently designed for the control of ionic polymer metal composite actuator. An Arduino based neural network controller [21] for the speed of a DC motor was implemented. In fact, there are many more other works but we just reviewed some most related ones. Our main contribution is to design and implement an Arduino based robot arm control system using fuzzy logic system, which is cheaper and able to be used for education and training purposes. In the next section, we introduce an one link robot arm with an Arduino based fuzzy controller. The third section presents some basic definitions of fuzzy logic systems, shows the structure of a fuzzy PID controller and describes how to build it. In section 4, a sketch for Arduino based fuzzy PID controller is presented and real time control responses are shown. The final section draws some conclusions and provides future work. ROBOT ARM CONTROL SYSTEM In this section, a real model of robot arm control system using Arduino UNO will be introduced and its operation will be presented. It comprises of a one link robot arm as a plant, an Arduino UNO as control device, an optical encoder as a position sensor and an H bridge as an actuator. It is shown as in Fig. 1. In this figure, the Arduino UNO and the H bridge are put inside a box, the DC motor is attached to a frame and the gear shaft is attached to one end of the link. The input to the robotarm is considered as voltage applied to the DC motor and the output from this system is defined as the angle of the link (in degree). The angular position of the robot’s arm link is firstly read via two channels (channel A and B) of an optical encoder wired to digital pins 180

151(06): 179 - 185

2 and 3 of the Arduino board. This Arduino Uno is used as a hardware for the digital fuzzy PID controller. Next, the control signal is calculated by a fuzzy PID control algorithm based sketch. Then, the signal is sent to a PWM pin and used to drive a DC motor via an H-bridge by PWM technique. A PWM voltage, proportional to the control signal, from the H-bridge is applied to the DC motor. Since a microcontroller is used, other control algorithms can also be programmed to regulate the position of the robot arm. This provides a flexibility in using advanced control algorithms.

Figure 1. Robot arm control system

An advantage of Arduino is that a computer can be indirectly used to control the plant via an Arduino. Fortunately, Matlab/Simulink provides an IO library for Arduino. Thus, we can setup the Arduino and do programming on Simulink to execute any control algorithm. Therefore, there are two options for using hardware: Arduino and computer/laptop. For this set of hardwares, it is also used to control other single input single output plants such as magnetic levitation systems, inverted pendulums, and even multi input multi output systems, for example, robotics and manipulators. FUZZY PID CONTROLLER In general, a fuzzy logic system includes three main components: fuzzification, If – Then rules and defuzzification. Behind the if–then rules are fuzzy operations such as fuzzy

Nguyễn Hoài Nam và Đtg

Tạp chí KHOA HỌC & CÔNG NGHỆ

complement, fuzzy union and fuzzy intersection. Any function that satisfies certain conditions can be used as a fuzzy operation, for example, MIN and PRODUCT for fuzzy intersection operations and MAX for fuzzy union operation. These functions are widely used in fuzzy logic system. There are two types of fuzzy models: Mamdani and Sugeno. In this work, we use Sugeno model [3] because of its simpler defuzzification method.

151(06): 179 - 185

ìï ïï ïï 0, if e < a or e > c ïï e - a trimf (e,[a; b; c]) = ïí , if a £ e < b ïï b - a ïï ïï e - c , if b £ e < c ïïî b - c

(3)

Five fuzzy sets for the input are used as follows: mE1 (e) = trimf (e,[- ¥ ; - 20; - 10]) mE 2 (e) = trimf (e,[- 20; - 10; 0]) mE 3 (e) = trimf (e,[- 10; 0;10]) mE 4 (e) = trimf (e,[0;10; 20]) mE 4 (e) = trimf (e,[10; 20; ¥ ])

Singletons for the outputs of the proportional part, the integral part and the derivative part are chosen as follows, respectively: P1 = - 97; P2 = - 50; P3 = 0; P4 = 50; P5 = 97; I1 = - 0.8; I 2 = - 0.4; I 3 = 0; I 4 = 0.4; I 5 = 0.8;

Figure 2. Fuzzy PID controller

D1 = - 0.1; D2 = - 0.07; D3 = 0; D4 = 0.07; D5 = 0.1;

A fuzzy PID controller can be described as a block diagram, which is shown in Fig 2. The controller contains three parts: fuzzy proportional part K P , fuzzy integral part K I and fuzzy derivative part K D . Each part is a fuzzy logic system (FLS), which is used as one of parameters of PID controller. The input to these FLSs is the error between the setpoint r and the robot arm position y : (1) e= r- y The outputs of these FLSs are fuzzily nonlinearly proportional to the input and the controller’s output comprises of these FLSs outputs as in Fig. 1: t

u = u p + K I ò edx + K D 0

de dt

The If-Then rules are designed as: If

e Î E1 Then u P = P1 ; K I = I1 ; K D = D1 ; OR

If

e Î E 2 Then u P = P2 ; K I = I 2 ; K D = D2 ; OR

If

e Î E 3 Then u P = P3 ; K I = I 3 ; K D = D3 ; OR

If

e Î E 4 Then u P = P4 ; K I = I 4 ; K D = D4 ; OR

If

e Î E 5 Then u P = P5 ; K I = I 5 ; K D = D5 ;

The outputs of FLSs are determined as below, 5

uP =

å

5

a i Pi / å a i

i= 1

5

KI =

å

5

a i Ii / å a i

i= 1 5

and K D =

å

Thus, these fuzzy gains are all dependent on the error. The If – Then rules are obtained from simulations in Matlab and practical tests. In this case, we use five triangular membership functions for the input and constants for each output of FLSs. These constants have different values for each FLS depending on each part. For convenience, the triangular membership function will be represented as follows,

(5)

i= 1 5

a i Di / å a i ,

i= 1

(2)

(4)

i= 1

(6)

i= 1

respectively, where a i = mEi (e) is a degree of membership. The integral term and derivative term in Eq. 2 can be approximated, respectively, as follows t

k

u I = K I ò edx » Ts å ei 0

uD = K D

(7)

i= 1

e - ek - 1 de » KD k dt Ts

(8)

where t = kTs , k is an integer, and Ts is sampling time. 181

Nguyễn Hoài Nam và Đtg

Tạp chí KHOA HỌC & CÔNG NGHỆ

The set of equations from Eq. (1) to Eq. (8) will be used to program. To carry out these FLSs on hardware, we need to use a computer or microprocessor. In this case, as mentioned above, we choose Arduino Uno as a platform to program these fuzzy algorithms since this microcontroller family is open both in hardware and software. In addition, it is a low-cost solution for experiments. The sketch will be clearly provided in the next section. SKETCH AND REAL TIME CONTROL The sketch includes three main components: setup, main program and functions. The whole sketch is written as follows: #include #define IN2 12 #define IN1 13 #define ENB1 9 long count=0; unsigned long timep, time, etime; boolean A, B; byte state, statep; float Output, kP, kI, kD, error, lastError; int Setpoint = 0; void set_point() {Setpoint=random(-180, 180);} void setup() { MsTimer2::set(2000, set_point); MsTimer2::start(); Serial.begin(9600); pinMode(2, INPUT); //Encoder Channel A pinMode(3, INPUT); //Encoder Channel B pinMode(7, INPUT); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT); pinMode(ENB1, OUTPUT); attachInterrupt(0,Achange,CHANGE); attachInterrupt(1,Bchange,CHANGE); timep = micros(); //set the initial time A = digitalRead(2); B = digitalRead(3); if ((A==HIGH)&&(B==HIGH)) statep = 1; if ((A==HIGH)&&(B==LOW)) statep = 2; if ((A==LOW)&&(B==LOW)) statep = 3; if ((A==LOW)&&(B==HIGH)) statep = 4; } void loop() { time = micros(); etime = time - timep; if (etime > 10000) { // etime is sampling time Ts plot(Setpoint,-map(count,-45424,45424,-180,180));

182

151(06): 179 - 185

Serial.println(map(count,-45424,45424,-180,180)); float errorSum, D, I; error = map(count,-45424,45424,180,180)+Setpoint; fuzzy (); // Calculate PID parameters based on FLSs errorSum + = error*etime; I=kI*errorSum; // integral part D=kD*(error-lastError)/etime; // derivatie part Output = kP + I + D; // Controller’s output If (Output>0) { digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH);} else if(Output=255) Output=255; if(Output...


Similar Free PDFs