a low-cost control system experiment for engineering ... · a low-cost control system experiment...

19
Paper ID #17725 A Low-Cost Control System Experiment for Engineering Technology Stu- dents Dr. Curtis Cohenour Ph.D., P.E. P.E., Ohio University Dr. Cohenour is an Assistant Professor in the Ohio University Engineering Technology and Management Department, in Athens, Ohio. He received a Bachelor of Science degree from West Virginia Institute of Technology in 1980, a Master of Science degree from Ohio University in 1988, and a Ph. D. in Electrical Engineering from Ohio University in 2009. He is a registered professional engineer in West Virginia, and Ohio. Dr. Cohenour has worked in Industry as an electrical engineer and project manager. He joined Ohio University in 2002 as a research engineer working for the Ohio University Avionics Engineering Cen- ter. He has worked on projects covering a wide variety of avionics and navigation systems such as, the Instrument Landing System (ILS), Microwave Landing System (MLS), Distance Measuring Equipment (DME), LAAS, WAAS, and GPS. His recent work has included research with the Air Force Research Laboratory in Dayton, Ohio, aimed at understanding and correcting image geo-registration errors from a number of airborne platforms. c American Society for Engineering Education, 2017

Upload: lekien

Post on 09-Sep-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: A Low-Cost Control System Experiment for Engineering ... · A Low-Cost Control System Experiment for Engineering Technology Students Abstract A low-cost control system experiment

Paper ID #17725

A Low-Cost Control System Experiment for Engineering Technology Stu-dents

Dr. Curtis Cohenour Ph.D., P.E. P.E., Ohio University

Dr. Cohenour is an Assistant Professor in the Ohio University Engineering Technology and ManagementDepartment, in Athens, Ohio. He received a Bachelor of Science degree from West Virginia Institute ofTechnology in 1980, a Master of Science degree from Ohio University in 1988, and a Ph. D. in ElectricalEngineering from Ohio University in 2009. He is a registered professional engineer in West Virginia, andOhio.

Dr. Cohenour has worked in Industry as an electrical engineer and project manager. He joined OhioUniversity in 2002 as a research engineer working for the Ohio University Avionics Engineering Cen-ter. He has worked on projects covering a wide variety of avionics and navigation systems such as, theInstrument Landing System (ILS), Microwave Landing System (MLS), Distance Measuring Equipment(DME), LAAS, WAAS, and GPS.

His recent work has included research with the Air Force Research Laboratory in Dayton, Ohio, aimed atunderstanding and correcting image geo-registration errors from a number of airborne platforms.

c©American Society for Engineering Education, 2017

Page 2: A Low-Cost Control System Experiment for Engineering ... · A Low-Cost Control System Experiment for Engineering Technology Students Abstract A low-cost control system experiment

A Low-Cost Control System Experiment for Engineering Technology

Students

Abstract

A low-cost control system experiment is presented. The plant for the control system is a modified Radio Control (RC) servo. The servo is modified by removing the controller, then bringing the two motor leads, and the three potentiometer (pot) leads outside the servo case. The motor and pot are connected to an Arduino Uno R3. Inputs for auto manual selection, manual inputs, and additional pots are connected for reference and gain adjustments. This experiment is part of an electronics course in Engineering Technology and Management (ETM). The electronics course uses the Arduino Uno R3 to teach electronics, real time programing, and with this experiment, PID control. There is no time allotted in this course for traditional frequency based or time based control system design, but this simple set up allows the student to experience many of the situations that arise in industrial control systems. The student learns about input, output, feedback, and control. The first step for the student is to move the servo by hand and observe the feedback from the pot. The student then runs the motor and observes the direction. The student can then determine the sign of the feedback, and implement manual control. The motor is connected to two Arduino outputs. This creates an H-bridge. Dead-band control is implemented by setting the outputs high and low for one direction, low and high for the reverse, and low and low for stop. The student sets the dead-bands to allow the servo output to follow a reference pot. At this point the student has performed his/her first control system startup and likely experienced many of the challenges of commissioning a control system. The Arduino outputs connected to the motor are capable of Pulse Width Modulation (PWM). Proportional output is achieved by setting one output pin low, while the other is controlled using PWM. This allows proportional control of the motor in either direction. The student can now implement proportional only control. The student can turn the pot by hand and feel the control system response. This gives the student a direct kinesthetic learning experience. Advanced learners can now add integral and derivative control. The addition of integral control forces the student to understand initialization and integral windup. The student writes the Proportional Integral Derivative (PID) control algorithm such that auto/manual transitions and gain changes are bumpless. The addition of the control system experiment cost less than $5.00 per student, but provides the student with a realistic control system problem complete with all of the vagaries of an in-plant control system commissioning. Introduction

