IgH EtherCAT Master 源码编译安装

本文档详细介绍了如何在Linux系统中下载、编译、安装IgHEtherCATMaster源码,并配置使其成为主站。包括了解压源码、配置编译选项、安装、启动主站以及解决编译过程中的常见问题。此外,还提供了设置 EtherCAT 开机自启动的方法,包括使用sysv-rc-conf工具和update-rc.d命令。同时,针对权限问题,给出了修改udev规则的步骤,确保程序正常运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


1.下载IgH EtherCAT Msater 源码:

http://http://www.etherlab.org/download/ethercat/ethercat-1.5.2.tar.bz2  版本为1.5.2

2.编译源码:

(1)解压源码包

tar -xjf ethercat-1.5.2.tar.bz2
cd ethercat-1.5.2/


(2)配置编译:
在运行./configure时要配置选项,我的配置是:

./configure --with-linux-dir=/usr/src/linux-header-3.14.29-29 --enable-8139too=no --enable-wildcards=yes
make
make modules

3. 安装:

make install
make modules_install
make DESTDIR=/vol/nfs/root modules_install</span>

4.配置主站:

安装完成后,会在/opt/目录下生成一个etherlab/文件夹,其中包括库文件什么的。进入这个文件夹:

cd /opt/etherlab

修改配置文件:
vim etc/sysconfig/ethercat

在MASTER0_DEVICE=""填写你的以太网卡的MAC地址,DEVICE_MODULES="generic",保存退出。

在/etc目录下新建一个sysconfig/的文件夹,将修改后的ethercat文件复制到刚刚新建的文件中:

mkdir /etc/sysconfig/
cp etc/sysconfig/ethercat  /etc/sysconfig/
ln -s /opt/etherlab/etc/init.d/ethercat  /etc/init.d/

为了让EtherCAT 主站能开机自启动,将ethercat设置为开机自启动服务。这里我采用的是sysv-rc-conf 工具,先安装sysv-rc-conf:
apt-get install sysv-rc-conf

安装完成后,运行sysv-rc-conf:
sysv-rc-conf

这时会打开一个图形界面,找到ethercat设置为S运行级,按Q退出。
先不要着急启动ethercat,还有关键的一步,运行如下的命令:

depmod

5.启动主站:
/etc/init.d/ethercat start

如果安装没有问题,会出现下面的提示:
Starting EtherCAT master 1.5.2  done

安装完毕。


设置Ether Master开机自启动:


1.通过sysv-rc-conf 来管理

如果没有安装,则通过下面的命令来安装:

apt-get install sysv-rc-conf

直接运行命令:

sysv-rc-conf

 启动,然后配置ethercat的运行级。这种方式在x86平台能成功,但是在arm平台没有用。采用第二种方法。


2.用自启动脚本控制命令:update-rc.d

添加ethercat开机自启动:update-rc.d ethercat start 2 3 5 .

此命令是最后空格加一点(.),会在rc3.d,rc5.d生成S02ethercat的链接。


3.invoke-rc.d

invoke-rc.d ethercat stop

invoke-rc.d ethercat start

修改ethercat设备权限:

运行程序时,要打开/dev/EtherCAT0文件需要root权限,为了不每次都手动修改权限,所以要设置。

运行:vim /etc/udev/rules.d/99-ethercat.rules

添加如下的内容:

KERNEL=="EtherCAT[0-9]",MODE="0777"

保存后退出,然后执行udevadm control --reload-rules,重启。

配置库:

vim /etc/ld.so.conf 

添加下面的内容,及库文件的绝对路径:

/opt/etherlab/lib

/usr/local/lib


安装过程中可能会出现的问题及解决办法:

1.在Linux环境中安装EtherCAT Master源码时,输入命令:

# make modules_install 

出现下面的错误:

