05 Master methods 主站方法

EtherCAT 伺服控制功能块实现 EtherCAT 是运动控制领域主要的通信协议,开源EtherCAT 主站协议栈 IgH 和SOEM 两个项目,IgH 相对更普及一些,但是它是基于Linux 内核的方式,比SOEM更复杂一些。使用IgH 协议栈编写一个应用程序,控制EtherCAT 伺服电机驱动器是比较简单的。但是要实现一个通用的EtherCAT 组件库(例如IEC61131-3 ,或者IEC61499功能块)就复杂一些了,例如动态地加入一个从站驱动器,通过组件控制某一个从站。本博文研究基于组件的EtherCAT 程序架构及其实现方法。 阅读详情

主站操作函数比较多,仅摘取对PDO数据处理的部分仅供参考。

/**03 Creates a new process data domain.
 *创建一个新的流程数据域。
 * For process data exchange, at least one process data domain is needed.
 * This method creates a new process data domain and returns a pointer to the
 * new domain object. This object can be used for registering PDOs and
 * exchanging them in cyclic operation.
 *对于进程数据交换,至少需要一个进程数据域。此方法创建一个新的进程数据域,
 *并返回一个指向新域对象的指针。该节点可用于注册和循环操作的pdo交换。
 * This method allocates memory and should be called in non-realtime context
 * before ecrt_master_activate().
 *这个方法分配内存,并且应该在非实时环境中'在ecrt master activate()之前'被调用。
 * \return Pointer to the new domain on success, else NULL.
 */
ec_domain_t *ecrt_master_create_domain(
        ec_master_t *master /**< EtherCAT master. */
        );

/**04 Obtains a slave configuration.
 *获取slave配置。
 * Creates a slave configuration object for the given \a alias and \a position
 * tuple and returns it. If a configuration with the same \a alias and \a
 * position already exists, it will be re-used. In the latter case, the given
 * vendor ID and product code are compared to the stored ones. On mismatch, an
 * error message is raised and the function returns \a NULL.
 *为给定的一个别名和一个位置元组创建一个从属配置对象并返回它。如果具有相同的别名和位置
 *的配置已经存在,它将被重用。在后一种情况下,将给定的供应商ID和产品代码与存储的ID和产品
 *代码进行比较。如果不匹配,则抛出一个错误消息并返回一个NULL。
 * Slaves are addressed with the \a alias and \a position parameters.
 * - If \a alias is zero, \a position is interpreted as the desired slave's
 *   ring position.
 * - If \a alias is non-zero, it matches a slave with the given alias. In this
 *   case, \a position is interpreted as ring offset, starting from the
 *   aliased slave, so a position of zero means the aliased slave itself and a
 *   positive value matches the n-th slave behind the aliased one.
 *从机是用一个别名和一个位置参数寻址的。—如果一个别名为零,一个位置将被解释为
 所需的从属环位置。如果一个别名是非零的,它将用给定的别名匹配一个slave。在这种
 情况下,\a的位置被解释为环形偏移,从别名从属器开始,所以零的位置意味着别名从属
 器本身,一个正值匹配别名从属器后面的第n个从属器。
 * If the slave with the given address is found during the bus configuration,
 * its vendor ID and product code are matched against the given value. On
 * mismatch, the slave is not configured and an error message is raised.
 *如果在总线配置期间找到具有给定地址的从服务器,则它的供应商ID和产品代码
 与给定值匹配。如果不匹配,则不配置从服务器并引发错误消息。
 * If different slave configurations are pointing to the same slave during bus
 * configuration, a warning is raised and only the first configuration is
 * applied.
 *如果在总线. configuration期间不同的从服务器配置指向相同的从服务器,则会引发一个警告,并且只应用第一个配置。
 * This method allocates memory and should be called in non-realtime context
 * before ecrt_master_activate().
 *这个方法分配内存,并且应该在非实时环境中在ecrt master activate()之前被调用。
 * \retval >0 Pointer to the slave configuration structure.
 * \retval NULL in the error case.
 */
ec_slave_config_t *ecrt_master_slave_config(
        ec_master_t *master, /**< EtherCAT master 主站*/
        uint16_t alias, /**< Slave alias. 从站假名*/
        uint16_t position, /**< Slave position.从站位置 */
        uint32_t vendor_id, /**< Expected vendor ID.期望的供应商ID */
        uint32_t product_code /**< Expected product code. 期望的产品代码*/
        );