Engineering Technology and Management (ETM) students fill many roles in the work force. ETM students are generalist and most will become involved with control systems at some time during their career. The control system experiment described here is designed to give the

Page 3: A Low-Cost Control System Experiment for Engineering ... · A Low-Cost Control System Experiment for Engineering Technology Students Abstract A low-cost control system experiment

students a working understanding of a control system so they are prepared for positions in industry. Typical roles for ETM graduates include operations, maintenance, sales, supervision, and quality. Each of these roles may include some involvement with control systems. Students employed as operators will use equipment with feedback control mechanisms. Maintenance employees will be required to diagnose and repair control equipment. Supervisors will have operational, or maintenance duties over controls systems. Sales personnel will represent automated machinery, controls components, or control equipment. Quality engineers will use manual control systems where quality data is used to modify the process in some way to maintain quality. Not every student will be a controls engineer but all are likely to benefit from the experience. ETM students at our university are required to take an electronics course. The course is taught using the Arduino [1]. The focus of the course is on electronics and real time programming. The course teaches students electronics, schematics, circuit analysis, programing, and how to use a breadboard. This lab experiment leverages the existing course materials and implements a Proportional Integral Derivative (PID) controller using software in the Arduino. Existing methods of teaching control systems particularly in electrical engineering involve too much math for our ETM students. The students take physics, chemistry, and a first course in calculus, but have no application specific knowledge of integration, differentiation, phasors, or frequency domain techniques. Thus, we must provide the students with application specific training. The lab experiment described here focuses on working knowledge such as vocabulary, block diagrams, startup, and tuning. The lab experiment seeks to teach the students what a control system is, how it works, and how to use it. The students write code in the Arduino to implement a PID controller. The focus is on heuristics rather than theory. This lab was inspired by Ray’s paper [2] “An Inexpensive Control System Experiment: Modeling, Simulation, and Laboratory Implementation of a PID Controller-Based System”. This one to two week lab uses an electronic model of a mass spring damper system as the plant, and a PID controller to teach controls. Both the plant and the PID are constructed on a bread board with operational amplifiers (op amps) and discrete components. Matlab© SIMULINK is also used to simulate the control system. An oscilloscope is used to show the system response. Our students have no familiarity with op amps or Matlab© SIMULINK. The focus of our course is real time software so we would like to use the software to implement the PID. Again because the students have no familiarity with op amps we would like to have a different plant. In this case a modified RC servo as will be described. Kiefer [3] describes a similar challenge with the mathematics of controls systems and teaches many of the items needed for Ray’s approach. He describes a six part lab for mechanical engineering students in which he covers electrical components, op amps bread boards, and circuits. Our students cover all of this material with the exception of op amps. The course by

Page 4: A Low-Cost Control System Experiment for Engineering ... · A Low-Cost Control System Experiment for Engineering Technology Students Abstract A low-cost control system experiment

Kiefer is self-paced and there is no mention of how long it takes a student to complete the course. Content and Format

The content and format of this paper may be unfamiliar because a great deal of the technical detail is contained in the lab document. Rather than repeat or rewrite the lab content it is included in its entirety Appendix 1. The Arduino start code for the course is included in Appendix 2. Readers interested in the technical details are encouraged to read the lab in addition to the paper. Those wishing to duplicate the lab can start with the code in Appendix 2. The goals, or student outcomes are presented first. This is followed by as description of the lab including a few technical details that are explained in the lectures but not in the body of the lab. This is followed by a description of a trial run through the lab with a group of three students. The results of the trial are assessed based on an assignment given after the first hour of the lab, and a survey given at the end of the class. This is followed by a summary and conclusions. Student Outcomes

