ROS2_IGH方案配置(二)——EtherLab安装

前言

本次IGH配置准备采用EtherLab团队的协议站,借助Icube团队的ethercat_driver_ros2组件实现对接
https://icube-robotics.github.io/ethercat_driver_ros2/quickstart/usage.html
上一步完成了PREEMPT_RT的安装,现在进行IgH EtherCAT MASTER的安装

sudo apt-get update

sudo apt-get upgrade

sudo apt-get install git autoconf libtool pkg-config make build-essential net-tools

参考步骤如链接所示,注意,这里适配的版本为Ubuntu22.04 LTS

安装

首先在Home目录下创建一个文件夹
mkdir EtherLab

下载
git clone https://gitlab.com/etherlab.org/ethercat.git

clone完可以打开文件夹看看:nautilus .
后续步骤相同:

cd ethercat
git checkout stable-1.5
sudo rm /usr/bin/ethercat  #第一次装不需要
sudo rm /etc/init.d/ethercat#第一次装不需要
./bootstrap  # to create the configure script
编译模组

(每次更新内核都需要进行编译操作),非必要不更新。

./configure --prefix=/usr/local/etherlab  --disable-8139too --disable-eoe --enable-generic
make all modules
sudo make modules_install install
sudo depmod
添加符号关联
sudo ln -s /usr/local/etherlab/bin/ethercat /usr/bin/

sudo ln -s /usr/local/etherlab/etc/init.d/ethercat /etc/init.d/ethercat

sudo mkdir -p /etc/sysconfig

sudo cp /usr/local/etherlab/etc/sysconfig/ethercat /etc/sysconfig/ethercat

这一步骤类似于updatealternative中的符号关联操作,跟着做就对了。

sudo ln -s是一个命令行指令,用于在Linux和其他类Unix操作系统中创建符号链接。符号链接也被称为软链接或者快捷方式。
符号链接是一个特殊的文件类型,它指向另一个文件或者目录。当你打开或者访问符号链接时,实际上是访问指向的目标文件或者目录。
sudo ln -s命令的主要用途包括:
创建符号链接:使用该命令可以创建一个符号链接,并指定链接的名称和链接的目标。
创建软件包链接:在Linux系统中,软件包通常被安装到特定的目录中。使用符号链接,可以将软件包的可执行文件链接到系统路径中,以便在任何位置都可以访问。
维护链接:当你需要更改文件或者目录的位置时,可以使用该命令更新符号链接的目标。
创建快捷方式:符号链接可以用于创建在不同位置的文件之间的快捷方式,方便用户访问。

创建udev 规则

udev rule是一种在Linux系统上配置和管理设备的机制。它允许用户在设备插入、设备移除、设备属性更改等事件发生时执行特定的操作。
udev rule的作用主要包括以下几个方面:
自动设备管理:通过udev rule,可以自动地在设备插入时执行一些操作,如自动挂载磁盘、自动启动设备驱动程序等。
设备命名:在Linux系统中,设备通常以类似于/dev/sda的名称存在。udev rule可以用来定义自定义设备名称,为设备提供更加可读和易于识别的名称。
设备权限控制:udev rule可以用于控制设备文件的权限,以确保只有授权的用户或组可以访问设备。
触发特定操作:通过udev rule,可以在设备插入、移除或者属性更改时触发一些特定的操作,如运行脚本、发出通知、记录日志等。
动态创建设备节点:在一些情况下,设备可能不会在启动时创建设备节点,而是在设备插入时动态地创建。通过udev rule,可以实现自动创建设备节点的功能。

sudo gedit /etc/udev/rules.d/99-EtherCAT.rules

打开文件,往里面添加内容:
KERNEL=="EtherCAT[0-9]*", MODE="0666"
6表示读写权限(4+2),而0表示没有执行权限。0666表示所有者、组成员和其他用户都有读写权限,但没有执行权限。

设置主站网卡:
sudo gedit /etc/sysconfig/ethercat

MASTER0_DEVICE="ff:ff:ff:ff:ff:ff"mac address
DEVICE_MODULES=“generic”
找到对应行,并添加这两行内容进去,保存

启动主站
sudo /etc/init.d/ethercat start

打印结果:
在这里插入图片描述
ctrl+alt+T搞个新终端

ethercat slaves

输出:
在这里插入图片描述
PREOP +2HCS558-EC
<从站状态> + <device_0_name>

安装ethercat_driver_ros2

ROS2环境是必备的,这里,插件基于的开发环境是ROS2 humble,humble的安装过程略去
ROS2humble手册

cd ~/ros2_ws
git clone https://github.com/ICube-Robotics/ethercat_driver_ros2.git src/ethercat_driver_ros2
rosdep install --ignore-src --from-paths . -y -r
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release --symlink-install
source install/setup.bash

在这里插入图片描述 按照步骤进行操作

sudo rosdep init 
rosdep update

报错信息如下:

