机器人ROS学习:Ubuntu22.04安装ROS2和Moveit2实现运动规划

通过本篇文章学习,你可以收获以下内容:

  • 学会在 Ubuntu22.04 上安装 Moveit2
  • 学会下载编译运行 Moveit2 样例程序
  • 学会使用样例程序进行运动规划等

版本平台

  • 系统版本:ubuntu22.04
  • ROS2 版本:humble
  • Moveit 版本:moveit2-humble

1. 安装 Moveit2


1.1 安装Ubuntu操作系统和 ROS2

这里不在赘述,教程很多,注意我们使用的ubuntu版本和ros版本如上

1.2 安装Moveit2

目前 Moveit2 官方已经支持二进制安装,这里我们就直接使用下面命令即可

复制代码
sudo apt-get install ros-humble-moveit

2.编译 moveit2 测试程序

2.1 创建工作空间

复制代码
mkdir -p  ~/moveit2/src/

2.2下载代码

复制代码
cd moveit2/src/
git clone https://github.com/ros-planning/moveit2_tutorials.git

2.3 安装依赖包

安装依赖使用rosdepc(或rosdep)

复制代码
vcs import < moveit2_tutorials-main/moveit2_tutorials.repos
rosdepc install -r --from-paths . --ignore-src --rosdistro $ROS_DISTRO -y

2.4 编译代码

安装好依赖包后,将刚才的代码编译

复制代码
cd ../
colcon build --event-handlers desktop_notification- status- --cmake-args -DCMAKE_BUILD_TYPE=Release

3. 运行程序

终端source执行install下的bash,避免任意路径找不到程序

复制代码
source install/setup.bash
sudo sed -i  "source install/setup.bash" ~/.bashrc
ros2 launch moveit2_tutorials demo.launch.py rviz_tutorial:=true

添加 MotionPlanning 然后修改 group 拖拽机械臂执行运动规划。如果这里不能编译成功,请看目录5

4、编译问题

编译中可能缺少的包

复制代码
sudo apt install ros-humble-osqp-vendor
sudo apt install libgoogle-benchmark-dev
sudo apt install ros-humble-ament-cmake-google-benchmark
sudo apt install ros-humble-stomp
sudo apt-get install ros-humble-warehouse-ros-sqlite sqlite3
pip3 install pybind11

apt搜索包

复制代码
apt-cache search  xxx包名
#
apt-cache search osqp
#
apt-cache search stomp

注意:当补充了很多包,遇到py_binding_tools 报错,可以重新执行

复制代码
rosdepc install -r --from-paths . --ignore-src --rosdistro $ROS_DISTRO -y

5. pymoveit2

看到这里说明 moveit2_tutorials C++编译失败,可能是ros环境问题,缺少依赖包,配置错误等,由于我自己很多年没用c++,这里我们只能换python试试了

5.1 PyMoveIt2 使用教程

下载PyMoveIt2代码,安装依赖项并使用 colcon 构建,我的ros版本是humble,需要按环境替换${ROS_DISTRO}

复制代码
# Clone this repository into your favourite ROS 2 workspace
git clone https://github.com/AndrejOrsula/pymoveit2.git
# Install dependencies
rosdepc install -y -r -i --rosdistro ${ROS_DISTRO} --from-paths .
# Build
cd ../
colcon build --merge-install --symlink-install --cmake-args "-DCMAKE_BUILD_TYPE=Release"

在使用pymoveit2前,请确保您已经引用了ROS 2的工作空间,需要source

复制代码
source install/local_setup.bash

5.2 运行示例

为了演示 pymoveit2 的使用,代码中 examples 目录中包含了基本功能的脚本。更多示例可以在 ign_moveit2_examples 仓库中找到

我们先配置一个用于控制使用 MoveIt 2 的机器人的环境,下载脚本,并编译

复制代码
# Clone this repository into your favourite ROS 2 workspace
git clone https://github.com/AndrejOrsula/panda_ign_moveit2.git
cd panda_ign_moveit2/
# Import dependencies
vcs import < panda_ign_moveit2.repos
# Install dependencies
IGNITION_VERSION=fortress rosdep install -y -r -i --rosdistro ${ROS_DISTRO} --from-paths .
# Build
colcon build --merge-install --symlink-install --cmake-args "-DCMAKE_BUILD_TYPE=Release"

编译成功即可运行示例

相关推荐
欧云服务器7 天前
怎么让脚本命令可以同时在centos、debian、ubuntu执行?
ubuntu·centos·debian
智渊AI7 天前
Ubuntu 20.04/22.04 下通过 NVM 安装 Node.js 22(LTS 稳定版)
ubuntu·node.js·vim
winfreedoms7 天前
ROS2知识大白话
笔记·学习·ros2
The️7 天前
Linux驱动开发之Read_Write函数
linux·运维·服务器·驱动开发·ubuntu·交互
再战300年7 天前
Samba在ubuntu上安装部署
linux·运维·ubuntu
qwfys2007 天前
How to install golang 1.26.0 to Ubuntu 24.04
ubuntu·golang·install
木尧大兄弟7 天前
Ubuntu 系统安装 OpenClaw 并接入飞书记录
linux·ubuntu·飞书·openclaw
小虾爬滑丫爬7 天前
ubuntu上设置Tomcat 开机启动
ubuntu·tomcat·开机启动
老师用之于民7 天前
【DAY25】线程与进程通信:共享内存、同步机制及实现方案
linux·c语言·ubuntu·visual studio code
小虾爬滑丫爬7 天前
Ubuntu 上设置防火墙
ubuntu·防火墙