The desired student outcomes are as follows:

1. Explain what a control system is and give examples

2. Analyze a control system and identify Plant, Input, Output, Feedback, Setpoint, Controller

3. Design and implement controls including Manual, Dead-band, Proportional, Proportional /

integral and PID

4. Startup and trouble shoot a control system

5. Recognize States and know how to initialize them

First we would like the students to know what a control system is and give some examples. As instructors we may take for granted what a control system is but for a student with no prior experience of what a control system is there will be questions. Once the student can identify a control system, the questions are then, what are the parts, how do they interact? Figure 1 shows a student response to the question: Give an example of a control system and label the following: plant, controller, feedback, setpoint, error. This question was given as an exercise after the first lecture. The single loop PID is normally what engineers think of when you say the word “controller” but there are many other types of controllers. The PID is just a good solution to a large number of problems. Other types include manual control, Dead-band control, and Proportional control. The students will be starting at the beginning so simpler controls are an ideal step before trying to program the PID. Having worked on many control systems in industry the first step of any controls system is startup, checkout. Once the system is operational then maintenance and troubleshooting are required. The author’s recommendation for startup is included in the lab. Nothing is ever perfect so the student will invariably run into trouble and have to troubleshoot the system.

Page 5: A Low-Cost Control System Experiment for Engineering ... · A Low-Cost Control System Experiment for Engineering Technology Students Abstract A low-cost control system experiment

Finally, there is the concept of a state. An integral is a state. The derivative requires a state. The meaning of integral and derivative may be unclear to the student at this point but they can appreciate that these values that are passed from one iteration of the control to the next. It is important for students as future control engineers to recognize a state and insure it is properly initialized.

Figure 1 A student response to the question: Give an example of a control system and name the parts. A list of the parts

underlined by the student is given.

Lab Technical Description

An annotated photograph of the experimental setup is give in Figure 2. The schematic is given in the lab document Appendix 1. The plant is an RC servo, the controller is the Arduino. Potentiometers (pots) are used for the reference, the gains, and the feedback from the servo. There is an auto/manual switch and manual increase and decrease pushbuttons (PBs). There are two types of inexpensive servos available from popular internet sources. First is the RS001b 9g servo. This is a 180° servo with hard stops at the end of the rotation. The second is the RS001a 8g servo. This servo has no stops and will rotate continuously without stalling the motor. The pot will only turn about 210° before it slips on the output shaft. With the RS001a the motor will not stall. This is a significant advantage over the RS001b. During start up the RS001b will likely stall and could destroy the Arduino outputs.

Page 6: A Low-Cost Control System Experiment for Engineering ... · A Low-Cost Control System Experiment for Engineering Technology Students Abstract A low-cost control system experiment

Figure 2 An annotated photograph of the Arduino based control system setup.

A typical RC servo is shown in Figure 3. There are three leads to the servo, in this case colored red, black and white. Note colors vary but in this case the red lead is +5V, the black lead is ground, and the white lead is the signal. To make the unmodified servo operate a pulse with a width between 0.7 and 2.0 ms repeated every 20ms is applied to the signal. Changing the width of the pulse changes the position of the output arm. There is a control circuit that drives the motor based on the width of the pulse. For this lab the servo is controlled by the Arduino so the control circuit is removed and discarded. The three leads are soldered directly to the pot with the white lead applied to the wiper, A0 in Figure 3. The motor is connected to a red and black wire and brought outside of the case. The servo looks unchanged in Figure 2, but it will never operate as an RC servo again.

Page 7: A Low-Cost Control System Experiment for Engineering ... · A Low-Cost Control System Experiment for Engineering Technology Students Abstract A low-cost control system experiment

Figure 3 Components of an RC servo. For use in this lab the controller is removed and the two motor lead, and three pot leads

are brought outside of the case. Servo image from [4]