/**05 Selects the reference clock for distributed clocks.
 *为分布式时钟选择参考时钟。
 * If this method is not called for a certain master, or if the slave
 * configuration pointer is NULL, then the first slave with DC functionality
 * will provide the reference clock.
 *如果某个主服务器没有调用此方法,或者从服务器的. configuration指针为NULL,
 那么第一个具有DC功能的从服务器将提供参考时钟。
 * \return 0 on success, otherwise negative error code.
 */
int ecrt_master_select_reference_clock(
        ec_master_t *master, /**< EtherCAT master. 主站*/
        ec_slave_config_t *sc /**< Slave config of the slave to use as the
                               * reference slave (or NULL).作为参考从站的从站配置(或为空) */
        );

/**06 Obtains master information.
 *得到主站的信息。
 * No memory is allocated on the heap in
 * this function.
 *在这个函数中,没有在堆上分配内存。
 * \attention The pointer to this structure must point to a valid variable.
 *
 * \return 0 in case of success, else < 0
 */
int ecrt_master(
        ec_master_t *master, /**< EtherCAT master 主站*/
        ec_master_info_t *master_info /**< Structure that will output the
                                        information 输出信息的结构体*/
        );

/**07 Obtains slave information.
 *获得从站信息。
 * Tries to find the slave with the given ring position. The obtained
 * information is stored in a structure. No memory is allocated on the heap in
 * this function.
 *尝试在给定的环位置找到从站。获得的信息存储在一个结构中。在这个函数中,没有在堆上分配内存。
 * \attention The pointer to this structure must point to a valid variable.
 *指向这个结构的指针必须指向一个有效的变量。
 * \return 0 in case of success, else < 0
 */