— stderr: ethercat_manager
CMake Warning at CMakeLists.txt:19 (add_executable):
Cannot generate a safe runtime search path for target
ethercat_sdo_srv_server because files in some directories may conflict with
libraries in implicit directories:
runtime library [libpython3.10.so.1.0] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/gkj/miniconda3/lib
Some of these libraries may not be found correctly.

Finished <<< ethercat_manager [4.63s]
— stderr: ethercat_interface
CMake Warning at CMakeLists.txt:24 (add_library):
Cannot generate a safe runtime search path for target ethercat_interface
because files in some directories may conflict with libraries in implicit
directories:
runtime library [libpython3.10.so.1.0] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/gkj/miniconda3/lib
Some of these libraries may not be found correctly.
In file included from /home/gkj/ros2_ws/src/ethercat_driver_ros2/ethercat_interface/src/ec_master.cpp:15:
/home/gkj/ros2_ws/src/ethercat_driver_ros2/ethercat_interface/include/ethercat_interface/ec_master.hpp:160:46: warning: missing initializer for member ‘ec_slave_config_state_t::operational’ [-Wmissing-field-initializers]
160 | ec_slave_config_state_t config_state = {0};
| ^
/home/gkj/ros2_ws/src/ethercat_driver_ros2/ethercat_interface/include/ethercat_interface/ec_master.hpp:160:46: warning: missing initializer for member ‘ec_slave_config_state_t::al_state’ [-Wmissing-field-initializers]
/home/gkj/ros2_ws/src/ethercat_driver_ros2/ethercat_interface/src/ec_master.cpp: In constructor ‘ethercat_interface::EcMaster::DomainInfo::DomainInfo(ec_master_t*)’:
/home/gkj/ros2_ws/src/ethercat_driver_ros2/ethercat_interface/src/ec_master.cpp:43:38: warning: missing initializer for member ‘ec_pdo_entry_reg_t::position’ [-Wmissing-field-initializers]
43 | const ec_pdo_entry_reg_t empty = {0};
| ^
/home/gkj/ros2_ws/src/ethercat_driver_ros2/ethercat_interface/src/ec_master.cpp:43:38: warning: missing initializer for member ‘ec_pdo_entry_reg_t::vendor_id’ [-Wmissing-field-initializers]
/home/gkj/ros2_ws/src/ethercat_driver_ros2/ethercat_interface/src/ec_master.cpp:43:38: warning: missing initializer for member ‘ec_pdo_entry_reg_t::product_code’ [-Wmissing-field-initializers]
/home/gkj/ros2_ws/src/ethercat_driver_ros2/ethercat_interface/src/ec_master.cpp:43:38: warning: missing initializer for member ‘ec_pdo_entry_reg_t::index’ [-Wmissing-field-initializers]
/home/gkj/ros2_ws/src/ethercat_driver_ros2/ethercat_interface/src/ec_master.cpp:43:38: warning: missing initializer for member ‘ec_pdo_entry_reg_t::subindex’ [-Wmissing-field-initializers]
/home/gkj/ros2_ws/src/ethercat_driver_ros2/ethercat_interface/src/ec_master.cpp:43:38: warning: missing initializer for member ‘ec_pdo_entry_reg_t::offset’ [-Wmissing-field-initializers]
/home/gkj/ros2_ws/src/ethercat_driver_ros2/ethercat_interface/src/ec_master.cpp:43:38: warning: missing initializer for member ‘ec_pdo_entry_reg_t::bit_position’ [-Wmissing-field-initializers]
/home/gkj/ros2_ws/src/ethercat_driver_ros2/ethercat_interface/src/ec_master.cpp: In destructor ‘virtual ethercat_interface::EcMaster::~EcMaster()’:
/home/gkj/ros2_ws/src/ethercat_driver_ros2/ethercat_interface/src/ec_master.cpp:69:20: warning: unused variable ‘slave’ [-Wunused-variable]
69 | for (SlaveInfo & slave : slave_info_) {
| ^~~~~
/home/gkj/ros2_ws/src/ethercat_driver_ros2/ethercat_interface/src/ec_master.cpp: In member function ‘void ethercat_interface::EcMaster::registerPDOInDomain(uint16_t, uint16_t, std::vector&, ethercat_interface::EcMaster::DomainInfo*, ethercat_interface::EcSlave*)’:
/home/gkj/ros2_ws/src/ethercat_driver_ros2/ethercat_interface/src/ec_master.cpp:209:32: warning: missing initializer for member ‘ec_pdo_entry_reg_t::position’ [-Wmissing-field-initializers]
209 | ec_pdo_entry_reg_t empty = {0};
| ^
/home/gkj/ros2_ws/src/ethercat_driver_ros2/ethercat_interface/src/ec_master.cpp:209:32: warning: missing initializer for member ‘ec_pdo_entry_reg_t::vendor_id’ [-Wmissing-field-initializers]
/home/gkj/ros2_ws/src/ethercat_driver_ros2/ethercat_interface/src/ec_master.cpp:209:32: warning: missing initializer for member ‘ec_pdo_entry_reg_t::product_code’ [-Wmissing-field-initializers]
/home/gkj/ros2_ws/src/ethercat_driver_ros2/ethercat_interface/src/ec_master.cpp:209:32: warning: missing initializer for member ‘ec_pdo_entry_reg_t::index’ [-Wmissing-field-initializers]
/home/gkj/ros2_ws/src/ethercat_driver_ros2/ethercat_interface/src/ec_master.cpp:209:32: warning: missing initializer for member ‘ec_pdo_entry_reg_t::subindex’ [-Wmissing-field-initializers]
/home/gkj/ros2_ws/src/ethercat_driver_ros2/ethercat_interface/src/ec_master.cpp:209:32: warning: missing initializer for member ‘ec_pdo_entry_reg_t::offset’ [-Wmissing-field-initializers]
/home/gkj/ros2_ws/src/ethercat_driver_ros2/ethercat_interface/src/ec_master.cpp:209:32: warning: missing initializer for member ‘ec_pdo_entry_reg_t::bit_position’ [-Wmissing-field-initializers]
/home/gkj/ros2_ws/src/ethercat_driver_ros2/ethercat_interface/src/ec_master.cpp: In static member function ‘static void ethercat_interface::EcMaster::setThreadRealTime()’:
/home/gkj/ros2_ws/src/ethercat_driver_ros2/ethercat_interface/src/ec_master.cpp:423:17: warning: ISO C++ forbids variable length array ‘dummy’ [-Wvla]
423 | unsigned char dummy[MAX_SAFE_STACK];
| ^~~~~
In file included from /home/gkj/ros2_ws/src/ethercat_driver_ros2/ethercat_interface/include/ethercat_interface/ec_slave.hpp:26,
from /home/gkj/ros2_ws/src/ethercat_driver_ros2/ethercat_interface/include/ethercat_interface/ec_master.hpp:25,
from /home/gkj/ros2_ws/src/ethercat_driver_ros2/ethercat_interface/src/ec_master.cpp:15:
/home/gkj/ros2_ws/src/ethercat_driver_ros2/ethercat_interface/include/ethercat_interface/ec_sdo_manager.hpp: In member function ‘size_t ethercat_interface::SdoConfigEntry::type2bytes(std::string)’:
/home/gkj/ros2_ws/src/ethercat_driver_ros2/ethercat_interface/include/ethercat_interface/ec_sdo_manager.hpp:113:3: warning: control reaches end of non-void function [-Wreturn-type]
113 | }
| ^