The servo is small and the work must be done inside of the servo case. If the pot or the motor are removed to solder the leads the gearbox cannot be reassembled. In the author’s opinion this modification (hack), cannot be performed by a student. In addition the breadboard in Figure 2 was wired by the author. The breadboard could be wired by the student but that would have slowed execution of the trial. The pot is connected to A0 of the Arduino. The motor is connected to D5 and D6 of the Arduino as shown in Figure 4. This configuration is commonly known as an H-Bridge. Each of the Arduino outputs can be either high or low. To stop the motor one sets both outputs low, or both high. There will be no voltage across the motor and the motor will stop. Actually the motor will be in dynamic braking mode, but that is beyond the scope of this paper or this lab. To make the motor go Counter Clockwise (CCW) set D5 high and D6 Low, the voltage across the motor will be higher on the left. To make the motor go Clockwise (CW) the polarity is reversed by setting D6 high and D5 low. This is used for the dead-band control. The motor runs full speed CW or CCW, or stops based on the outputs D5 and D6.

Page 8: A Low-Cost Control System Experiment for Engineering ... · A Low-Cost Control System Experiment for Engineering Technology Students Abstract A low-cost control system experiment

Figure 4 Connection of the "hacked" servo motor to the Arduino. Top is stop, middle is CCW, and bottom is CW.

This works fine for dead-band control but for proportional or PID we need to run the motor at less than full speed. D5 and D6 can be operated in Pulse Width Modulation (PWM) mode. In PWM the output is a series of rectangular pulses at 490 Hz with a duty cycle of 0 to 100%. The PWM mode is available using the analogWrite(pin, duty) function, where pin is the pin number 5 or 6 and duty is an integer between 0 and 255 for 0 to 100% duty cycle. To go CW at half duty cycle D5 is set low, and D6 is set to PWM analogWrite(6, 128). In this way a proportional output is achieved. With the information above interested readers are referred to the lab document in Appendix 1. Lab parts 1-3 are recommended. Parts 4 and 5 are for those who would like the complete experience. Lab Trial

The lab is designed to fit within the existing electronics course. The course includes all of the necessary requisite skills: Arduino coding and hardware, schematics, circuit analysis, and breadboards. The course runs for fifteen weeks, and meets twice a week. There are currently 11

Page 9: A Low-Cost Control System Experiment for Engineering ... · A Low-Cost Control System Experiment for Engineering Technology Students Abstract A low-cost control system experiment

labs and a final project. The labs are one week each and the final project is three weeks. This leaves one week of slack for holidays, etc.… To include this lab some other topic must be dropped. To determine the value to the students, and the feasibility of including this material the lab was tested. The lab was tested with three students at the end of the fall 2016-17 term. The students were selected based on class rank top, middle, lower, and willingness to participate. The offer was made to three students and all accepted. The students were asked to take an online learning styles questionnaire [5], do one assignment and take a survey. The author assumed that the students would be kinesthetic learners based on the ETM major being a very hands on curriculum. The learning styles revealed that the author and the students were all visual learners. The author scored 11 while the students scored 9 7 and 5 on the visual scale of Index of Learning Styles Questionnaire [5]. With this observation the course power point slides were modified to focus on block diagrams to appeal to visual learners, as in Figure 5.

Figure 5 Block diagram of the Dead-band control. This slide developed to support students with a visual learning style.

The lab has many hands on features that should appeal to kinesthetic learners. The students can move the servo arm by hand and see the pot values change on the Arduino’s Integrated Development Environment (IDE) serial monitor. The student can feel when the servo pot reaches its end of travel. The student can move the servo arm in dead-band control and compare that with manual and proportional control. The students can hear, feel, and see what happens as the gain is changed. The lab was held for one hour per week for three weeks. The students were given prewired breadboards with the modified servo. The lab consisted of check out and coding of the various control modes as described in the lab. In addition, the students were given the start code in Appendix 2. This allowed the students to focus on the PID control and not the wiring or the

Page 10: A Low-Cost Control System Experiment for Engineering ... · A Low-Cost Control System Experiment for Engineering Technology Students Abstract A low-cost control system experiment

servo modification. As mentioned before the modification of the servo is not something a student at this level of experience could perform. The students at the end of the electronics course could wire the breadboard. The students enjoyed the lab and two of the three wanted to do a fourth hour during finals week to complete the PID portion of the lab. Additional results and comments are included in the next section. Student Assessment and Outcomes

