1. 介绍¶
This documentation presents the RoboDK API for Python. With the RoboDK API it is possible to create simulations with robots and mechanisms as well as generating brand-specific programs for robots. Whereas you can use the graphical user interface to create programs, you can extend its capabilities using a programming language such as Python. The RoboDK API for Python integrates all the offline programming features of the RoboDK simulator and allows you to deploy automated applications for a large variety of robots and mechanisms. 本文档介绍了Python中的RoboDK API,RoboDK API能够创造机器人和机构的仿真模型。也能为机器人生成特定品牌的项目。你可以使用图形用户界面来创建项目,你可以使用类似于Python这样的编程语言来扩展其功能。基于Python的RoboDK API集成了所有RoboDK模拟器的离线编程功能,并允许你开展大量机器人机构的自动化应用。 The RoboDK API for Python is composed of the robolink and robodk modules: Python中的RoboDK API是由robolink和robodk模块组成的: * The robolink Module module is the bridge between RoboDK and Python. Every object in the RoboDK item tree can be retrieved and is represented by the object Item. An item can be a robot, a reference frame, a tool, an object or a specific project. * The robolink Module 模块是RoboDK和Python之间的桥梁。在RoboDK项目树的每个对象可以被检索并且通过对象的项目来表示。一个项目可以是机器人,一个参考系,一个工具,一个对象或一个特定的项目。 * The robodk Module is a robotics toolbox for Python, inspired from Peter Corke's Robotics Toolbox: http://petercorke.com/Robotics_Toolbox.html. The following page provides an overview of the RoboDK API for Python: https://www.robodk.com/offline-programming * The :ref:`robodk`是一个为Python开发的机器人工具,灵感来自Peter Corke的机器人工具箱:http://petercorke.com/Robotics_Toolbox.html。以下页面提供了Python中RoboDk API的一个概述:https://www.robodk.com/offline-programming。 With the RoboDK API it is possible to simulate and program robots for applications as simple as pick and place or as complex as synchronizing the movements of many robots. RoboDK API example using Python: 应用RoboDK API可以进行仿真和应用于程序机器人的简单取放物体或者应用于复杂的多机器人同步运动。 使用Python的RoboDk API的例子如下: .. code-block:: python
from robolink import * # 导入robolink库(与RoboDK桥接) RDK = Robolink() # 建立一个与仿真的链接 robot = RDK.Item('Robot') # 检索机器人 robot.setJoints([0,0,0,0,0,0]) # 设置所有机器人轴坐标为零
target = RDK.Item('Target') # 检索目标项 robot.MoveJ(target) # 移动机器人到目标
# 计算一个沿Z坐标轴相对目标位置100毫米的新位置 from robodk import * # 导入robodk库(机器人工具箱) approach = target.Pose()*transl(0,0,-100) robot.MoveL(approach) # 直线移动到接近位置
The same script used for simulation can be used for offline programming, which means that the appropriate program can be generated for the robot being used. RoboDK supports a large number of robot controllers and it is easy to include compatibility for new robot controllers using postprocessor. A quick overview of RoboDK Processors is provided in the following video: https://www.robodk.com/help#PostProcessor 用于仿真的同一脚本可以用于离线编程,这意味着可以为正在使用的机器人产生适当的程序。 RoboDK支持大量机器人控制器,而且它很容易包含了新机器人使用中的兼容性问题。 RoboDK处理器的简要概述在下面的视频提供: https://www.robodk.com/help#PostProcessor
1.1. 如何安装¶
RoboDK uses the Python IDLE editor by default. You can change these settings to automatically use Notepad https://notepad-plus-plus.org/ or Pycharm https://www.jetbrains.com/pycharm/ in the menu: Tools-Options-Other
RoboDK默认使用Python的IDLE编辑器。你可以用记事本自动更改这些设置https://notepad-plus-plus.org/或者在pytharm的https://www.jetbrains.com/pycharm/菜单中 Tools-Options-Other
RoboDK uses Python 3 by default. Otherwise, Python 2 libraries are available in the folder RoboDK/Python/v2/
. RoboDk 默认使用 Python 3。否则,在文件夹 RoboDK/Python/v2/下使用Python 2的固件库。 +------------+--------+ | |longtext| | |logo| | +------------+--------+
你应该安装RoboDk;https://www.robodk.com/download 在RoboDK中如果验证Python正常工作,你可以允许这一步:
1.开始RoboDK。
2.选择``Program-Add Python Program``一个新的Python项目将出现一个``Prog1``的名字
3.双击新项目。你可以看到一个脚本中的错误会出现,列出在站中可用的对象。
4.我们能正确的点击新项目并且选择"Edit Python script"去修改
如果你获得一个错误他意味着RoboDK没能察觉到Python。如果正确安装了Python我们能够调整Python以下的设置来正常使用Python
1.1.1. Windows¶
If you alredy installed RoboDK for Windows you should have Python 3.4 installed. Otherwise, you can install Python from the following link: https://www.python.org/downloads/windows/ When you start RoboDK, the robodk Module and robolink Module are automatically copied to the folder: C:/Python34/
Alternatively, these files can be copied manually from the folder: C:/RoboDK/Python/
We can place the Python 2 libraries for RoboDK in the Python folder. 如果你已经为Window安装了ROboDK,你应该已经安装了Python3.4。否则你可以从以下链接中安装Python: https://www.python.org/downloads/windows/ 当你启动RoboDK,robodk Module和robolink Module会被自动复制到以下路径: C:/Python34/
或者你可以从文件夹中手动复制这些文件: C:/RoboDK/Python/
在Python文件夹中,我们可以为RoboDK添加Python 2 固件库。
1.1.2. Mac¶
RoboDK and Python must be installed separately. You can download Python for Mac here:
https://www.python.org/downloads/mac-osx/
(Python 3 is recommended) RoboDK and Python 必须被分开安装。你可以从Mac那里下载Python:
https://www.python.org/downloads/mac-osx/
(推荐使用Python 3 )
RoboDK uses the folder /RoboDK/Python
as PYTHONPATH
for the robodk Module and robolink Module. We can place the Python 2 libraries for RoboDK in that folder if Python 2 is used. RoboDK使用``/RoboDK/Python``文件夹为 robodk Module and robolink Module 作为``PYTHONPATH``。 如果使用Python 2 我们可以在这个文件夹下为RoboDK放置Python 2 函数库。
1.1.3. Linux¶
RoboDK and Python must be installed separately. You can download Python for Linux here: https://wiki.python.org/moin/BeginnersGuide/Download
(Python 3 is recommended) RoboDK and Python 必须被分开安装。你可以从Linux那里下载Python: https://wiki.python.org/moin/BeginnersGuide/Download
(推荐使用Python 3 )
RoboDK uses the folder /RoboDK/Python
as PYTHONPATH
for the robodk Module and robolink Module. We can place the Python 2 libraries for RoboDK in that folder if Python 2 is used. RoboDK使用``/RoboDK/Python``文件夹为 robodk Module and robolink Module 作为``PYTHONPATH``。 如果使用Python 2 我们可以在这个文件夹下为RoboDK放置Python 2 函数库。
1.2. RoboDK API for Matlab¶
A Matlab version of the RoboDK API is available here:
https://www.robodk.com/Matlab-API RoboDK API的matlab版可以在这里找到:
https://www.robodk.com/Matlab-API
1.3. RoboDK API for C#¶
A C# version of the RoboDK API is also available. The following video shows a C# sample application merged with RoboDK:
https://www.youtube.com/watch?v=1hRRYr9bEsY 已经可以使用C#版的RoboDK API。下面的视频显示了一个合并RoboDK的C#实例程序:
https://www.youtube.com/watch?v=1hRRYr9bEsY