ROS2应用
系统配置:ubuntu22.04
ROS2版本:humble
ROS2环境配置
- 更新下载源
PowerShell
sudo apt update- 输入ros2下载指令
PowerShell
wget http://fishros.com/install -O fishros && . fishros设备连接至虚拟机
- 查看设备
PowerShell
ll /dev/ttyUSB*- 建立端口映射
PowerShell
sudo gedit /etc/udev/rules.d/99-serial-imu.rules- 填写映射文件内容
PowerShell
KERNEL=="ttyUSB*", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", MODE:="0777", SYMLINK+="imu-serial"- 保存退出,运行命令使规则生效
PowerShell
sudo udevadm trigger
sudo service udev reload
sudo service udev restart- 验证
PowerShell
ll /dev/imu-serial导入准备好的压缩包
飞书同级目录下有IMU_ROS2.zip
通过文件传输软件传输到虚拟机中
安装IMU_Library库
PowerShell
# 下载解压IMU_ROS2压缩文件后,进入到IMU_Library目录下,运行setup.py
cd IMU_ROS2/IMU_Library
# 安装库及其依赖
pip install -e .
# 或使用setup.py安装
python setup.py installpython相关库安装
PowerShell
sudo pip3 install pyserial
sudo pip3 install smbus2构建ROS2项目
- 返回到~/IMU_ROS2目录
PowerShell
cd IMU_ROS2
colcon build --symlink-install- 把工作目录~/IMU_ROS2写入到环境变量中
PowerShell
# 编辑 ~/.bashrc
sudo gedit ~/.bashrc
# 把下面命令写到末尾
source ~/IMU_ROS2/install/setup.bash编译成功后,执行以下命令查看imu_ros2功能包下是否有可执行文件
ros2 pkg executables imu_ros2
开启ROS2节点
PowerShell
source install/setup.bash
ros2 run imu_ros2 imu_publisherIMU数据打印
- 打开新的终端,查看imu话题
PowerShell
ros2 topic list- 打印/imu/data话题数据
PowerShell
ros2 topic echo /imu/data- 打开新的终端,查看msg话题
PowerShell
ros2 topic echo /imu/magRViz2可视化
- 运行命令,打开rviz可视化界面
PowerShell
ros2 launch imu_ros2 imu_visualization.launch.py常见问题
- 启动节点如出现打开失败,请尝试以下指令
PowerShell
# 在~/IMU_ROS2目录下运行
source install/setup.bash
# 端口号问题
sudo chmod 666 /dev/imu-serial