The three students participating in the trial lab experiment completed parts one, two, three, and four of the lab. This includes start up, manual control, dead-band control, and proportional control. In addition the lecture on the PID, part 5 was given but the students did not work on this part. After completing the proportional control the students were asked to demonstrate their controls. The students had no problems responding to the following questions:

1. Show the impact of high gain. (the servo oscillates)

2. Show how the controls responds to a disturbance. (try to turn the servo by hand)

3. How does the gain impact this?

4. Show that the control is bumpless when turned on.

A course evaluation was given at the end of the lab trial. The scale is 1-5 where 1 is Strongly Disagree and 5 is Strongly Agree. The results are in given in Table 1. Questions one through five are about the technical content of the course. Questions six through ten are about the presentation and the insertion of the lab into the existing electronics course. Note that all students felt that they knew what a control system is. The student response to questions two through four indicate that two of students were confident in their ability to perform control systems work. Question five indicates a slight desire to perform control system work in their post college career. Table 1 Results of Couse Evaluation Response 1-5 Indicates Strongly Disagree to Strongly Agree

Quest.

Num. Question

Student Mean Median

1 2 3

1 I know what a control system is. 5 5 5 5.0 5

2 I could trouble shoot and tune a control system. 3 4 4 3.7 4

3 I could start up a control system. 2 5 4 3.7 4

4 I could design and implement a control system. 2 4 4 3.3 4

5 I would like to work with control systems as part of my

job. 3 4 3 3.3 3

6 The PID should be included in ETM electronics course. 3 3 4 3.3 3

7 Students should be required to wire the PID

breadboard. 4 3 3 3.3 3

8 The lectures and Power Point slides were useful. 5 5 4 4.7 5

9 I referred to the Power Point slides. 5 5 5 5.0 5

Page 11: A Low-Cost Control System Experiment for Engineering ... · A Low-Cost Control System Experiment for Engineering Technology Students Abstract A low-cost control system experiment

10 I watched the lecture capture. 1 1 1 1.0 1

The students found the lectures and Power Point slides useful as indicated in questions eight and nine, but did not use the lecture capture as indicated by the response to question ten. The students suggested only mild support for including the course in the existing electronics course. This is also addressed in the student comments below:

Student Comments

“I feel like you learn a lot about control systems through this lab and I have no doubt

that people could do part 1. However I would probably make the next 2 parts a second

part because it is a lot of information to take in.”

“The PID lab was good for this course because it was complex and it also was a good

example of how electronic controls can be used in industry and other applications of

control systems.”

Summary and Conclusions

A control systems lab was developed for ETM students using a modified RC servo, as a possible lab for an existing Arduino based electronics course. The cost of the added components is low but there is considerable labor involved in the servo modification. The lab was tested and the students performed well. The trial run showed that three weeks would be needed to cover this lab. This is similar in magnitude to the final project. The first week would be devoted to wiring and testing the control circuit. The second week for doing manual and dead-band control, and the third week for the proportional control. Additional time would be required for the PID portion but this could be reserved for students that finish the other components early. The benefit probably does not justify the inclusion of the PID lab into this course however, there are some other options. The lab could be included in one of three other classes. Our curriculum includes an automation class, a robotics class, and an elective PLC class. In addition, we are starting and ATMAE Robot Competition Course for spring of 2016-17. The current plan is to include the PID lab in the ATMAE Robot Competition Course. There are fewer students, three teams of five, and the students can use the control skills in the Robot Design Course.

Page 12: A Low-Cost Control System Experiment for Engineering ... · A Low-Cost Control System Experiment for Engineering Technology Students Abstract A low-cost control system experiment

Bibliography

[1] Arduino S.r.l. , "Arduino," 2016. [Online]. Available: http://www.arduino.org/. [Accessed 2016].

[2] B. Ray, "An Inexpensive Control System Experiment: Modeling, Simulation, and Laboratory Implementation of a PID Controller-Based System," in Proceedings of the

ASEE's 123rd Annual Conference and Expositiion, New Orleans, 2015.

