INTRODUCTION
A program can accomplish a given task in any number of ways. Therefore programs can quickly grow to an unmanagable size. One of the learning tasks in programming is to develop an understanding of loops and variables. In this way, we can limit the size of the program. Loops allow programs to repeat a set of functions for a specified number of times. Variables provide the ability to assign and monitor values. The use of variables allows for complex control of a system.
EQUIPMENT
- RoboPro software
- fishertechnik components:
- Interface, power supply, and USB Cable
- 1 complete wire
- 1 lamp
PROCEDURE
In this activity you will create a program that controls the number of times a light turns on and off.
The ability to use variables in your program is a powerful feature. Variables are intermediate storage spots for specific information. At specific spots in your program, you can query the variable and instruct the program to act on this information. This information can be whether a particular switch has been pressed, whether a predetermined number has been reached, or how often a specific event has occurred.
The variable expression can represent anything that has a value. The variable can equal another variable, an analog input, or a number. We can manipulate the variables to produce the output we desire.
Increase Available Function Blocks
1. Open a new file in RoboPro. Choose Level 5 Objects from the Menu Bar. This will make available the function blocks needed to complete this activity.
2. Expand Program Elements. This will allow you to view the full list of available element subgroups.
3. Select Basic elements. This will allow you to utilized common programming element blocks such as start and end program.
4. Create the program below. Three new function blocks are utilized. The Plus function block can be located in the program elements subgroup Commands. The Variable function block can be located in the program elements subgroup Variables, Timers. The Branch (with Data Input) function block can be located in the program elements subgroup Branch, Wait.
5. Wire a lamp to M1.
Plus Function Block
Every time a program passes through the Plus function block, it adds a value to the block connected to the node on the right.
6. Right click on the Plus function block to bring up additional information. Four different areas can be manipulated.
Command: Identifies the mathematical operation that the function block will perform.
Value: Identifies a numeric value to be manipulated by the mathematical command.
Description of Value: This text will be viewable on the function block in the program.
Data Input for Command Value: If this box is checked, a node will appear on the left, which allows a starting value to be designated.
7. Change the command element Value to "2".
Variable Function Block
A Variable keeps track of a value. RoboPro function blocks that are orange communicate values or information. They do not represent ports or control any physical components. They contain or provide information for the function blocks that must make Branch decisions.
8. Right click on the Variable function block. Three different items can be manipulated.
Name: Identifies the variable, not the value of the variable. It is helpful to name the variable something that describes its function. Also, the variable may be used in multiple places.
Initial Value: Identifiies the starting numeric value of the variable. Depending on your program design, the numeric value of the variable may need to be set at a specific value other than the default 0.
Variable Type: Local variables are only valid in the subprogram in which they are defined. Global variables with the same name are valid throughout the main program and all subprograms. Object variables are only valid for specific variable instances.
9. Change both variable function blocks names from "var" to "Count". Make sure that "Count" is spelled the same for both blocks. "Count" and "count" are two different variables.
A branch (with Data Input) is much like the Analog Branch. Both possess yes and no nodes based upon a defined condition. The important difference is that Analog Branches retrieve information from an analog input device, while a Branch (with Data Input) retrieves information from whatever value is provided through the infromation node on the left side of the function block. It is common for this information to come from a Variable function block.
10. Right click on the Branch to bring up additional information. Two different items can be manipulated.
Condition: Identifies the condition that will be considered true.
Swap Y/N Branches: Choosing this selection causes the 1 and 0 nodes to trade places on the function block.
11. Change the Branch block condition to greater than 8.
12. Create descriptions next to each function block to describe what you believe will happen at each one.
13. Run the program and adjust any descriptions that may have performed differently that you predicted. Demonstrate the successful program for your instructor.
14. For how many seconds was the light on?
5 seconds.
15. Write a program that repeats the following sequence three times before ending: The lamp turns on for four seconds and turns off for four seconds. Insert text next to each function block to explain what is happening. Demonstrate the successful program to your instructor.
CONCLUSION
16. Describe how you might modify the Plus command so that it can reset a variable block to 0 within a program.
17. What might an industrial or manufacturing engineer need to count or keep track of? Describe one example.