Using Macros

The RoboDK API allows customizing the simulation as much as desired. By default, RoboDK installs Python and a set of sample macros that allows a higher level of customization. This includes simulating a paint gun, programming robots through Python, simulating 2D cameras, converting SVG files to robot programs, automatically setting a TCP given a standoff, simulating discrete events, etc. Other programming languages can also be used, such as C#, C++ or Matlab. More information is available in the RoboDK API section.

In this example, we will add an existing sample macro that will simulate the behavior of the paint gun. We will also recolor the spray volume with a transparent color (by selecting ToolsChange color tool - Shift+T) or load the existing model with appropriate colors (available from the local library as paint_gun.tool or the online library, note that the Set Tool instruction might need to be updated to link to the new tool).

1. Select FileGetting Started - Image 59 Open to open a new Python macro (py file).

2. Navigate to C:/RoboDK/Library/Macros/ to see some sample macros.

3. Select SprayOn.

4. Select Open. A new Python object Getting Started - Image 60 will be added. This macro allows simulating particle deposition modeling the spray volume.

5. Double click the SprayOn macro to test it.

6. Select On to activate it.

7. Hold Alt key, drag the robot flange and move the robot along the surface with the Paint gun.       
You should see the trace of the paint gun. The color and transparency should change depending on how close or far the TCP is from the surface.          
Select Esc once to clear the simulated paint.

8. Double click the same SprayOn program and select Off to turn the particle simulation Off.

Getting Started - Image 61

To better understand what happens behind the scenes, it is possible to view or edit the Python code the following way:

1. Right click Getting Started - Image 62 SprayOn.

2. Select Edit Python Script.

A new window (text editor) will appear showing the code that models the spray behavior and how Python is integrated with RoboDK.

To take the spray simulation into account in the main program we can follow these steps:

1. Right click the instruction Call ApproachMove.

2. Select Add InstructionGetting Started - Image 63 Program call Instruction, a new instruction will be added after the first program call and a new window will pop up.

3. Enter SprayOn(1).

4. Select OK.

5. Repeat the same operation after the PaintTop program setting SprayOn(0), as shown in the following image.
If necessary, reorder the instructions by drag & dropping them within the program.

6. Run the MainProg program. After two iterations, the result should look like as shown in the image (simulating at normal speed).

Getting Started - Image 64

It is also possible to create new macros:

1. Select ProgramGetting Started - Image 65 Add Python Program

2. Right click the new program and select Edit Python Script

RoboDK supports setting the robot speed within the program, setting digital outputs, waiting for digital inputs, displaying messages, etc. These instructions are available under the Program menu.