[3] S. Kiefer, L. Silverberg, J. Thrower and K. Kelmer, "Teaching Undergraduate Controls to Non-Electrical Engineering Students," in Proceedings of the 2001 American Society for

Engineering Education Annual Conference & Exposition, Albuquerque, 2001.

[4] Jameco Inc., "How Do Servo Motors Work," [Online]. Available: http://www.jameco.com/jameco/workshop/howitworks/how-servo-motors-work.html. [Accessed 7 March 2017].

[5] B. Soloman and R. Felder, "Index of Learning Styles Questionnaire," 2016. [Online]. Available: https://www.webtools.ncsu.edu/learningstyles/. [Accessed 2016].

Page 13: A Low-Cost Control System Experiment for Engineering ... · A Low-Cost Control System Experiment for Engineering Technology Students Abstract A low-cost control system experiment

12

Appendix 1 Name: __________________________

CONTROLS

ARDUINO PID LAB

Overview:

Control systems are everywhere. Your home thermostat is a control system. In the winter if the

temperature is too low the furnace comes on. When the house warms up the heat goes off. This is a

form of dead-band control. In the summer the thermostat controls the air-conditioning in a similar

manner but the sign of the feedback is reversed. Industrial controls include liquid level control, reactor

temperature control, gauge (metal thickness) control, position control, and an endless list of others. In

this lab we will do position control using the motor, gear train, and potentiometer from an RC servo.

Every control system has four parts. These are:

• Plant - this is the physical system you are controlling (a reactor)

• Feedback – this is a measurement of the Process Variable (temperature)

• Setpoint – this is the desired value for the Process Variable (temperature)

• Input – this is the means by which you can change the process variable (steam valve)

• Controller – The mechanism that changes plant input to create a change in the feedback

In our experiment the plant is the motor gear box and pot. The feedback is the voltage from the pot. The setpoint is the position we want to move the servo arm to. The plant input is the signal we send to the motor, and the controller is part of the Arduino software. Lab part 1 Startup:

Before we can startup a process we must check all of the I/O. The schematic is shown in Figure 6. We want all of the pots including the feedback, reference and gain pots to generate an increasing voltage to the Arduino when they move clockwise. Verify that the auto manual switch and the manual inputs generate a true inside of the Arduino. Make sure the motor rotates the servo arm CW when digital output 6 goes high, and CCW when output 5 goes high. The feedback pot should read near 512 counts when the servo arm points away from you. This servo has no stops so it is difficult to damage the Arduino outputs but it could happen so use care. Go through the schematic, Figure 6, and check each item. If you need to make a correction use a red pencil. When an Item is checked use a yellow highlighter to indicate that the item is connected and operating properly inside of the Arduino. Use the PidRoot01.ino as a starting point.

Page 14: A Low-Cost Control System Experiment for Engineering ... · A Low-Cost Control System Experiment for Engineering Technology Students Abstract A low-cost control system experiment

13

Figure 6 PID Lab Schematic.

Page 15: A Low-Cost Control System Experiment for Engineering ... · A Low-Cost Control System Experiment for Engineering Technology Students Abstract A low-cost control system experiment

14

Lab part 2 Manual control:

Typically industrial controls have a manual and auto mode. In manual the operator controls the action. In our case there are two pushbuttons increase (CW) and decrease (CCW). The motor is connected in and H-bridge. Turning D6 on and turning D5 off will cause the motor to go CW. Setting D5 high and D6 low will reverse the motor (ccw), and setting both D5 and D6 low will stop the motor. Write software to control D6 and D5 with the pushbuttons. If the motor runs the wrong way reverse the leads going to the motor. Set up software limit switches so that you cannot run past the ends of the servo pot. Try not to let it go below 100 or above 924. This is important because there may be some coasting. Once you have the motor outputs working you can highlight these on the schematic. Congratulations you have performed your first control system startup. (Ref code: PidMan01.ino) You can make the motor turn at less than full speed by setting one output low and the other to Pulse Width Modulation (PWM) but we will do that latter. Lab part 3 Dead-band Control:

