Robotstudio软件二次开发:基于C#语言的Smart组件开发基础

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


上一篇:基于C#语言的Robotstudio软件二次开发基础

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年1月25日
下一篇 2020年1月25日

相关推荐