提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
原文链接 在这里,同时参考了Primary_student同学的IgH EtherCAT MASTER安装。本文的适配的版本为Ubuntu22.04 humble 的 LTS。
拟议的开发基于IgH EtherCAT Master。安装步骤总结如下:
验证您是否可以运行未签名的内核模块
Etherlab 是默认未签名的内核模块。要允许内核加载未签名的模块,您需要禁用安全启动。
验证安全启动是否已启用(您需要先安装“mokutil”):
sudo apt-get install mokutil
mokutil --sb-state
它应该打印:
SecureBoot disabled
如果打印:
SecureBoot enabled
然后您需要禁用安全启动。具体操作如下:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install git autoconf libtool pkg-config make build-essential net-tools
git clone https://gitlab.com/etherlab.org/ethercat.git
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前要注意检查系统是否安装了gcc-12, 这是编译过程中必需的编译器, 如果内核是用 gcc-12 编译的, 但是系统中没有安装该版本编译器,就会导致 接下来 make modules 阶段的失败, 为了解决这个问题, 安装正确版本的GCC。
gcc 是 GNU Compiler Collection 的缩写,是一种强大、广泛使用的编译器工具链,用于将代码(如C、C++、Objective-C等语言编写的源代码)编译成可执行的二进制文件。GCC 在开源软件社区特别受欢迎,是Linux和许多其他操作系统的默认编译器。其功能包括编译、汇编和链接代码,并且支持跨平台编译、优化、调试和分析等多种功能。
主要功能
编译源代码:将高层次的编程语言(如C或C++)转换为机器代码,以便在特定平台上运行。
优化:可以生成经过优化的代码,提升程序的执行效率。
调试:与调试工具(如gdb)结合,帮助程序员进行错误排查。
跨平台支持:可以在一种架构上编译生成适用于另一种架构的程序。
sudo apt update
sudo apt install gcc-12 g++-12
export CC=gcc-12 # 设置 gcc-12 为当前编译器(仅针对本次编译)
在 /home/xxx/ethercat 目录下重新运行后续指令:
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
sudo gedit /etc/udev/rules.d/99-EtherCAT.rules
加入文档:
KERNEL=="EtherCAT[0-9]*", MODE="0666"
sudo gedit /etc/sysconfig/ethercat
在Ubuntu上查看MAC地址
ifconfig
找到对应行,将ff:ff:ff:ff:ff:ff由自己的mac地址代替,并将这两行内容输入进去,保存
MASTER0_DEVICE="ff:ff:ff:ff:ff:ff" mac address
DEVICE_MODULES=“generic”
sudo /etc/init.d/ethercat start
它应该打印
Starting EtherCAT master 1.5.3 done
ethercat slaves
它应该打印连接的从属设备的信息:
<id> <alias>:<position> <device_state> + <device_name>
例子:
0 0:0 PREOP + <device_0_name>
0 0:1 PREOP + <device_1_name>
代码如下(示例):
source /opt/ros/humble/setup.bash
或者把这行加入到下面文档中
sudo gedit ~/.bashrc
sudo apt install python3-colcon-common-extensions
mkdir ~/ros2_ws/src
cd ~/ros2_ws
git clone https://github.com/ICube-Robotics/ethercat_driver_ros2.git src/ethercat_driver_ros2
确保已安装hardware_interface库,这是ros2_control库的一部分。运行以下命令以安装相关依赖项:
sudo apt update
sudo apt install ros-humble-ros2-control ros-humble-hardware-interface
更新CMAKE_PREFIX_PATH:如果hardware_interface库已经安装,但CMake仍然无法找到它,可以尝试手动设置CMAKE_PREFIX_PATH。在构建之前运行以下命令:
export CMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH:/opt/ros/humble
确认是否安装了rosdep:
sudo apt install python3-rosdep2
rosdep install --ignore-src --from-paths . -y -r
sudo rosdep init # 这步可能不需要,如果出现新开一个终端 sudo nano /etc/hosts 将raw.githubusercontent.com 的所有可可能的ip 添入 # [rosdep init 错误解决终极方法(药到病除)](https://blog.csdn.net/weixin_46398948/article/details/120047411)
rosdep update
最后运行以下命令继续构建工作区:
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release --symlink-install
source install/setup.bash