Control systems may be direct acting or reverse acting. Direct acting control is one where an increase of the plant input causes an increase in the feedback. A reverse acting control is the opposite. It seems like a simple thing but it is often too complex to figure out in advance. Assume you’re wrong and take precautions when you test this. Use the manual outputs to determine if the control is direct acting or reverse acting. Create a dead band control as follows:

1. Compute the error in counts between the feedback and the reference pot.

2. If the error is greater than some dead band move the motor to reduce the error.

3. Compute the dead band using the proportional gain pot.

4. Create auto outputs based on error and the dead band.

5. Display these values on the serial monitor.

6. With the system in manual make sure the control systems works by watching the auto outputs

on the serial monitor and duplicating these using the manual buttons (which we know work).

7. After this is working “close the loop”.

8. What happens if the dead-band is too large? ____________

9. … or too small? ___________________

Congratulations you are a controls engineer. Now for something more challenging. (Ref code: Dead-bandCtrl01.ino)

Page 16: A Low-Cost Control System Experiment for Engineering ... · A Low-Cost Control System Experiment for Engineering Technology Students Abstract A low-cost control system experiment

15

Lab part 4 Proportional Control:

Program a proportional control in the Arduino. Equation 1 is the equation for a proportional controller. The output ���� is equal to the proportional gain �� times the error ����. The sub t, ��� indicates that output and the error are functions of time. The proportional gain is not a function of time even though you can change it with the proportional pot. ���� = ������ Equation 1

Where: ���� is the error and is equal to the setpoint less the feed back �� is the proportional gain ���� is the controller output. Equation 1 is a continuous equation valid for all time but we have a sampled system. The Arduino is has a delay of 10 ms so the loop function runs about 100 times per second. For the proportional control converting this to a sampled system is trivial but we will do it here to prepare you for the Proportional Integral Derivative (PID) control which we will work on next. ���� = ������ Equation 2

Where: ���� is the error at the kth iteration at time � �� is the proportional gain ���� is the controller output at the kth iteration at time � We can code this in the Arduino as: error=setPointPot-svoFeedBackPot;

outVal=error*pGain;

Note that � is implied. You will need to make sure that the outVal does not exceed the range ±255.

You must use the PWM for this. If outVal>0 you will want the motor to go CW to do this set d5 low use the analogWrite function to set pin d6 to the value of outVal. If outVal>0 then set d6 low and use the analogWrite function to set pin d5 to –outVal. Try different setting of the proportional gain pot. What happens if the gain is too high, or too low? Scale the value of the proportional pot to so that the gain is about right when the proportional gain pot is in the middle of its range.

Lab part 5 Proportional Integral Derivative Control:

The PID is a very common controller in industry. Sometimes they are standalone units often called single loop controllers. PID controllers are also found in Distributed Control Systems (DCS) and Programmable Logic Controllers (PLC). You may even need to implement a PID in an Arduino, Raspberry Pie, or other programmable device. There is even an Arduino PID library, but our objective here to learn what a PID is and how to use it. The control equation for the PID is:

Page 17: A Low-Cost Control System Experiment for Engineering ... · A Low-Cost Control System Experiment for Engineering Technology Students Abstract A low-cost control system experiment

16

���� = �� ����� + � � ������ + �� ��� ������ � Equation 3

Where: ���� is the error and is equal to the setpoint less the feed back �� is the proportional gain � is the integral gain �� is the derivative gain ���� is the controller output. We have seen what the proportional gain is but what do the integral and derivatives do? The integral gain will build over time. For example if you need a steam valve at 50% to maintain the temperature of a reactor using a proportional controller, Equation 1 you will need some temperature error to keep the valve open. If you use a Proportional Integral (PI) controller. The integral part of the controller will ramp up to keep the valve open with zero error. The derivative component reacts to the rate of change of the error and can be used to limit overshoot. As with the proportional controller we need to convert Equation 3 into a sampled system. This was straight forward with the proportional but a little more complicated with the integral and the derivative. The integral can be converted to a summation using the rectangular integration. The integral contribution at � is the rectangle with a height equivalent to the error and a width equivalent to the sample time �� in our case 0.01 s. Each time the loop function runs the integral is updated by adding the error times the sample time to the old integral value. The equation for this is:

