上篇:
Robotstudio软件在为仿真人员提供强大的仿真功能的同时,也对外开放了二次开发接口,因此,在软件自身功能不能满足工作需求的时候,我们也可以根据需求自定义开发出符合工作需要的虚拟仿真与离线编程功能。Robotstudio软件支持二次开发的功能包含Smart组件与Add-Ins插件两种,开发语言是基于.NET框架的C#语言。本期,就来为大家介绍一下Robotstudio软件中Add-Ins插件的开发,算是一个基础入门吧。
Robotstudio软件版本:RobotStudio 6.08
SDK版本:RobotStudio SDK.6.08
开发软件版本:Microsoft Visual Studio Professional 2019
一、开发环境配置
1.依次安装Microsoft Visual Studio Professional、RobotStudio、RobotStudio SDK三个软件。
2.安装完成后,从C:Program Files (x86)ABB Industrial ITRobotics ITSDKRobotStudio SDK 6.08ProjectTemplates目录中复制RobotStudioEmptyAddIn、RobotStudioSampleAddIn、RobotStudioSmartComponent三个模板文件到C:UsersXDocumentsVisual Studio 2019TemplatesProjectTemplatesVisual C#文件目录中。
说明:上述文件目录中的X为计算机名称。
二、开发项目创建
1.在Microsoft Visual Studio中创建新项目,创建过程中语言、平台、项目类型筛选对象均选择“所有…”,然后可以再下方的项目模板中看到三个Robotstudio软件的三个基于C#语言的二次开发模板,这里我们点选RobotStudio 6.08 EmptyAdd-in模板。
2.在配置新项目对话框中可以设置项目名称、项目保持位置、解决方案名称等内容,这里也可以保持默认,点击创建按钮。
三、代码编写
完整程序代码如下:
using System;using System.Collections.Generic;using System.Text;using ABB.Robotics.Math;using ABB.Robotics.RobotStudio;using ABB.Robotics.RobotStudio.Environment;using ABB.Robotics.RobotStudio.Stations;namespace RobotStudioEmptyAddin1{ public class Class1 { // This is the entry point which will be called when the Add-in is loaded public static void AddinMain() { Logger.AddMessage(new LogMessage("Hello World!")); } }}
2.代码编写完成后,点击“生成解决方案”命令按钮,或直接按F6快捷键,对代码进行编译生成,编译成功后在项目文件目录的Debug文件夹下可以看到
RobotStudioEmptyAddin1.dll与
RobotStudioEmptyAddin1.rsaddin两个文件。
其中,*.rsaddin格式文件是Robotstudio软件插件加载文件, *.dll格式文件是插件文件的动态链接库。
四、运行测试
1.将Debug文件夹下编译生成的插件文件与动态链接库文件复制到X:Program Files (x86)ABB Industrial ITRobotics ITRobotStudio 6.08BinAddins文件目录中。(X为Robotstudio软件安装盘盘符)
2.打开Robotsrudio软件,然后点击上方的“Add-Ins”菜单,在其下左侧的Add-Ins浏览标签下展开“概述”,在其下可以看到已经加载进来我们开发好的插件。
3.右击加载进来的插件RobotStudioEmptyAddin1,在弹出的快捷菜单中点选“加载Add-In”,在Robotstudio软件下方的输出对话框中,可以看到已经显示出信息提示“Hello World!”,软件二次开发成功。
下篇:
Robotstudio软件除了支持Add-Ins插件的二次开发以外,还支持Smart组件的二次开发。开发语言同样是基于.NET框架的C#语言或VB语言。Smart组件是Robotstudio软件中实现高级仿真功能的智能组件,软件自身提供的Smart组件包含信 与属性、传感器、建模、运动等子对象组件。当软件自带的Smart组件无法满足仿真需求的时候,我们就可以通过对Robotstudio软件的二次开发,开发出满足需求新的Smart组件。本期,再来为大家介绍一下Robotstudio软件中Smart组件的开发方法,我们还是从实现“Hello Word!”消息输出开始。
Robotstudio软件版本:RobotStudio 6.08
SDK版本:RobotStudio SDK.6.08
开发软件版本:Microsoft Visual Studio Professional 2019
一、开发环境配置
开发环境的搭建比较简单,在上一篇文章《基于C#语言的Robotstudio软件二次开发基础》中已经介绍过了,小伙伴可在文章列表中查看一下,这里不再赘述。
二、开发项目创建
1.创建新项目,项目模板选择ABB机器人提供的Smart组件二次开发模板“Robotstudio 6.08 Smart Component”。
2.配置新项目时可以对项目进行命名,修改项目保存位置。
三、代码编写
Signals用于设置Smart组件的信 属性,代码<IOSignal name=”SampleSignal” signalType=”DigitalInput”/>的含义:设置I/O信 名称为SampleSignal,信 类型为数字量输入。
SmartComponent1.xml完整程序代码如下所示:
<?xml version="1.0" encoding="utf-8" ?><lc:LibraryCompiler xmlns:lc="urn:abb-robotics-robotstudio-librarycompiler" xmlns="urn:abb-robotics-robotstudio-graphiccomponent" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:abb-robotics-robotstudio-librarycompiler file:///C:Program%20Files%20(x86)ABB%20Industrial%20ITRobotics%20ITSDKRobotStudio%20SDK%206.08LibraryCompilerSchema.xsd urn:abb-robotics-robotstudio-graphiccomponent file:///C:Program%20Files%20(x86)ABB%20Industrial%20ITRobotics%20ITSDKRobotStudio%20SDK%206.08GraphicComponentSchema.xsd"> <lc:Library fileName="SmartComponent1.rslib"> <lc:DocumentProperties> <lc:Author>President</lc:Author> <lc:Image source="SmartComponent1.png"/> </lc:DocumentProperties> <SmartComponent name="SmartComponent1" icon="SmartComponent1.png" codeBehind="SmartComponent1.CodeBehind,SmartComponent1.dll" canBeSimulated="false"> <Signals> <IOSignal name="Button" signalType="DigitalInput"/> </Signals> <Assets> <Asset source="SmartComponent1.dll"/> </Assets> </SmartComponent> </lc:Library></lc:LibraryCompiler>
CodeBehind.cs完整代码如下所示:
using System;using System.Collections.Generic;using System.Text;using ABB.Robotics.Math;using ABB.Robotics.RobotStudio;using ABB.Robotics.RobotStudio.Stations;namespace SmartComponent1{ /// <summary> /// Code-behind class for the SmartComponent1 Smart Component. /// </summary> /// <remarks> /// The code-behind class should be seen as a service provider used by the /// Smart Component runtime. Only one instance of the code-behind class /// is created, regardless of how many instances there are of the associated /// Smart Component. /// Therefore, the code-behind class should not store any state information. /// Instead, use the SmartComponent.StateCache collection. /// </remarks> public class CodeBehind : SmartComponentCodeBehind { /// <summary> /// Called when the value of an I/O signal value has changed. /// </summary> /// <param name="component"> Component that owns the changed signal. </param> /// <param name="changedSignal"> Changed signal. </param> public override void OnIOSignalValueChanged(SmartComponent component, IOSignal changedSignal) { if (changedSignal.Name == "Button") { Logger.AddMessage(new LogMessage("Hello World!")); } } }}
四、项目编译
项目编译之前需要对项目“生成事件”进行相关设置,否则编译时会出现一些错误。
1.VS软件中上方的“项目”菜单下点击“SmartComponent1属性”,在打开的对话框中左侧属性条中点选“生成事件”,然后在生成后事件命令行中将原TargetPath文件路径信息修改为D:Program Files (x86)ABB Industrial ITRobotics ITRobotStudio 6.08BinLibraryCompiler.exe。由于Smart组件开发程序编译过程中需要依赖LibraryCompiler.exe,将一些生成文件复制到项目文件目录中,因此,这里需要将LibraryCompiler.exe的文件目录添加进来。LibraryCompiler.exe的文件目录是Robotstudio软件安装目录的bin文件夹。若是Robotstudio软件安装时未修改安装位置,则这里无须再修改生成事件,直接编译生成即可。
2.设置完成后编译项目,编译成功后在项目文件目录中生成*.rslib 格式的Smart组件库文件,此文件即为我们二次开发的Smart组件,包含二次开发的所有功能。
五、运行测试
1.打开Robotstudio软件,新建一个机器人系统,系统选项保持默认即可。
2.软件“基本”菜单栏下,“导入模型库”按钮下拉菜单中点击“浏览库文件”,浏览到编译生成的*.rslib 格式Smart组件库文件SmartComponent1,并将其打开。
3.在弹出的验证Smart组件提示框中点击是,Smart组件被加载进来。
4.左侧布局浏览树中,右击加载进来的Smart组件,打开组件属性窗口,可以看到,我们开发的Smart组件中显示Button信 按钮。
5.点击“Button”按钮,信 被置位,信 指示灯被点亮,同时在软件下方的信息输出窗口中显示“Hello World!”。
The End
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!