1.运行时行为的概念
运行时行为(Runtime Behavior)是通过C#代码对机电一体化系统的对象进行控制以及定义其行为,适用于运动控制比较复杂的控制要求中。
2.创建运行时行为
打开运行时行为对话框的方式有三种。如图所示。
(1) 方式一

(2) 方式二

(3) 方式三

3.运行时行为参数含义


4.编辑器结构介绍

①引用命名空间。
②定义全局变量。
③数据连接,将程序的变量与MCD中的参数进行相互连接。
④初始化数据,仅在仿真开始时执行一次。
⑤清理工作,仅在仿真结束时执行一次。
⑥仿真操作步,每一个仿真步都在此处执行,主要用于动态控制工作。
⑦此处插入仿真刷新代码,当可以安全地读取和更改主控制循环之外的运行时变量时,将调用此函数。
⑧此处插入重绘仿真代码,这里可以使用运行时数据更新MCD组件显示。
例子(1):
按下按钮传送带以0.005米的速度前进,松开按钮就停止。

using System;
using NXOpen;
public class UserBehavior : BehaviorDef
{
TransportSurface TS;
SlidingJoint SJ; // 全局变量定义
public override void Define (IDefinitionContext access)
{
access.Connect("传输面_传送带", out TS);
access.Connect("滑动副_按钮", out SJ); // 关联变量
}
public override void Start (IRuntimeContext context)
{
// Insert start up code here
}
public override void Stop (IRuntimeContext context)
{
// Insert stopping code here
}
public override void Step (IRuntimeContext context, double dt)
{
if(SJ.Position > 0.00045) // 当滑动副的位置大于0.0045时 //
{
TS.ParallelSpeed = 0.05; // 则将0.05m/s赋予给传输面的平行速度 //
}
else
{
TS.ParallelSpeed = 0; // 否则将0m/s赋予给传输面的平行速度 //
}
}
public override void Refresh (IRuntimeContext context)
{
// Insert simulation refreshing code here. This is called when it is safe
// to read and change runtime variables outside of the main control loop.
}
public override void Repaint ()
{
// Insert simulation repainting code here. This is where you use the data
// taken from the runtime to update the display.
}
}演示场景下载:


少有人走的路



