Where: ���� is the sampled error �� is the sample time ���� is the continuous time error The derivative the rate of change of the error. The derivative conversion is: ��� ���� = ���� − �������� Equation 5

Where: ���� is the sampled error for this scan ������ is the sampled error for the previous scan

Using Equation 4 and Equation 5 we can convert continuous time PID in Equation 3 to a the sampled time system in Equation 6.

���� = �� ����� + � �����������

+ �� ���� − �������� � Equation 6

� �������� = ���������

�� Equation 4

Page 18: A Low-Cost Control System Experiment for Engineering ... · A Low-Cost Control System Experiment for Engineering Technology Students Abstract A low-cost control system experiment

17

There is still a small problem with Equation 6. If the integral ∑ �������� is large and we

change��, or � then there will be a large change in the output. This could cause a big jump in the output which could cause off specification product, damage equipment, or even cause injury. To avoid this problem use the distributive property and write Equation 6 as:

���� = ������ +���� ����������

+ ���� ���� − �������� Equation 7

Now if you change��, or � there will be no step in the output. States:

One final note. A state is a value that is carried over from a previous execution of the loop function. Normally we don’t worry about this but in controls it is an important consideration. If you look at Equation 7 there are only two things you need from the previous scan, the integral, ∑ ��� ���������� and the previous value of the error, ������. Everything else we can and

should calculate at the top of the loop. So we need the integral and the previous value of the error before we calculate anything else. What happens the first time through the loop? The answer depends on the platform you are using. If the integral is not initialized it could be some huge number like one billion. This would cause the output to saturate at full scale forever. So we should set to zero, correct? This probably isn’t a bad idea but maybe we can do better. A control system should always start in manual. You don’t want anything to move when you turn the system on for safety reasons. We can calculate the error in manual mode so we will have the previous error value when we start up. For the integral we might find a value that initializes the controller output to the manual value when we switch to auto. In other words, given the controller output in manual mode we can compute the integral to ensure there is no bump when we switch to auto. This is sometimes called the reset equation:

���� ����������

= ���� − ������� + +���� ���� − �������� � Equation 8

Where: ���� is the manual output ∑ ��� ���������� is the integral value needed to start the controller without a

step in the output Sometimes the controller can’t reach the setpoint. For example, you have an undersized furnace in your house and the temperature drops to -40°F. The furnace just runs all night. We refer to this as saturation. In your control the output is limited to ±255. If the limiter is active your controller is saturated. If you don’t do something when the output is saturated the integral will just get larger and larger. Then if you change the setpoint it will take a long time for the integral to unwind. You can prevent this by using the reset equation anytime the output is saturated. If you have made it this far congratulations. You will be a great controls engineer.

Page 19: A Low-Cost Control System Experiment for Engineering ... · A Low-Cost Control System Experiment for Engineering Technology Students Abstract A low-cost control system experiment

18

Appendix 2

// Read and display I/O int svoPot, refPot, proPot, intPot, drvPot; // pot vlaues on bool fcwPb, fccwPb, fautSsw; // dig inputs int mtrRef = 0; // analog outs int loopDly = 5; int loopCnt = 0; int db = 15; void setup() { pinMode(5, OUTPUT); pinMode(6, OUTPUT); pinMode(10, INPUT_PULLUP); pinMode(11, INPUT_PULLUP); pinMode(12, INPUT_PULLUP); Serial.begin(9600); } void loop() { // input svoPot = analogRead(0); refPot = analogRead(1); proPot = analogRead(2); intPot = analogRead(3); drvPot = analogRead(4); fccwPb = !digitalRead(10); fcwPb = !digitalRead(11); fautSsw = !digitalRead(12); if (loopCnt > 500) { // print the values tp serial monitor Serial.print(svoPot); Serial.print(" "); Serial.print(refPot); Serial.print(" "); Serial.print(proPot); Serial.print(" "); Serial.print(intPot); Serial.print(" "); Serial.print(drvPot); Serial.print(" "); Serial.print(fccwPb); Serial.print(" "); Serial.print(fcwPb); Serial.print(" "); Serial.print(fautSsw); Serial.print(" "); Serial.println(""); loopCnt = 0; } loopCnt += loopDly; delay(loopDly); }