这里存在一些报错信息,可以略过,主要原因是conda环境与ros2环境冲突,暂时不处理
同样需要注意的是,colcon build时候的终端所在目录即是build目录,原作者是在src/ethercat_driver_ros2目录下build,这里我选择了在ros2_ws进行build操作,source的地方也相应发生变化。

### 如何使用树莓派构建机器人 #### 使用 SSH 连接树莓派并配置 ROS 节点 通过 SSH 登录到树莓派可以远程操作设备。假设 IP 地址已知,可以通过以下命令登录: `ssh clbrobot@IP地址`[^1]。 完成连接后,在 ROS 环境下启动底盘节点以初始化硬件驱动程序: ```bash roslaunch clbrobot bringup.launch ``` 此脚本通常用于加载必要的参数和服务,确保机器人能够正常运行。 #### 启动校准工具和动态重配置界面 为了调整机器人的运动性能,可执行以下 Python 脚本来校准角速度: ```bash rosrun rikirobot_nav calibrate_angular.py ``` 对于实时调节参数的功能,ROS 提供了一个图形化工具 `rqt_reconfigure`,允许用户修改 YAML 文件中的数值而无需重启系统: ```bash rosrun rqt_reconfigure rqt_reconfigure ``` 这一步骤有助于优化控制算法的表现[^1]。 #### 布线设计与实际应用案例分析 尽管具体的布线方式因项目需求不同有所差异,但一般原则包括合理规划线路走向、减少电磁干扰以及便于维护检修等工作流程。例如,当涉及直流电机驱动时,推荐采用 H 桥电路来实现双向旋转功能[^4]: 具体做法如下所示——将电机两端分别接到 L298N 的 OUT1 和 OUT2 接口处;同时注意电源正负极方向正确无误以免损坏元件。 #### 解决常见问题之 IGH 编译错误处理方法论探讨 如果遇到在 ARM 平台上编译 EtherCAT 协议栈失败的情况,则需切换至 X86 架构主机进行交叉编译后再移植回去安装即可解决问题。以下是完整的指令序列作为参考指南之一: ```bash ./configure --prefix=/agvwork/igh/ethercat-stable-1.5/etherlab \ --with-linux-dir=/opt/linux-headers-5.4.75-rt41-v7l \ --enable-8139too=no --enable-generic=yes make ARCH=arm CROSS_COMPILE=/opt/raspberry/tools-master/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf- ``` 上述过程可能耗时较长,请耐心等待直至全部完成为止[^3]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值