Industrial Automation course Lesson 8 PLC Structured text Exercises Politecnico di Milano Universidad de Monterrey, July 2015, A. L. Cologni 1
Exercise 1 Let s consider a rocks transport system based on a cart. The operator defines the beginning of the cycle using the START button. The cart goes through the entire rail from left to right and it stops waiting to be filled. The rocks, after being accumulated in a tank, are moved mechanically into the cart, which must automatically move along the rail from right to left. Politecnico di Milano Universidad de Monterrey, July 2015, A. L. Cologni 2
Exercise 1 As INPUTS we have six sensors: Rocks Start Start button ET Empty Tank LS Left Switch TDS Tank Down Switch RS Right Switch TUS Tank Up Switch UPT TUS DWT Start TDS ET LM RM LS As OUTPUTS we have: RS RM Right Motor DWT Down Tank LM Left Motor UPT Up Tank Politecnico di Milano Universidad de Monterrey, July 2015, A. L. Cologni 3
Exercise 1 The implementation choices, in structured text, can be very different, it means that the implementation is more free in respect of the ladder and the SFC. Since it is a higher level language, it gives the possibility of organize, in function of the programmer needs, the software. N.B.: it is a double-edged sword: it is possible to create confusion and you can make everything incomprehensible! Politecnico di Milano Universidad de Monterrey, July 2015, A. L. Cologni 4
Exercise 1 «Ladder-based» solution PROGRAM _INIT LM := 0; RM := 0; DWT := 0; UPT := 0; END_PROGRAM PROGRAM _CYCLIC IF Start AND LS AND NOT ET THEN RM := 1; IF RS THEN RM := 0; IF RS AND NOT LS AND TUS AND NOT TDS AND NOT ET THEN DWT := 1; IF RS AND NOT LS AND TDS AND NOT TUS THEN DWT := 0; IF RS AND NOT LS AND TDS AND NOT TUS AND ET THEN UPT := 1; IF RS AND NOT LS AND TUS AND NOT TDS THEN UPT := 0; IF RS AND NOT LS AND TUS AND NOT TDS AND ET THEN LM := 1; IF LS AND NOT RS THEN LM := 0; END_PROGRAM Politecnico di Milano Universidad de Monterrey, July 2015, A. L. Cologni 5
Exercise 1 «SFC-based» solution PROGRAM _INIT LM := 0; RM := 0; DWT := 0; UPT := 0; END_PROGRAM PROGRAM _CYCLIC CASE State OF 0: LM := 0; RM := 0; DWT := 0; UPT := 0; IF Start AND NOT ET THEN State := 1; 1: 2: RM := 1; IF RS THEN RM := 0; State := 2; DWT := 1; IF TDS THEN DWT := 0; State := 3; 3: IF ET THEN UPT := 1; State := 4; 4: 5: IF TUS THEN UPT := 0; State := 5; LM := 1; IF LS THEN LM := 0; State := 0; END_CASE END_PROGRAM Politecnico di Milano Universidad de Monterrey, July 2015, A. L. Cologni 6
Exercise 1 Which solution is better? It depends from the type of machine that you want to control: as it will be shown, in the washing plant the «ladderbased» solution is the most easy and intuitive. In the case, instead, of the machining station control, the best solution is that based on the finite-state machine. Politecnico di Milano Universidad de Monterrey, July 2015, A. L. Cologni 7
Exercise 1.1 Let s add to the previous exercise, a maintenance stop every 100 cycles. It is necessary to add: MS (Maintenance Stop) as output MR (Maintenance Reset) as input N.B.: It will be necessary to create also a counter variable! We analyze only the machine state solution Politecnico di Milano Universidad de Monterrey, July 2015, A. L. Cologni 8
Esercizio 1.1 PROGRAM _INIT LM := 0; RM := 0; DWT := 0; UPT := 0; n := 0; END_PROGRAM PROGRAM _CYCLIC CASE State OF 0: LM := 0; RM := 0; DWT := 0; UPT := 0; IF Start AND NOT ET THEN State := 1; 1: RM := 1; IF FD THEN RM := 0; State := 2; 2: DWT := 1; IF TDS THEN DWT := 0; State := 3; 3: IF ET THEN UPT := 1; State := 4; 4: IF TUS THEN UPT := 0; State := 5; 5: LM := 1; IF LS THEN LM := 0; n := n + 1; IF n>=100 THEN MS := 1; State := 6; ELSE State := 0; 6: IF MR THEN MS := 0; n := 0; State := 0; END_CASE END_PROGRAM Politecnico di Milano Universidad de Monterrey, July 2015, A. L. Cologni 9
Exercise 2 Let s consider an automatic car wash plant. The customer approaches to the belt when the traffic light is green. The wash phases are: soaping, brushing, rinsing and drying. All the phases are preceded by a photocell that detects the car arrival in that section of the plant. Every 1000 washes the plant must be blocked and wait for the maintenance, made by an operator. Politecnico di Milano Universidad de Monterrey, July 2015, A. L. Cologni 10
Exercise 2 SM BM RM DM MAI RTL MAIR InP BP RP DP OutP Inputs Outputs InP Input photocell RTL Red traffic light (0=GREEN, 1=RED) BP Brushing photocell SM Soaping motor RP Rinsing photocell BM Brushing motor DP Drying photocell RM Rinsing motor OutP Output photocell DM Drying motor MAIR Maintenance reset MAI Maintenance stop Politecnico di Milano Universidad de Monterrey, July 2015, A. L. Cologni 11
Exercise 2 The plant can be considered as a set of single smaller plants: Soaping Brushing Rinsing Drying Each of these «plants» must be turned on when the input photocell detects the passage of a car, while it must be switched off when the car is completely exited from the section (when the next photocell is deactivated). Politecnico di Milano Universidad de Monterrey, July 2015, A. L. Cologni 12
Exercise 2 As already described in lesson 4, the solution to this exercise is based on a «distributed» management of each part of the plant. We already seen in lesson 7 how it is possible, in a fast way, to create Function Blocks in ST. Because of the presence of 3 sections that have the same behavior, we start, first of all from the creation of a Function Block that control a part of the plant. Politecnico di Milano Universidad de Monterrey, July 2015, A. L. Cologni 13
Exercise 2 FUNCTION_BLOCK PlantSection IF NOT Activation THEN IF EDGEPOS(InP) THEN Activation := 1; ELSE IF EDGENEG(OutP) THEN Activation := 0; END_FUNCTION_BLOCK Each section is activated when a positive edge of the input photocell is detected, while it is deactivated when a negative edge of the output photocell is reached. Inputs: InP, OutP Outputs: Activation Politecnico di Milano Universidad de Monterrey, July 2015, A. L. Cologni 14
Exercise 2 FUNCTION_BLOCK FirstSection IF n<1000 THEN IF NOT RTL THEN IF EDGEPOS(InP) THEN RTL := 1; Activation := 1; ELSE IF EDGENEG(OutP) THEN RTL := 0; Activation := 0; n := n + 1; ELSE RTL := 1; Activation := 0; Mai := 1; IF MaiReset THEN n := 0; RTL := 0; Mai := 0; END_FUNCTION_BLOCK The first section (Soaping) has to manage also the traffic light and the programmed maintenance. For this reason it is necessary to use a different Function Block. Inputs: InP, OutP, MaiReset Outputs: RTL, Mai, Activation Politecnico di Milano Universidad de Monterrey, July 2015, A. L. Cologni 15
Exercise 2 PROGRAM _INIT END_PROGRAM PROGRAM _CYCLIC Soaping(InP := InP, OutP := BP, MaiReset := MAIR); MAI := Soaping.Mai; RTL := Soaping.RTL; SM := Soaping.Activation; Brushing(InP := BP, OutP := RP); BM := Brushing.Activation; Rinsing(InP := RP, OutP := DP); RM := Rinsing.Activation; Drying(InP := DP, OutP := OutP); DM := Drying.Activation; END_PROGRAM The program file is very simple: subsequent call to the plant section are executed, passing the input parameters. N.B.: Why we didn t use a single entity of the Plant Section Function Block? Politecnico di Milano Universidad de Monterrey, July 2015, A. L. Cologni 16
Exercise 3 Let s consider an automatic drilling and riveting system for sheet metal. When the two pieces arrive, a robot execute the handling of the components (subsequently one to each other) and it positions them on the mounting jig. When the handling is finished the machining can be executed using the automatic driller (the duration of this operation is 5 sec) and the riveter (10 sec). At the end of the operations the robots moves the piece in a pallet. Politecnico di Milano Universidad de Monterrey, July 2015, A. L. Cologni 17
Exercise 3 PA CA CB RST RC P PB BDS FDS FRS BRS DON DFM DBM T MA MB R RON RFM RBM Inputs PA Presence sensor conveyor A FDS Front driller switch PB Presence sensor conveyor B BRS Back riveter switch RST Robot state (0=IDLE, 1=EXECUTING) FRS Front riveter switch BDS Back driller switch Politecnico di Milano Universidad de Monterrey, July 2015, A. L. Cologni 18
Exercise 3 PA CA CB RST RC P PB BDS FDS FRS BRS DON DFM DBM T MA MB R RON RFM RBM RC Robot command (0=STOP, 1=from CA to MA, 2=from CB to MB, 3=from M to P) Outputs DON RFM Driller ON Riveter front motor DFM Driller front motor RBM Riveter back motor DBM Driller back motor RON Riveter ON Politecnico di Milano Universidad de Monterrey, July 2015, A. L. Cologni 19
Exercise 3 Consider the steps necessary to achieve the final product: 1)Wait the activation of CA and CB 2)Send the command 1 to the robot and wait the end of the execution 3)Send the command 2 to the robot and wait the end of the execution 4)Move the driller until reach its front switch 5)Activate the driller for 5 seconds 6)Move back the driller until it reaches the back switch 7)Move the riveter until reach its front switch 8)Activate the driller for 10 seconds 9)Move back the driller until it reaches the back switch 10)Send the command 3 to the robot and wait the end of the execution 11)Send the command 0 to the robot Politecnico di Milano Universidad de Monterrey, July 2015, A. L. Cologni 20
Exercise 3 PROGRAM _INIT State := 0; END_PROGRAM PROGRAM _CYCLIC CASE State OF 0: (* Stop *) IF PA AND PB THEN RC := 1; State := 1; RST := 1; 1: (* Moving A *) IF NOT RST THEN RC := 2; State := 2; RST := 1; 2: (* Moving B *) IF NOT RST THEN State := 3; 3: (* Driller forward *) DFM := 1; IF FDS THEN DFM := 0; State := 4; 4: (* Driller machining *) DON := 1; t := t + dt; IF t>=t#5s THEN t := T#0s; DON := 0; State := 5; 5: (* Driller backward *) DBM := 1; IF BDS THEN DBM := 0; State := 6; 6: (* Riveter forward *) RFM := 1; IF FRS THEN RFM := 0; State := 7; 7: (* Riveter machining *) RON := 1; t := t + dt; IF t>=t#10s THEN t := T#0s; RON := 0; State := 8; 8: (* Riveter backward *) RBM := 1; IF BRS THEN RBM := 0; RC := 3; State := 9; RST := 1; 9: (* Moving product *) IF NOT RST THEN State := 0; END_CASE; END_PROGRAM Politecnico di Milano Universidad de Monterrey, July 2015, A. L. Cologni 21
Remarks Structured text remarks It s the highest level programming language of the IEC 61131 norm. It shows a set of problems (also present in the other languages) related to the software engineering. In the industrial context, it is not used a lot: it is entering now thanks to some tools that allow the automatic generation of the code. Politecnico di Milano Universidad de Monterrey, July 2015, A. L. Cologni 22