Tutorial Task - Add Area Restriction PLC Logic

Task Overview

In this task, you'll learn how to use the Get Variable activity to get the state of a photo eye variable. You'll design an emulation system in which photo eyes will communicate with each other to restrict the flow of items to a specific area. The Get Variable activity will be used by photo eyes to determine whether the restricted area is clear and can receive flow items. If not, the motor will stop until the area is clear again.

When you're finished, the simulation model will work similar to the one shown in the following image:

Step 1 Edit the 3D Model

In this step, you'll edit the 3D model to add a second conveyor line that converges with the first. You'll also add a separate motor to control this conveyor as well as its own source, processor, and sink. Lastly, you'll make the two conveyors different colors so that you can easily distinguish between them visually. When you're finished, your model should look similar to the following image:

To build this model:

  1. Make sure your 3D model window is open and active. From the Library, drag the following 3D objects into the model:
    • A Source
    • A Straight Conveyor (under Conveyors)
    • A Processor
    • A Sink
    • A Motor (under Conveyors)
  2. Move the tail of Conveyor2 (the newly added conveyor) to rotate it 90 degrees so that it is perpendicular to the other conveyor.
  3. Move Conveyor2 so that it intersects with Conveyor1.
  4. Click Processor2 to select it. In Properties, change its Z-rotation to -90.00.
  5. Add a Photo Eye (under Conveyors) to Conveyor1, placing it slightly after the intersecting Conveyor2.
  6. Add two additional Photo Eye objects to Conveyor2, placing one slightly before the intersecting Conveyor1 and one slightly after.
  7. For clarity, rename the photo eyes as follows:
  8. Object New Name
    Photo eye before intersection on Conveyor1 PhotoEye1A
    Photo eye after intersection on Conveyor1 PhotoEye1B
    Photo eye before intersection on Conveyor2 PhotoEye2A
    Photo eye after intersection on Conveyor2 PhotoEye2B
  9. Create port-connections (A-connects) between the following objects:
    • From Motor2 to Conveyor2
    • From Source2 to Conveyor2
    • From Conveyor2 to Processor2
    • From Processor2 to Sink2
  10. Click Source2 to bring up its properties on the right. In Properties, under the Source section, check the Arrival at time 0 box.
  11. In the Inter-Arrivaltime box, delete the current text and type 10.
  12. In the Toolbox under the Conveyor System group, right-click ConveyorType1 to open a menu. Select Duplicate to create a copy of this conveyor type.
  13. Click the copied conveyor type to open its properties on the right. Under the Straight Conveyor section click on the Properties button to bring up the Conveyor Properties Type window.
  14. In the name box at the top, rename this conveyor type as ConveyorType2.
  15. On the Visual tab in the Side Skirt group, change the Color to red.
  16. Click the OK button to save the changes and close the window.
  17. In the Toolbox, double-click ConveyorType1 to open its properties window.
  18. On the Visual tab in the Side Skirt group, change the Color to light blue.
  19. Click the OK button to save the changes and close the window.
  20. In the 3D model, click Conveyor2 to select it. In Properties, click the Conveyor Type menu and select ConveyorType2.

Check that your simulation model looks similar to the image shown at the beginning of this step.

Step 2 Add Activities and Variables to the Process Flow

In this step, you'll edit the process flow that controls the simulation logic for the first conveyor. You'll add and rename several different shapes, activities, and emulation variables. When you're finished, your process flow should look similar to the following image:

For now, you'll merely add and connect these activities to the process flow. You'll edit the properties to add the functionality in a later step.

