Structured Programming

From Wiki
Revision as of 12:31, 25 November 2020 by Mab (talk | contribs) (Created page with "Category:CPRogCategory:TinyCtrlCategory:Downloads Choosing a suitable structure for your robot program is important for lowering the programming and maintenance ef...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Choosing a suitable structure for your robot program is important for lowering the programming and maintenance effort. This article explains sub-programs and the matrix command in a pick-and-place example.

You can download the example programs here: File:ExamplesStructuredProgramming.zip

Sub-programs

Sub-programs are useful for extracting repeated tasks from your program and defining them once in a separate program.

In a pick-and-place scenario objects often are fed to and picked from the same position (or a position recognized by a camera), then placed at some other position. Instead of repeating the picking commands for each object define them in a separate program, then use the Subprogram command that you can find in the Flow menu to call this program whenever you need to pick an object. If need to change the picking position or precedure later on you will only need to change a few commands in this program instead of many commands for each object.

See the programs "Packaging.xml" and "Layer1.xml" of the examples. Packaging.xml packs a whole box consisting of multiple layers. "Layer1.xml" picks and places several objects into a layer using the sub programs "PickPart.xml" and "PlacePart.xml".

Matrix command

The approach described above still relies on defining each placing position manually. If these positions are laid out in a grid the Matrix command can be used to generate the coordinates. This way programs with many placing position can be shrunk down to a few program commands.

This is shown in the example "Layer1_Matrix.xml". In order to use the matrix command you will need to define 3 corner positions using position variables (Store command) and the number of positions in X and Y direction (see the dimension parameters in the matrix command itself). If the matrix turns out to move non-rectangular you should try to swap the defined corners (unless a diamond-shaped motion pattern is what you need). For each position within the matrix the target variable will be set to the calculated position while the counter variables will enumerate the position in both directions.