众所周知,在TwinCAT开发环境的EtherCAT | Online界面可以实现大部分EtherCAT问题的诊断,比如查看主站和每个从上的OP状态,CRC校验错误计数等。下面介绍TwinCAT中的几个“隐藏”得比较深的工具。
以上内容都包含在3个文档中,强烈推荐至倍福虚拟学院“https://tr.beckhoff.com.cn”下载,值得详细研读:
1 EtherCAT仿真工具
本来这是为了配合TwinCAT Matlab/Simulink硬件在环调试的一个工具,也可以用于专门的自动化仿真软件与TwinCAT的IO接口。我发现它的另一个用途:练习EtherCAT故障诊断——因为工程师并不是随时都在车间,当谈到一个EtherCAT故障的现象如何、应该如何处理的时候,手边没有硬件是没有办法实操练习的。倍福工程师有相对较好的实验条件,可以在Demo架上测试,但是如果系统复杂、IO站很多时,仍然很难重现故障。
最简单的EtherCAT仿真环境是这样的:
例如在编程笔记本上测试时,扩展一个USB转以太网的转换器,电脑就有了两个独立的有线网卡,用网线把它们短接,就搭成了上述测试的硬件平台:
EtherCAT Simulation的配置也很简单:
(1) 导出EtherCAT 配置文件
从项目文件或者手动配置好EtherCAT网络后,设置使用的Adapter,然后导出EtherCAT配置文件:
(2) 手动添加EtherCAT Simulation
(3) 配置文件导入至Simulation
(4) 激活配置看结果
如果Adapter选择正确,EtherCAT驱动安装正确,双网卡互连,在EtherCAT Master的Topology窗体中可显示所有从站及状态。为了测试大型EtherCAT网络的仿真效果,本例中的配置了100个EK1100及若干XFC模块、紧凑驱动模块等:
EtherCAT Simulation可以模拟丢包、断线、WC等故障,既可以模拟短时故障,也可以模拟永久性故障:
该功能需要TE1111授权,试用版授权只能运行30min。倍福工程师使用EtherCAT Simulation练习EtherCAT诊断时,可以借用含完整授权的USB Dongle,倍福用户则需要购买。
仿真效果与CPU性能有关,抖动越小,周期越短,则仿真效果越好
对于带DC时钟的从站的仿真,比如伺服驱动、XFC模块等,只能仿真其EtherCAT接口,并不能仿真模块本身的内部功能。受硬件影响,仿真出来的DC特性也不及真正的物理从站设备。
EtherCAT Simulation的典型的应与仿真软件配合,仿真现场设备以辅助EtherCAT主站应用的虚拟调试。故障模拟可以从TwinCAT XAE触发,也可以从仿真软件触发。本例中的从XAE触发,仅仅是为了演示方便。
完整功能请参考:
2 EtherCAT 从站的Register
绝大多数时候,通过TwinCAT XAE中的EtherCAT Online界面、Slave Diagnose界面、TwinCAT 报警窗体就可以直观地诊断从站信息。那么这些信息是从哪里来的呢?它们一定是来自从站的Register,由主站进行采集并在TwinCAT XAE中以可视化的方式呈现。普通用户只要使用这些可视化界面就足够了,但是如果你想深入了解背后的机制,TwinCAT还提供了直接访问这些Register的通道。在从站的Advanced Setting页面选择最后一项“ESCAccess/Memory”:
输入Start Offset和Length,可以定义显示的起始地址和长度。那么哪些常用信息位于什么地址呢?
(1) 连接丢失计数器
Register 内存地址 | ||
(2) 无效帧计数器
(3) EtherCATOnline界面显示CRC
TwinCAT 中, EtherCAT主站的Online 页面总是以 word-oriented的方式显示计数值。但是默认的Online界面并不显示以上计数,需要在主站的Advanced Setting页面的Online View中进行设置:
勾选中0300等Register之后,就中以在Online中显示了:
(4) Frame到达从站端口的时间
(5) 历史诊断信息Register 0x10F3
(6) AL状态码Register 0x0134
配置错误:
运行时错误:
3 Frame时序分析
对于普通IO模块或者EtherCAT从站来说,EtherCAT Frame早到或者晚到甚至偶尔不到都影响不大,但是对于带DC时钟并启用了DC功能的EL模块或者EtherCAT从站来说,Frame晚到或者丢失就会引起报警。
那么Frame到底是什么时间到达特定的EtherCAT从站的呢?TwinCAT XAE中提供了可视化界面。以一个包含两个DC从站EL7201和EL7211的EtherCAT网络为例,控制器在Runing模式下,从EtherCAT Master的Advanced Setting界面打开Slave Diagnose窗体:
这里有几个术语要解释:
这几个术语所代表的时间点,在从站侧的相互关系为:
尝试修改主站和从站的Shift Time,然后在这个可视化界面显示时序图,可以更加深刻地理解EtherCAT分布时钟。当从站报Sync Lost时,就可以到这个界面进一步观察故障信息。详细的说明请参考:3_EtherCAT Synchronization -cn V2.pptx (Page48-60)
4 EtherCATframe的抖动
最理想的情况是每个任务周期EtherCAT Frame在相同的时间出发,但实际上受TwinCAT实时核抖动以及任务运算量波动的影响,Frame的实际出发时间总是和理论值有所偏差,包括正差(pos)和负差(neg)。TwinCAT XAE中在EtherCAT主站的Advanced Setting里提供DistributedClocks的Diagnosis功能,可以监视实际的波动情况:
上图显示最大偏差界于20-50us之间,按50us计算。如果这个偏差超过了任务周期的20-30%,就很容易发生同步错误。所以任务周期越短——比如低于1ms——发生同步错误的概率越大。如果最大偏差超过500us,那就不是同步任务的问题,而要检测EtherCAT网卡、驱动、TwinCAT实时核的问题了。比如在第三方PC上测试运行TwinCAT通常会发生抖动偏大的问题,对于有分布时钟要求的微秒级任务就可能会有影响。
5 完整的AL状态码解释
No eror No error | |
0x0001 | Unspecified error General Error which is not defined in the following list |
0x0002 | No Memory Local Application runs out of memory (e.g. dynamic memory allocation for emergency messages |
0x0011 | Invalid requested state change Requested state change is invalid(e.g. IS, IO, PO, PB, SB, OB) |
0x0012 | Unknown requested state Requested state change is unknown(e.g. if the requested state code is not 1, 2, 3 4, 8) |
0x0014 | No valid firmware The downloaded file is no valid firmware file |
0x0013 | Bootstrap not supported The device doesn't support Bootstrap state |
0x0015
| Invalid mailbox configurationThe maibox SyncManger configuration is not valid in Bootstrap state |
0x0016 | Invalid mailbox configurationThe mailbox SyncManger configuration is not valid in PREOP state |
0x0017 | Invalid sync manager configuration Sync manager configuration is not valid |
0x0018 | No valid inputs available Slave application cannot provide valid inputs |
0x0019 | Slave applicaton cannot receive valid outputs |
0x001A | Synchronization eror Multiple synchronization errors. Device is not synchronized any more(shall be used d no specific Synchronization error can be distinguished) |
0x001B | Sync manager watchdogNo process data recerved yet (s->O)or not received within a specifed timeout value |
0x001C | Invalid Sync Manager Types |
0x001D
| Invalid output Configuration SyncManger configuration for output process data is invalid |
0x001E | Invalid Input configurator SyndManger configuration for mput process data is invalid |
0x001F | Invalid watchdog configuration watchdog Settings are invalid (e.g. SyndManger watchdog trigger is enabled but no watchdog timeout is defined) |
0x0020 | Slave needs cold start evice requires a power off-power on reset |
0x0021 | Slave needs INIT pplication requests INIT state |
0x0022 | Slave needs PREOP Slave application requests PREOP state |
0x0023 | Slave needs SAFEOP Slave application requests SAFEOP state |
0x0024 | Invalid Input Mapping Input process data mapping do not match to expected mapping |
0x0025 | Invalid Output Mappingoutput process data mapping do not match to expected mapping |
0x0026 | Inconsistent Settings General settings mismatch |
0x0027 | Freerun not supported |
0x0028 | Synchronization not supported |
0x0029 | Freerun needs 3 Buffer ModeFreeRun Mode, sync manager has to run in 3-Bufler Mode |
0x002A | Background Watchdog |
0x002B | No Valid Inputs and Outputs |
0x002C | Fatal Sync Error Fatal Sync Error Synco or Sync1 are not received any more |
0x002D | No Sync Eror ync not receed: In SAFEOP the slave waits for the firstSyncorSync1 events before switching to OP if these events were not received during the SAFEOP to OP- Timeout time the ecode should refuse the state transition to oP with this al status(SystemTimeottset too big. no DC event received |
0x0030 | Invalid DC SYNC Configuration Distributed Clocks configuraton is invalid due to applicaton requirements |
0x0031 | Invalid DC Latch Configuration DC Latch connguration is invalld due to application requirements |
0x0032 | PLL ErTor Master not synchronized at least one DC event received |
0x0033 | DC Sync IO Error Mutuple synchronization errors. IO is not synchronized any more |
0x0034 | DC Sync Timeout ErrorMufuple synchronization errors. Too much SM Events missed |
0x0035 | DC Invalid Sync Cycle Time |
0x0036 | DC Synco Cyde Time DC Synco Cycle time does not fit to applicaton requrements |
0x0037 | DC Sync1 Cycle Time DC Sync1 cyde time does not nt to application requirements |
0x0041 | MBX_ AOE |
0x0042 | MBX EOE |
0x0043 | MBX COE |
0x0044 | MBX FOE |
0×0045 | MBX SOE |
0x004F | MBX VOE |
0x0050 | EEPROM No Access EEPROM not assigned to PDI |
0x0051 | EEPROM Error EEPROM access error |
0x0060 | Slave Restarted Locally |
0x0061 | Device ldentification value updated The device identifcation value was updated and is now valid |
0x00F0 | Application Controler avalable The local application releases the appcation controller which snow avadable and services the ethercAt state machine and all other device features This optional AL Status Code shall onty be used for devices that have a different power suppl for the ESC and the application controller and which cannot define a maximum timeout value for transition|→P NOTE: Use case can be if ESC is powered before applicaton controller. Err Indication can be used by Master to indicate that stave is ready for boot-up (instead of cchc polling) |