To add these activities and variables:

  1. With the process flow open and active, rename the Sensors (Inputs) shape as Conveyor 1: Check Area Is Clear.
  2. Directly under this shape, add another Process shape.
  3. Rename the new shape Conveyor 1: Indicate When Area Is Clear.
  4. In the Conveyor 1: Check Area Is Clear shape, click the stacked block of activities and click the Unlink buttons to cut the links from the Set Variable: Motor to 0 and the Delay: 5 seconds activities so that they aren't connected to the stacked block any more.
  5. Delete the Delay: 5 seconds activity.
  6. Create a new stacked block starting with the Source: Item at Photo Eye activity. Add the following activities, appending them to end:
    • A Get Variable (under Shared Assets)
    • A Decide (under Basic)
  7. You'll create another stacked block, this time starting with the Set Variable: Motor to 0 activity. Add a Wait for Event (under Basic) after it.
  8. Add the stacked block starting with the Set Variable: Motor to 1 to the end of this stacked block.
  9. Create another stacked block with the following activities:
    • An Event-Triggered Source (under Token Creation)
    • A Set Variable (under Shared Assets)
    • A Sink (under Basic)
  10. To the right of the activities, add a Sink (under Basic).
  11. Rename the activities and shared assets as follows:
  12. Activity New Name
    Source: Item at Photo Eye Source: Item at PhotoEye 1A
    Get Variable Get Variable: PhotoEye 2A State
    Decide Decide: Is PhotoEye 2A Clear?
    Set Variable: Motor to 0 Set Variable: Motor1 to 0
    Wait for Event Wait for Event: PhotoEye2A Clear
    Set Variable: Motor to 1 Set Variable: Motor1 to 1
    Variable: Photo Eye Variable: PhotoEye1A
    Sink Sink: Item Proceeds
  13. Create two connectors going out from the Decide: PhotoEye 2A Clear? activity. The first connector should go to the Set Variable: Motor1 to 0 activity. The second connector should go to the Sink: Item Proceeds activity.
  14. Click connector 1 to select it. In Properties in the Name box, type No.
  15. Click connector 2 to select it. In Properties in the Name box, type Yes.
  16. In the Conveyor 1: Indicate When Area Is Clear shape, create a stacked block of activities with the following activities:
    • An Event-Triggered Source (under Token Creation)
    • A Set Variable (under Shared Assets)
    • A Sink (under Basic)
  17. To the right of this new stacked block of activities, add a Variable (under Shared Assets).
  18. Rename these activities as follows:
  19. Activity New Name
    Source Source: PhotoEye1B Is Clear
    Set Variable Set Variable: PhotoEye1A to Clear
    Sink Sink: Conveyor1 Area Is Clear
    Variable Variable: PhotoEye 1B
  20. In the Controls (Outputs) shape, click Variable: Motor to select it. Rename it Variable: Motor1.
  21. Press Ctrl+C to copy Variable: Motor1. Click a blank area in the shape and press Ctrl+V to paste the copy. Check that the new variable is named Variable: Motor2.

Consider saving your simulation model at this point.

Step 3 Copy and Adapt the Logic for Conveyor 2

In this step, you'll copy the sections of the process flow that will control the simulation logic for the first conveyor and adapt it for the second conveyor. When you're finished, the copied sections of your process flow should look similar to the following image:

For now, you'll merely add and connect these activities to the process flow. You'll edit the properties to add the functionality in a later step.