/home/ethercat/ethercat-1.5.2/master/ethernet.c: In function ‘ec_eoe_init’:
/home/ethercat/ethercat-1.5.2/master/ethernet.c:151:72: error: macro "alloc_netdev" requires 4 arguments, but only 3 given
if (!(eoe->dev = alloc_netdev(sizeof(ec_eoe_t *), name, ether_setup))) {undefined
^
/home/ethercat/ethercat-1.5.2/master/ethernet.c:151:22: error: ‘alloc_netdev’ undeclared (first use in this function)
if (!(eoe->dev = alloc_netdev(sizeof(ec_eoe_t *), name, ether_setup))) {undefined

该错误提示函数alloc_netdev少一个参数,这可能是因为Linux内核版本问题,也可能是虚拟机的问题,因为我的Linux是安装在虚拟机里的。

解决办法就是打开错误提示的源文件:ethernet.c,给函数alloc_netdev增加一个参数:

eoe->dev = alloc_netdev(sizeof(ec_eoe_t *), name, NET_NAME_UNKNOWN,ether_setup)


2.在ARM平台运行./configure时出现下面的错误:

checking build system type... configure: error: cannot guess build type; you must specify one

这是因为没有指定编译平台,如下这样添加一个配置选项就可以了:

./configure --build=arm-linux

3.ARM平台有时会出现类似:
W: Failed to fetch http://za.archive.ubuntu.com/ubuntu/pool/main/e/eglibc/libc-bin_2.11.1-0ubuntu7.10_i386.deb
  Something wicked happened resolving 'za.archive.ubuntu.com:http' (-5 - No address associated with hostname)
的错误,这是因为DNS有问题,运行vim /etc/resolv.conf  修改如下:
nameserver 8.8.8.8
 

之前工作有接触到Ethercat 并学习实践了IghMaster库,现在不做这方面工作了把代码开源出来,希望对大家有用。 代码使用Source Insight 3.5编辑的,用其它编辑器可能会出现乱码。 压缩包中包含了 1.基于Ighmaster 1.5.2驱动Sanyo,泰科伺服电机做力矩模式运动的代码。包含电机使能/禁止使能,设置运行模式,控制模式,发送力矩控制命令,读取力矩反馈等功能。基于SDO方式实现的代码。 2. 基于Ighmaster 1.5.2 驱动Et100 Io板代码,基于PDO,SDO方式的Io控制及温湿度读取 3. 测试例子包括了介于原生驱动接口ioctl方式控制码和基于libethercat库的驱动代码。具体见源代码。 文档目录结构及简要说明 0.Ethercat调试记录.txt 自己调试Ethercat过程中碰到的问题及解决办法 1. libethercat\std 目录 编译Igh生成的ethecat库 2. libethercat\include Igh Master Ethercat库包含的头文件 3. scripts/ 自动生成从站信息的相关脚本文件,要生成从站信息,将该文件夹复制到开发板运行GenerateSlavesConfig.sh。 默认生成ec_common_configs_define.h和ec_common_configs_define.c文件,这两个文件会在libethercat\ec_common\ecat_common.c,libethercat\ec_common\ecat_common.h相关接口使用。 4. libethercat\ec_common 4.0 ec_common_configs_define.h ec_common_configs_define.c 由脚本scripts/GenerateSlavesConfig.sh自动生成的从站信息,包括从站PDO,SDO设置等,更具体的可以参照scripts/README.txt 4.1 ecat_common.h ecat_common.c 基于ibethercat\std 中的库的二次封装库,简化了PDO,SDO等操作 4.2 ecat_common_intermediate_interface.h ecat_common_intermediate_interface.c 与具体厂商相关的接口库,基于ecat_common.c中接口的实现,不同设备修改这两个文件中的接口进行适配。 目前该文件实现的山羊电机接口。主要实现的PDO接口的电机状态查询,上电开机,关机,操作模式设置,力矩设置等接口,不同电机的类似接口可以参照该文件实现,接口作用见名知意。 封装接口的关键是对象字典的操作,根据手册设置对象字典即可,标准的Ethercat接口伺服电机一般来说对象字典定义基本是一样的,可能稍微有差别 5. 标准Igh Master接口的使用例子 mytest目录 mytest/test_torque_sanyo_ioctl 基于ioctl接口的sanyo电机测试例子 mytest/test_torque_tec_ioctl 基于ioctl接口的泰科电机电机测试例子 mytest/test_torque_tec_lib 基于libethercat\std库接口的电机测试例子 mytest/test_torque2 基于libethercat\std库接口的电机测试例子2 mytest/test_io_board ET1100,IO板的测试例子 基于标准的Igh 库及iotcl接口可以参照该文件夹例子 6.二次封装接口库ecat_common_intermediate_interface.c的使用说明 使用步骤 (1)将编译生成的Igh库文件替换libethercat\std文件, 文件名可能要改成,或者不该也行,自己写Makefile时匹配库名称就行 (2)将 scripts/ 目录复制到开发运行GenerateSlavesConfig.sh脚本,将脚本生成的ec_common_configs_define.h ec_common_configs_define.h 复制到libethercat\ec_common 文件夹 (3)基于二次封装接口的电机一般操作参照demo.c 参照demo.c中的ethercat_init() 进行从站初始化 初始化后就可以调用ecat_common_intermediate_interface.c中接口对从站进行操作 比如 interpolation_2_ecat_set_slave_pwr_on()接口使能电机, interpolation_2_ecat_set_slave_pwr_off() 关闭电机 interpolation_2_ecat_set_slave_target_pos() 设置目标位置,对应位置模式操作 其它接口作用见参照具体实现 7.关于轴操作的几点说明 (1)每个轴对应一个从站,由alias,position确定,一般来说从站不多时alias=0固定不变,对不同轴根据positon确定。 例如使能和关闭不同的轴 int interpolation_2_ecat_set_slave_pwr_on(MasterSpecifiedInfo_T *master_specified_info, int slave_pos); int interpolation_2_ecat_set_slave_pwr_off(MasterSpecifiedInfo_T *master_specified_info, int slave_pos); 中slave_pos参数就对应不同的轴,slave_pos=0,axis1 slave_pos=1,axis2... (2)设置不同轴的操作模式,位置,力矩,速度模式 可以参照这个接口 int interpolation_2_ecat_set_slave_operation_model(MasterSpecifiedInfo_T *master_specified_info, int slave_pos, unsigned char operation_model) 代码已经托管在云上,可以直接通过git下载: https://gitee.com/wllw7176/MyEthercat-IGH-1.5.2.git
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xutingjie168

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值