int ecrt_master_get_slave(

/**16 Finishes the configuration phase and prepares for cyclic operation.
 *完成配置阶段并准备循环操作。
 * This function tells the master that the configuration phase is finished and
 * the realtime operation will begin. The function allocates internal memory
 * for the domains and calculates the logical FMMU addresses for domain
 * members. It tells the master state machine that the bus configuration is
 * now to be applied.
 *这个函数告诉主机配置阶段已经完成,实时操作将开始。该函数为域分配内部内存,
 并计算域成员的逻辑FMMU地址。它告诉主状态机现在要应用总线配置。
 * \attention After this function has been called, the realtime application is
 * in charge of cyclically calling ecrt_master_send() and
 * ecrt_master_receive() to ensure bus communication. Before calling this
 * function, the master thread is responsible for that, so these functions may
 * not be called! The method itself allocates memory and should not be called
 * in realtime context.
 *这个函数被调用后,实时应用程序负责循环调用ecrt master send()和Ecrt master receive()
 *确保总线通信。在调用这个函数之前,主线程负责这个,所以这些函数可能不会被调用!方法本身
 *分配内存,不应该在实时上下文中调用。
 * \return 0 in case of success, else < 0
 */
int ecrt_master_activate(
        ec_master_t *master /**< EtherCAT master. */
        );

/**17 Deactivates the master.
 *
 * Removes the bus configuration. All objects created by
 * ecrt_master_create_domain(), ecrt_master_slave_config(), ecrt_domain_data()
 * ecrt_slave_config_create_sdo_request() and
 * ecrt_slave_config_create_voe_handler() are freed, so pointers to them
 * become invalid.
 *
 * This method should not be called in realtime context.
 */
void ecrt_master_deactivate(
        ec_master_t *master /**< EtherCAT master. */
        );

/**19 Sends all datagrams in the queue.
 *发送队列中的所有数据报。
 * This method takes all datagrams, that have been queued for transmission,
 * puts them into frames, and passes them to the Ethernet device for sending.
 *该方法将已排队等待传输的所有数据报放入帧中,并将其传递给以太网设备进行发送。
 * Has to be called cyclically by the application after ecrt_master_activate()
 * has returned.
 *必须在ecrt master activate()返回后由应用程序循环调用。
 */
void ecrt_master_send(
        ec_master_t *master /**< EtherCAT master. */
        );

/**20 Fetches received frames from the hardware and processes the datagrams.
 *从硬件中获取接收的帧并处理数据报。
 * Queries the network device for received frames by calling the interrupt
 * service routine. Extracts received datagrams and dispatches the results to
 * the datagram objects in the queue. Received datagrams, and the ones that
 * timed out, will be marked, and dequeued.
 *通过调用中断服务程序来查询网络设备接收到的帧。提取接收到的数据报,并将结果
 *分派给队列中的数据报对象。接收到的数据报和超时的数据报将被标记并退出队列。
 * Has to be called cyclically by the realtime application after
 * ecrt_master_activate() has returned.
 */
void ecrt_master_receive(
        ec_master_t *master /**< EtherCAT master. */
        );

/**22 Reads the current master state.
 *
 * Stores the master state information in the given \a state structure.
 *
 * This method returns a global state. For the link-specific states in a
 * redundant bus topology, use the ecrt_master_link_state() method.
 */
void ecrt_master_state(
        const ec_master_t *master, /**< EtherCAT master. */
        ec_master_state_t *state /**< Structure to store the information. */
        );
/**31 Retry configuring slaves.
 *重试配置从站
 * Via this method, the application can tell the master to bring all slaves to
 * OP state. In general, this is not necessary, because it is automatically
 * done by the master. But with special slaves, that can be reconfigured by
 * the vendor during runtime, it can be useful.
 *通过这个方法,应用程序可以告诉主站将所有从站设置为OP状态。一般来说,
 *这是不必要的,因为它是由主程序自动完成的。但是对于特殊的从站(可以由供应商
 *在运行时重新配置),它可能很有用。
 */
void ecrt_master_reset(
        ec_master_t *master /**< EtherCAT master. */
        );

IGH_Master主站配置驱动伺服电机和变频器总结 IGH_Master主站配置驱动伺服电机和变频器总结 Ethercat是倍福公司提出的一种工业现场总线协议,具有很好的实时性,IGH是一种开源的Ethercat主站实现协议,本文总结了一下使用IGH_Master驱动伺服电机和变频器的经验 阅读详情

相关推荐

IGH(ethercat)命令行不能进入OP原因

解决命令行不能让伺服进入OP模式的问题。

关注工业机器人应用 8963

2020-09-04

Igh1.5.2 etherCAT接口分析 用户空间库 本地应用程序接口驻留在内核空间中,因此只能从内核访问。 为了使应用程序接口在用户空间程序中可用,已经创建了一个用户空间库,该用户空间库可以根据LGPL版本2 [5]的条款和条件链接到程序。 这个库被命名为libethercat。 它的源代码驻留在lib /子目录中,并且在使用make时默认生成。 它被安装在安装前的lib /路径下,如libethercat.a(用于静态链接),libethercat.l...

chocolate2018的博客 4394

Apache与Nginx核心差异:进程模型、事件驱动与生产配置实践

Web服务器是现代应用交付的基石,其底层架构直接决定并发能力、资源开销与运维韧性。Apache基于多进程/多线程MPM模型,强调模块深度集成与运行时稳定性,适合PHP嵌入式部署和强认证场景;Nginx则采用异步非阻塞事件驱动架构,以极低内存支撑高并发,依赖FastCGI等标准协议实现语言解耦。这种根本性设计差异,导致二者在HTTPS配置、反向代理健壮性、大文件上传(413错误)定位路径、Brotli压缩支持及配置容错机制上表现迥异。理解进程模型与事件循环原理,是规避502网关错误、if指令陷阱、SSL环境变

weixin_30265103的博客 512

ubuntu22.04下Ethercat IGH DC同步实现

基于igh主站的电机ethercat DC同步通信 要在 Ubuntu 22.04 (Jammy Jellyfish) 中升级 ubuntu-advantage-tools 到 27.8,请运行命令: 要启用测试版实时内核,可运行: 需要验证实时性能,可以使用cyclitest,主要看max的值,经过14个小时时间,其最大值的延迟在230us左右,满足8ms为周期的控制 控制对象: 参考代码: 官方例程:dc_user,该例程以主站

LLiu_M__的博客 1万+

基于ModbusRTU和WebServer的PLC数据采集与监控系统

ModbusRTU作为工业现场广泛使用的串行通信协议,是连接PLC与上位机系统的关键桥梁。通过RS485总线,主站可周期读取从站寄存器数据,实现温度、压力、启停状态等设备参数的实时采集。结合WebServer技术,将采集到的数据以HTTP接口和可视化页面形式呈现,构成一套轻量级工业物联网解决方案。这种方案不仅适用于S7-200 SMART等中小型PLC,还能灵活扩展到多设备、多协议场景,帮助企业打破数据孤岛,降低数字化改造成本。文中完整演示了从PLC从站配置、Python主站数据采集到Flask前端展示的实

weixin_34054866的博客 345

用 Business Transaction Event 承接物料主数据变更,Material Master 增强里一个容易被低估的老接口

最近在处理 Material Master 相关增强时,我又翻到了一个很有年代感但依然很实用的增强点,Business Transaction Event,也就是很多 ABAP 顾问口中的 BTE。这个东西在 FI 领域更常见,大家一提到 FIBF,脑子里往往想到的是会计凭证、清账、付款、替代逻辑一类的场景。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 601

Android 内存分析方法记录三

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

蛰伏--当你不够强大时,就不要放弃努力 4836

【EtherCAT分析】一、EtherCAT主站代码解析

/ 任务周期(以 ns 为单位)#define MAX_SAFE_STACK (8 * 1024) //保证安全访问而不会出现故障的最大堆栈大小//常数PERIOD_NS: 定义了任务的周期,以纳秒(ns)为单位。在这里,周期被设置为 1000000 ns,即 1 毫秒。: 定义了最大的安全栈大小,单位是字节。在这里,最大安全栈大小被设置为 8 * 1024 字节,即 8 KB。这个值通常与实时系统中线程栈的大小相关,确保线程的栈不会溢出。: 定义了一秒钟内的纳秒数,即 1000000000 ns。

m0_56451176的博客 3509

EtherCAT使用与解析-ethercat空闲阶段函数解析

经过ethercat系统加载完成需要的内核模块后,一个是ec_master主站模块,另外一个就是ec_generic驱动模块,加载完成后,主站进入空闲阶段,开始执行空闲阶段函数./master/master.c/ec_master_idle_thread()空闲阶段函数,这里有个参数,该参数是thread_run开启线程函数时传递的,他指向主站空间。 整个的线程函数的流程如下: 1.接收数据帧...

lswdcyy的博客 1995

VS2015+C++实战:手把手教你用海康MVS里的Demo搞定多相机同步采图与保存

本文详细解析了在VS2015+C++环境下,利用海康威视MVS工业相机SDK实现多相机同步采图与保存的全流程。从环境准备、SDK选择到多相机初始化、同步采图方案,再到异常处理与性能优化,提供了实战技巧和代码示例,帮助开发者快速掌握工业相机二次开发的核心技术。

weixin_29170327的博客 286

信创改造实战:SpringBoot项目迁移到宝兰德BES 9.5.5的完整避坑指南(附依赖与web.xml配置)

本文详细介绍了将SpringBoot项目迁移到宝兰德BES 9.5.5的完整流程,包括依赖改造、web.xml配置降级等关键步骤。通过实战案例和避坑指南,帮助开发者高效完成国产中间件适配,确保项目平稳运行。特别针对Tomcat依赖排除和BES适配器选择提供了专业建议。

weixin_30689307的博客 758

igh ethercat DC同步 -- 基于rtai_rtdm_dc/main.c

/选择参考时钟,从机设备为sc_ek1100。通过线程休眠使主从站循环周期对齐,时间补偿调整休眠时间。DC同步分为静态同步:在非周期任务下同步 --- > 计算时钟偏移以及传输延时 --- >预运行阶段进行。

weixin_58059347的博客 1022

避坑实录:用certificate-manager重置vCenter 6.7证书时遇到的三个致命陷阱

本文详细解析了使用certificate-manager重置vCenter 6.7证书时可能遇到的三大致命陷阱,包括进度卡在85%的服务启动僵局、脚本突然退出的静默杀手以及密码错误锁死的隐藏机制。通过实战验证的解决方案和高级恢复技巧,帮助系统管理员有效避免vCenter环境瘫痪,确保证书更新过程顺利进行。

g5h6i7j的博客 925

ecrt_master_application_time

Added the distributed clocks feature and the respective method * ecrt_slave_config_dc() to configure a slave for cyclic operation, and * ecrt_master_application_time(), ecrt_master_sync_referenc...

老鹰不捉小鸡 1728

机器视觉应用工程师职位深度解析与面试指南

广东奥普特科技招聘机器视觉应用工程师,要求大专以上理工科专业背景,熟悉C/C++或PLC编程,具备自动化设备调试经验。岗位职责包括视觉项目方案评估、系统安装调试、售后技术支持及异常处理,需接受外派出差。该职位面向专业对口的应届生或实习生,强调动手能力、沟通技巧和吃苦耐劳精神。机器视觉工程师需掌握图像处理算法、硬件配置等核心技术,在工业自动化领域具有良好发展前景。求职者应注重编程能力和实践经验的积累,以胜任这一技术密集型岗位。

郑伟强dev的专栏 447

手把手教你学PCIE-- 热插拔电路设计与实现方案

PCIe热插拔(Hot-Plug)技术允许用户在系统运行时安全地插入或移除设备,而无需重启系统。本文将深入讲解热插拔电路的设计要点、关键器件选型及信号协议规范,涵盖机械结构、电气保护和电源管理三大核心模块。​。

MHD0815的博客 446

ethercat igh 应用层调用接口

是 IgH EtherCAT Master 提供的核心应用层接口头文件,它定义了与主站交互、配置从站、管理过程数据域 (Process Data Domain) 以及执行 SDO (Service Data Object) 访问等所需的函数、类型和常量。在使用时,请务必参考你所使用的具体 IgH EtherCAT Master 版本的头文件和官方文档。用于配置从站的同步管理器 (SyncManager, SM),主要用于 PDO 通信。配置必须在主站激活前完成。用于配置和管理支持 DC 的从站的时钟同步。

u013304893的博客 2186

【智能车Code review】—曲率计算、最小二乘法拟合

【1】曲率计算函数 选三个点计算曲率 float process_curvity(byte x1, byte y1, byte x2, byte y2, byte x3, byte y3) { float K; int S_of_ABC = ((x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1)) / 2; //面积的符号表示方向 byte q1 = (byte)((x2 - x1) * (x2 - x1) + (y2 - y1) *

hanhan的博客 1万+

IGH Master 主站CSP - Detail-ASD-A2-E

IGH Master 主站CSP - Detail-ASD-A2-E 示例

weixin_44687260的博客 683

华为OD机试真题:明日之星选举 (Java/Py/C/ C++/JS/GO)

华为OD机试(机考)双机位C卷 【明日之星选举】,提供Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试 - 明日之星选举。

qq_45776114的博客 929

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

IGH使用及配置

IGH常用命令总结及IGH主站初始化,基于ubuntu20.04

LLiu_M__的博客 3317

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

IGH 控制伺服的一个例子(验证中)

介绍了一个伺服控制的程序例子(使用子线程通讯交换数据),主线程与用户交互。还在测试中。

关注工业机器人应用 2436

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

igh ethercat 同步报文

ecrt_master_reference_clock_time:获取参考时钟的时间,同步主站时钟(返回值=参考时钟时间-参考时钟与主站的传输延迟)ecrt_master_sync_slave_clocks :1.获取参考时钟使主站同步参考时钟 2.FRMW,将参考时钟的时间发给dc从站。ecrt_master_sync_reference_clock_to:将sync_time发给参考时钟。ecrt_master_sync_reference_clock :将app_time发给参考时钟。

weixin_58059347的博客 691

IgH详解四、数据报接收流程

IgH通过调用ecrt_master_receive接口接收数据报文。 ec_device_poll接口调用的就是我们在实时网卡驱动中注册的ec_poll接口,以e1000为例 在初始化网卡驱动的时候会调用ecdev接口给协议栈注册网卡的轮询接收接口。 到这里也只是注册了接收接口,那又是怎么把报文传递给协议栈的呢?接收的数据报文是怎么处理的呢? 也是通过在网卡驱动中调用协议栈接收函数来实现的。 在网卡驱动中调用了协议栈的ecdev_receive函数,可以看到sk...

EtherCAT 3100

手把手教你将IgH EtherCAT Master移植到ARM开发板(Linux 4.19内核适配指南)

本文详细介绍了将开源IgH EtherCAT Master移植到ARM开发板(Linux 4.19内核)的完整流程。针对内核API变更、交叉编译环境搭建、关键代码适配等核心挑战,提供了从源码获取、配置编译到目标板部署、应用开发的实战指南,帮助工程师在嵌入式平台上构建实时工业网络主站系统。

kotlin6android的博客 376
上一篇: 04 ethercat(IGH)全局函数
下一篇: 06 Slave configuration methods 从站配置方法
leecheni
博客等级 码龄16年 1976粉丝 62原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址