使用新力川步进电机测试ether cat-igh的环境搭建

#1.树莓派4B作为主控
#2.开关电源24V明纬供电
#3.新力川ethercat步进控制器CL3-E57H
#4.新力川42步进闭环电机LC42H249

#使用了以上四个部件,来搭建现有的测试硬件环境

#使用命令行测试正常
#ethercat软件的安装需要从码云上git最新的
# https://gitee.com/cheni/ethercat.git
#这个是从github上镜像过来的,速度比较快,安装到最新版的ubuntu没有太多异常,可以正常运行。

 

 

#一开始遇到不能找到从站的问题,主要是配置文件中有点儿问题

#两个地方都要改才行

MASTER0_DEVICE="e4:5f:01:27:1b:3c"
DEVICE_MODULES="generic"

#------------------------------------------------------------------------------
#
#  EtherCAT master configuration file for use with init.d.
#
#  $Id$
#
#  vim: spelllang=en spell tw=78
#
#------------------------------------------------------------------------------

#
# Main Ethernet devices.
#
# The MASTER<X>_DEVICE variable specifies the Ethernet device for a master
# with index 'X'.
#
# Specify the MAC address (hexadecimal with colons) of the Ethernet device to
# use. Example: "00:00:08:44:ab:66"
#
# Alternatively, a network interface name can be specified. The interface
# name will be resolved to a MAC address using the 'ip' command.
# Example: "eth0"
#
# The broadcast address "ff:ff:ff:ff:ff:ff" has a special meaning: It tells
# the master to accept the first device offered by any Ethernet driver.
#
# The MASTER<X>_DEVICE variables also determine, how many masters will be
# created: A non-empty variable MASTER0_DEVICE will create one master, adding a
# non-empty variable MASTER1_DEVICE will create a second master, and so on.
#
# Examples:
# MASTER0_DEVICE="00:00:08:44:ab:66"
# MASTER0_DEVICE="eth0"
#
MASTER0_DEVICE="e4:5f:01:27:1b:3c"
#MASTER1_DEVICE=""

#
# Backup Ethernet devices
#
# The MASTER<X>_BACKUP variables specify the devices used for redundancy. They
# behaves nearly the same as the MASTER<X>_DEVICE variable, except that it
# does not interpret the ff:ff:ff:ff:ff:ff address.
#
#MASTER0_BACKUP=""

#
# Ethernet driver modules to use for EtherCAT operation.
#
# Specify a non-empty list of Ethernet drivers, that shall be used for
# EtherCAT operation.
#
# Except for the generic Ethernet driver module, the init script will try to
# unload the usual Ethernet driver modules in the list and replace them with
# the EtherCAT-capable ones. If a certain (EtherCAT-capable) driver is not
# found, a warning will appear.
#
# Possible values: 8139too, e100, e1000, e1000e, r8169, generic, ccat, igb.
# Separate multiple drivers with spaces.
#
# Note: The e100, e1000, e1000e, r8169, ccat and igb drivers are not built by
# default. Enable them with the --enable-<driver> configure switches.
#
DEVICE_MODULES="generic"

#
# List of interfaces to bring up and down automatically.
#
# Specify a space-separated list of interface names (such as eth0 or
# enp0s1) that shall be brought up on `ethercatctl start` and down on
# `ethercatctl stop`.
#
# When using the generic driver, the corresponding Ethernet device has to be
# activated before the master is started, otherwise all frames will time out.
# This the perfect use-case for `UPDOWN_INTERFACES`.
#
UPDOWN_INTERFACES=""

#
# Flags for loading kernel modules.
#
# This can usually be left empty. Adjust this variable, if you have problems
# with module loading.
#
#MODPROBE_FLAGS="-b"

#------------------------------------------------------------------------------

查看了一下dmesg命令,也有相关信息

 

 

### 使用 EtherCAT 读取电机电流 在工业自动化领域,EtherCAT 是一种广泛使用的现场总线协议。为了实现通过 EtherCAT 协议读取连接设备(如伺服驱动器)中的特定参数(例如电机电流),通常需要配置相应的寄存器地址并发送请求命令。 对于 EtherCAT 设备而言,在每个子报文中确实存在32位的空间可以用来指定目标节点以及内部的具体变量位置[^1]。当涉及到访问像电机电流这样的监控量时,则要依据所选用硬件产品的手册来确定确切的数据映射关系——即知道在哪一部分存储着代表实际测量值得二进制编码。 下面给出一段基于 Python 和 pysoem 库的简单示例程序片段,展示怎样初始化通信链路并向选定从站发出查询指令获取其当前工作状态下流经绕组内的电流量: ```python import time from pysoem import * if __name__ == '__main__': # 初始化上下文对象 ctx = Context() # 打开主站接口 if not open_master(ctx): raise Exception("Failed to open master") try: # 寻找网络上的所有从站 scan_bus(ctx) # 获取第一个找到的从站实例 slave_0 = get_next_slave(None, None) # 假设我们要操作的是位于索引为0x6071的对象属性(这通常是绝对值型模拟输入通道),它可能对应于某些品牌控制器里的实时采样所得之相电流强度。 obj_index = 0x6071 subindex = 0 while True: process_state_machine(ctx) # 运行状态机 # 发送/接收PDO交换过程... # 准备好缓冲区准备接受返回的结果 value_buffer = bytearray(4) # 调用API函数执行SDO下载动作以取得远端物理量表示形式 result = read_sdo(slave_0, obj_index, subindex, value_buffer) if result != SOEM_RES_SUCCESSFUL: print(f"Error reading SDO {result}") break current_value = int.from_bytes(value_buffer[:4], byteorder='little', signed=True)/1e3 # 将字节数组转换成浮点数,并假设原始单位是mA级别 print(f'Motor Current: {current_value:.3f} A') time.sleep(0.5) # 控制刷新频率 finally: close_master(ctx) ``` 这段代码展示了如何利用 `pysoem` 库建立与 EtherCAT 网络之间的联系,并尝试周期性的向某台已知类型的运动控制单元询问有关电动机电流通信的信息。需要注意的是这里选取的对象索引 (`obj_index`) 及其对应的子索引 (`subindex`) 参数取决于具体型号的手册说明;此外还应该考虑到不同厂商可能会采用不一样的编码规则去表达同样的物理意义。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

leecheni

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

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

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

打赏作者

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

抵扣说明:

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

余额充值