To copy and rename these activities and variables:

  1. Click the Conveyor 1: Check Area Is Clear shape to select it. Press Ctrl+C to copy it. Click a blank area of the process flow and press Ctrl+V to create a copy.
  2. Rename the new copied shape Conveyor 2: Check Area Is Clear.
  3. In Properties, change the Color of the newly copied shape to red (to match Conveyor2's color).
  4. In the Conveyor 2: Check Area Is Clear shape, rename the following activities and shared assets for clarity:
  5. Activity New Name
    Variable: PhotoEye 1A1 Variable: PhotoEye 2A
    Source: Item at PhotoEye 1A Source: Item at PhotoEye 2A
    Get Variable: PhotoEye 2A State Get Variable: PhotoEye 1A State
    Decide: Is PhotoEye 2A Clear? Decide: Is PhotoEye 1A Clear?
    Set Variable: Motor1 to 0 Set Variable: Motor2 to 0
    Wait for Event: PhotoEye2A Clear Wait for Event: PhotoEye1A Clear
    Set Variable: Motor1 to 1 Set Variable: Motor2 to 1
  6. Click the Conveyor 1: Indicate When Area Is Clear shape to select it. Press Ctrl+C to copy it. Click a blank area of the process flow and press Ctrl+V to create a copy.
  7. Rename the new copied shape Conveyor 2: Indicate When Area Is Clear.
  8. In Properties, change the Color of the newly copied shape to red (to match Conveyor2's color).
  9. For now, just delete the Variable: PhotoEye 1B1 variable. You'll create this variable later.
  10. In the Conveyor 2: Indicate When Area Is Clear shape, rename the following activities and shared assets for clarity:
  11. Activity New Name
    Source: PhotoEye 1B Is Clear Source: PhotoEye 2B Is Clear
    Set Variable: PhotoEye1A to Clear Set Variable: PhotoEye2A to Clear
    Sink: Conveyor1 Area Is Clear Sink: Conveyor2 Area Is Clear

Consider saving your simulation model at this point.

Step 4 Update the Variable Links and Connections

In this step, you'll update all of the emulation variable shared assets so that they are connected to the OPC DA Connection variable. You'll also make sure all the variables are linked to the correct objects in the 3D model and that they have the correct settings. To make these updates:

  1. In the Controls (Outputs) shape, click Variable: Motor2 to select it. Ensure that when it is selected, it shows a blue line linking it to the OPC DA Connection variable.
  2. In Properties next to the Associated Object box, click the Sampler button to enter sampling mode.
  3. In the 3D model, click Motor2 (the motor connected to the red conveyor) to sample it.
  4. In the Conveyor 1: Check Area Is Clear shape, click Variable: PhotoEye 1A to select it. Ensure that when it is selected, it shows a blue line linking it to the OPC DA Connection variable.
  5. In Properties, check that the Associated Object box reads PhotoEye1A.
  6. In the Write Events group next to the On Uncover event, click the Delete button to delete this event.
  7. In the Conveyor 2: Check Area Is Clear shape, click Variable: PhotoEye 2A to select it. Ensure that when it is selected, it shows a blue line linking it to the OPC DA Connection variable.
  8. In Properties next to the Associated Object box, click the Sampler button to enter sampling mode.
  9. In the 3D model, click PhotoEye2A (the first photo eye on the red conveyor) to sample it.
  10. In the Write Events group next to the On Uncover event, click the Delete button to delete this event.
  11. In the Conveyor 1: Indicate When Area Is Clear shape, click Variable: PhotoEye 1B to select it. In Properties, click the arrow next to the Variable or Value box to open a menu. Point to Internal Emulation Variable, and select OPC DA Sensor Tag.
  12. Next to the Connection box, click the Sampler button to enter sampling mode.
  13. In the Server Connection shape, click the OPC DA Connection variable to sample it.
  14. Next to the Associated Object box, click the Sampler button to enter sampling mode.
  15. In the 3D model, click PhotoEye1B (the second photo eye on the blue conveyor) to sample it.
  16. In the Write Events group, click the Add button to open a menu. Select On Uncover.
  17. In the Write Value box, delete the current text and type 0.
  18. With PhotoEye 1B selected, press Ctrl+C to copy this variable. Click a blank space in the Conveyor 2: Indicate When Area Is Clear shape and then press Ctrl+V to paste the variable into this shape.
  19. Rename the copied variable Variable: PhotoEye 2B.
  20. Click Variable: PhotoEye 2B to select it. In Properties, next to the Associated Object box, click the Sampler button to enter sampling mode.
  21. In the 3D model, click PhotoEye2B (the second photo eye on the red conveyor) to sample it.

Consider saving your simulation model at this point.

Step 5 Create the Area Restriction Logic

In this step, you'll edit the properties to add the area restriction logic for Conveyor 1. The following is an overview of how each activity will function in the Check Area Is Clear shape:

Activity Explanation
Source: Item at Photo Eye 1A This is an event-listening activity that will listen to events in the variable that is linked to PhotoEye1A on the first conveyor. You won't change this logic in this step, so just remember that you'll listen for the On Change event, which means that it will listen for any time PhotoEye1A is covered by a flow item. When the photo eye is covered, it will write a value of 1 to the server. The source will listen for any changes on the photo eye variable. When a value of 1 is written to the server, the source will release a token to the next downstream activity. You won't need to make any changes to this activity since you've already set up its logic.
Get Variable: PhotoEye 2A State The Get Variable activity can read information from other variables connected to the server. In this case, you'll get the value of the PhotoEye2A variable and store that value in a label on the token named PhotoEyeState. If the value is 1, that means that PhotoEye2A is covered. If the value is 0, that means that PhotoEye2A is clear.
Decide: Is PhotoEye2A Clear? This activity will use the PhotoEyeState label to decide which connector it should send the current token to. If the value of the PhotoEyeState label is 1, it will mean the value is true and that PhotoEye2A is covered. In other words, the restricted area is not clear. The Decide will send the token to the series of activities that will stop the motor so that the flow item will wait until the area is clear. If the value of the label is 0, the flow item can proceed and the token will be sent to the Sink activity connected to connector 2.
Set Variable: Motor to 0 This activity will set the motor variable to 0, which will stop the conveyor motor in the 3D model. You won't need to make any changes to this activity since you've already set up its logic.
Wait for Event: PhotoEye2A Clear This activity will hold the token until PhotoEye2A changes to 0, meaning it is clear. Once PhotoEye2A changes to 0, it will release the token to the next downstream activity.
Set Variable: Motor to 1 This activity will then set the motor variable back to 1, which will resume running the conveyor. You won't need to make any changes to this activity since you've already set up its logic.

And the following is an overview of how each activity will function in the Indicate When Area Is Clear shape:

Activity Explanation
Source: PhotoEye 1B Is Clear This activity will listen for any time PhotoEye 1B changes, either from clear or to covered. It will release a token when that change occurs.
Set Variable: PhotoEye1A to Clear This activity will set PhotoEye 1A to clear when it receives a token.
Sink: Conveyor1 Area Is Clear This activity will remove the token from the process flow and the flow item will continue along the conveyor. You'll use the default settings for this activity.

You'll also copy this logic to the second conveyor's activities too.

To make these changes:

  1. In the Conveyor 1: Check Area Is Clear shape, click the Get Variable: PhotoEye 2A State activity to select it. In Properties next to the Variable Reference box, click the Sampler button to enter sampling mode.
  2. In the Conveyor 2: Check Area Is Clear shape, click the Variable: PhotoEye 2A variable to sample it.
  3. In the box under the Assign to option, delete the current text and type token.PhotoEyeState.
  4. Repeat the previous steps for the Get Variable: PhotoEye 1A State activity (in the Conveyor 2: Check Area Is Clear shape), changing its Variable Reference to Variable: PhotoEye1A. Make sure you change the Assign to label name to token.PhotoEyeState as well.
  5. Click the Decide: Is PhotoEye2A Clear? activity to select it. In Properties, click the arrow next to the Send Token To box to open a menu. Select Conditional Decide to open its picklist options.
  6. In the Condition box, delete the current text and type token.PhotoEyeState.
  7. Repeat the previous steps for the Decide: Is PhotoEye1A Clear? activity (in the Conveyor 2: Check Area Is Clear shape).
  8. Click the Wait for Event: PhotoEye2A Clear activity to select it. In Properties next to the Object box, click the Sampler button to enter sampling mode.
  9. In the Conveyor 2: Check Area Is Clear shape, click the Variable: PhotoEye 2A variable to open a menu. Select Variable: PhotoEye 2A: On Change.
  10. In Properties, in the Label Assignment / Match Value table, click the cell that is on the New Value row under the Label Name or Value column. Type 0.
  11. Click the cell that is on the New Value row under the Operation column to open a menu. Select match value.
  12. Repeat the previous steps for the Wait for Event: PhotoEye1A Clear activity (in the Conveyor 2: Check Area Is Clear shape), but change its Object to Variable: PhotoEye 1A.
  13. In the Conveyor 1: Indicate When Area Is Clear shape, click the Source: PhotoEye 1B Is Clear activity to select it. Click the Exclamation Point button next to this activity to enter sampling mode.
  14. Click Variable: PhotoEye 1B to open a menu. Select Variable: PhotoEye 1B: On Change.
  15. Repeat the previous step for the Source: PhotoEye 2B is Clear activity (in the Conveyor 2: Check Area Is Clear shape), but sample Variable: PhotoEye2B instead.
  16. In the Conveyor 1: Indicate When Area Is Clear shape, click the Set Variable: PhotoEye 1A to Clear activity to select it. Click the Exclamation Point button next to this activity to enter sampling mode.
  17. Click Variable: PhotoEye 1A (in the Conveyor 1: Check Area Is Clear shape) to sample it.
  18. Repeat the previous steps for the Set Variable: PhotoEye 2A to Clear (in the Conveyor 2: Check Area Is Clear shape), but sample Variable: PhotoEye2A instead.

Reset and run the model:

Notice that when a flow item reaches the first photo eye on Conveyor 2 (the red one), it triggers the stop motor logic and then later resumes the motor when the second photo eye on Conveyor 1 (the blue one) is clear. You could try experimenting with different source arrival times to see how it would affect the queue times.

Conclusion

At this point, you've learned how to emulate basic PLC logic in FlexSim. If you were building an actual manufacturing system, you could program any number of variables for several different PLCs this way and then hand it off to the PLC programmer to program the actual PLC logic that will eventually be used in the system.

Once the PLCs have been programmed, you could possibly use FlexSim to then validate whether the PLCs had been programmed correctly before they are actually implemented in a manufacturing system. To validate this logic, you'd need to connect FlexSim to an actual OPC DA server using the properties in the OPC DA Connection. You'd also have to assign all your emulation variables to their appropriate tag IDs on the server. You'd then change the OPC DA Connection shared asset to "active" in FlexSim so that it will read or write values on the actual server.

At this point you could run the simulation model and test that the PLCs are operating the way they should operate in the actual system. In theory, you would have created a simulation of your future business system in FlexSim. So, the PLC will directly control the elements in the simulation model. You can then observe how the actual PLC has been programmed and compare it to the way the simulation model ran before the PLC was directly connected to the 3D model. See Validating PLC Logic for a deeper explanation.