The RoboDK API (Application Program Interface) is a set of routines and commands that RoboDK exposes through a programming language. The RoboDK API allows you to program any robot using one of the supported programming languages, such as C#, Python or C++. You can also automate repetitive tasks using the RoboDK API.
Compared to vendor-specific robot programming, with the RoboDK API it is possible to simulate and program any robot using a unique/universal programming language, such as Python. The following page provides an overview and a video showing offline programming with the API.
The RoboDK API is available for Python, C#, C++, Visual Basic (.NET) and Matlab. Any of these programming languages can be used to simulate and program any robot arm.
The RoboDK API can be used for the following tasks:
1. Automate the simulation: Create macros to automate specific tasks within the RoboDK simulator, such as moving objects, reference frames or robots.
2. Offline programming: Programming robots offline from a universal programming language. RoboDK will generate specific programs for a specific robot controller when the API is used (such as a program in Python or C#). The robot program is generated according to the post processor selected for a specific robot. The Offline Programming with Python section of this document provides more information and examples.
3. Online Programming: Programming robots online using a universal programming language: It is possible to move robots and retrieve their current position from the RoboDK API. RoboDK will drive the robots using robot drivers. The Online Programming with Python section in this document provides more information and examples.
In other words, the same program that is used for simulation (1) can be used to generate robot programs (2, Offline Programming) and to move the robot in real time (3, Online Programming).
This document covers the following topics:
● The Python API with examples for Simulation, Offline Programming and Online Programming
● The C# API with examples for Simulation, Offline Programming and Online Programming
● The Matlab API with a Simulink example for simulation
● The Command line options to start RoboDK
Python is a widely used high-level programming language for general-purpose programming. Python is a programming language that lets you work faster and integrate your systems more effectively. Python's syntax allows programmers to express concepts in fewer lines of code compared to other languages, making it friendly and easy to learn.
The previous section explains the advantages of using the RoboDK API with a widely used programming language for robot programming such as Python.
Python is automatically installed and integrated with RoboDK by default. Select Tools➔Options➔Other to change the default settings (Python location and Python Editor).
The RoboDK API for Python is divided in the following two modules:
● The robolink module (robolink.py): The robolink module is the interface between RoboDK and Python. Any object in the RoboDK Station Tree can be retrieved using a Robolink object and it is represented by the Item object. It is possible to perform different operations on that item according to the Robolink.Item class.
● The robodk module (robodk.py): The robodk module is a robotics toolbox for Python that allow operating with pose transformations and obtain Euler angles for different robot vendors. All post processors depend on this robodk module.
You can find the Python modules in the folder C:/RoboDK/Python/. This folder is automatically included by default (used as PYTHONPATH) when you run Python programs and post processors in RoboDK.
The following sections show how to create a simple program for simulation, offline programming and online programming respectively. More examples are available in the Python API for RoboDK page. Also, the RoboDK library comes with sample Python scripts in the folder Scripts and Macros, available in the default Library (C:/RoboDK/Library/).
This example shows how to create a new station using a UR robot and simulate a hexagonal movement with the robot.
1.Select File➔ Open
2.Open the UR10 robot
3.Select File➔ Open
4.Open the Paint_gun.tool file
5.Open the sample Python program SampleOfflineProgramming.py from C:/RoboDK/Library/Macros/
6.Double click the SampleOfflineProgramming item to run the simulation. The robot should draw a hexagon around the current location of the robot and the trace of the TCP will be displayed in yellow.
Alternatively, right click the program and select Run Python Script.
7.Right click the SampleOfflineProgramming item and select Edit Python Script. We should see the program as shown in the following image.
The SampleOfflineProgramming macro will draw a polygon of side n_sides and radius R at the current location of the robot, with respect to the robot reference frame. If desired, move the robot to a different location changing the polygon dimensions and re-run the program.
This example is similar to the program displayed in the offline programming section of the website (video included).
Python programs can be generated offline using the same Python code used to simulate the robot (as shown in the previous Python Simulation section). Offline Programming allows generating robot programs that can be executed on a specific robot controller:
1.Right click a Python program
2.Select Generate robot program (F6)
In this case the program is not simulated but executed quickly to obtain the result: a robot program specific to a robot controller.
RDK = Robolink()
Python programs can be directly executed on the robot using the same Python code used to simulate the robot (as shown in the Python Simulation section). Online programming allows running a generic program on a specific robot controller using Robot Drivers:
1.Right click a Python program
2.Select Run on robot
The program will run on the robot as it the Python program is executed.
RDK = Robolink()
If you installed RoboDK after installing Python, RoboDK may fail to properly run Python scripts or generate programs. This section shows the steps you should follow to properly set the Python interpreter in RoboDK and run Python scripts without issues.
You should follow these steps if you see an error message such as: “Set the path to the Python interpreter in Tools-Options-Python” or “Failed to run Python script. Set the path to the Python interpreter in: Tools-Options-Python tab”.
Follow these steps to properly setup the Python interpreter path if you already have Python installed:
1. Select the Start Menu on Windows and type python.
2. Right click the Python version you would like to use with RoboDK and select Open file location.
Repeat this procedure on the folder that opens:
3. Right click on Python 3.7 and select Open file location.
4. Select Copy on the path in the path title bar.
Provide the Python path in RoboDK settings:
5. Open RoboDK.
6. Select Tools-Options.
7. Select the Python tab.
8. Paste the path in the Python interpreter box adding /python.exe, as shown in the next image. Using forward slashes or backslashes should both work.
The RoboDK API for C# is a RoboDK.cs source file that contains the RoboDK class (similar to Python’s Robolink class), the RoboDK.Item class (similar to Python’s Robolink.Item class API), and other tools for robotics such as a Matrix class (RoboDK.Mat) for matrix operations to operate with pose transformations.
C# (pronounced "C sharp") is a programming language developed by Microsoft and designed for building a variety of applications that run on the .NET Framework. C# is simple, powerful, type-safe, and object-oriented. The main section of this document explains the advantages of using the RoboDK API with a widely used programming language such as C# for robot programming.
The RoboDK API for C# is provided with a sample project as shown in the following image (the complete source code is included). It is also possible to use it as a NuGet package to integrate it in any .Net project.
Select Load File to open a RoboDK station or any other file supported by RoboDK. If a robot is loaded, the ROBOT variable will be updated accordingly (same as using Select Robot).
C# programs are simulated by default when robot commands are used (such as MoveJ, MoveL or setDO). When the sample C# project is started, the simulation mode is also selected by default.
This means the robot movements will be simulated in RoboDK. For example, we can move the robot by steps of 10 mm selecting the buttons on the right (+Tx, -Tx, …), or we can select Run Test Program to run a hexagonal movement around the current location of the robot.
Set any breakpoints to debug your application and inspect robot targets. Robot targets can be defined as joint coordinates or Mat variables (4x4 pose Matrices) and they can be inspected as XYZWPR format to troubleshoot program issues. More information about reference frames in the Reference Frames section.
C# programs can be generated offline using the same C# code used to simulate the robot (Offline Programming). Follow these steps to test this feature:
1.Select Offline Programming in the Run Mode section
2.Select Run Test Program or any other combination of movements
3.Select Generate Prog to obtain the vendor-specific robot program
In this case the program is not simulated but quickly executed to obtain the result: a robot program specific to a robot controller. The Run Mode will be changed back to Simulation once the program is generated.
C# programs can be directly executed on the robot using the same C# code used for simulation. Online programming allows running a generic program on a specific robot controller using Robot Drivers. Follow these steps to test this feature using the C# sample project:
1.Select Run on Robot in the Run Mode section
2.Select any other commands that will make a robot move
The movements will run on the real robot and the simulator will synchronize the movements with the robot.
RDK = Robolink();
The RoboDK API for Matlab is available in the RoboDK install folder with some examples (C:/RoboDK/Matlab/). The RoboDK API for Matlab is provided as a group of m files.
Matlab is a proprietary programming language developed by MathWorks. Among other things, MATLAB allows matrix manipulations, plotting of functions and data and implementation of algorithms.
The main section of this document explains the advantages of using the RoboDK API with a widely used programming language such as Matlab for robot programming.
The RoboDK API for Matlab includes:
● Robolink.m is a class that interfaces with RoboDK. Any object in the RoboDK Station Tree can be retrieved using the Robolink object and it is represented by the RobolinkItem object (same as Python’s Robolink class).
● RobolinkItem.m is a class that represents a RoboDK item in the Station Tree. It is possible to perform different operations on that item (same as Python’s Robolink.Item class).
● transl.m, rotx.m, roty.m and rotz.m are functions that create pose matrices given an XYZ translation vector or rotations along a specific axis.
● Pose_2_XYZRPW.m an XYZRPW_2_Pose.m allow converting poses to XYZ position and RPW Euler angles and vice versa. More information in the Reference Frames section.
Sample code is available in the following page:
A Simulink project is available as an example. In the simulation, the robot is moved along a set of XYZ coordinates generated arbitrarily.
The following video shows the result of running the simulation:
This section describes the command line options available when RoboDK is started. Command line options can also be passed using the Command function of the API.
The following call represents a generic call with some arguments:
RoboDK.exe -[option1] -[option2] open_fileA -[option3] open_fileB ...
All file formats supported by RoboDK can be provided as arguments. Including the following formats:
● RDK ➔ RoboDK station file: This file holds a whole project in one file, including any dependencies (robots, tools, NC files, …).
● robot ➔ Robot file: Loading a robot file will also create a reference frame for that robot.
● tool ➔ Tool file: Automatically attached to the last robot added.
● stl/wrl/step/stp/iges/igs/sld ➔ Object (3D geometry): Objects can easily be converted to tools.
● apt/gcode/cnc ➔ NC program file: RoboDK automatically prepares a milling project (Utilities➔Milling Project).
RDK = Robolink(args='-ADDFRAME "-RENAME=Main Ref " load_object.stl')
Available command line Options:
Removes the RoboDK splash image on start.
Creates a RoboDK.debug.txt file in the bin folder that allows debugging the application.
Loads the arguments from a text file. Each line of that text file is considered as a one single argument.
Hides all windows while RoboDK is loading files and updating programs.
Avoids the automatic /SHOW once RoboDK has finished loading. The only way of showing the window afterwards is by using the API.
Hides all windows that are usually shown automatically when loading an NC file.
Start RoboDK without the User Interface (Window and 3D view). Use this option to run RoboDK in the background using the API.
Forces the API communication through the given port (TCP/IP protocol). Default port is 20500.
Don’t show the station tree.
Show the station tree docked on the left side of the window and opaque.
Adds a new reference frame. Any new objects loaded will be placed in this reference frame.
Forces that if a new object is loaded it will be placed at the station reference frame (not the last added frame).
Changes the name of the last reference frame or object that was added.
Moves the last reference frame that was added (in mm and degrees).
Will override any robot machining projects that have the same APT file
Does not override any robot machining projects (will create duplicate projects if there is a name match).
Loads or updates the APT file and generates the robot program if there are no issues.
Updates existing tools and objects when new files are loaded and there is a name match.
Never overrides tools and objects when new files are loaded.
Set the color of the last loaded object (object, tool, robot or mechanism). The color can be a named color or a hexadecimal color (such as #RRGGBBAA, example: #88112288).
Generates a main program that calls the programs linked to loaded APT files sequentially.
Set the first robot tool (or corresponding number) available as the active tool (the tool used when a new program is loaded).
Select the active tool using a name match.
Addcutter allows adding the geometry of a cutter with respect to a tool holder. A cutter is treated as a tool in RoboDK, holding the geometry of the cutter. The geometry of the cutter must be an STL file (ASCII or binary) with the origin at the tip of the tool. The length must be given in mm with respect to the tool holder (the positive Z axis of the tool holder must point outside).
Selectcutter has the same effect as SELECTTOOL, cutters are treated as tools.
Shows the RoboDK window. This is automatically done when all files have been loaded and machining projects have been updated.
Using one of the following options will alter the visibility provoked by the /SHOW command.
Exits the program if there are no error messages.
Exits the program even if there are any error messages.