机器人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"

编译成功即可运行示例

相关推荐
杰锅就是爱情17 小时前
OpenObserve Ubuntu部署
linux·运维·ubuntu
心随_风动18 小时前
Ubuntu 文件复制大师:精通cp命令完整指南
数据库·ubuntu·postgresql
空灵之海1 天前
Ubuntu Server 22.04.5系统安装教程
linux·运维·ubuntu
kk5791 天前
【Ubuntu】sudo apt update出现E :仓库***没有Release文件
linux·运维·ubuntu
~光~~1 天前
【问题解决】VMware +Ubuntu20.04创建用户后无法登陆的问题
ubuntu
PAQQ1 天前
解决 ubuntu 重启串口号变化
linux·运维·ubuntu
desssq1 天前
ubuntu 18.04 泰山派编译报错
linux·运维·ubuntu
喵喵爱自由1 天前
Ubuntu 24.04 Server 版系统安装及配置
数据库·ubuntu
清风笑烟语1 天前
Ubuntu 24.04 搭建k8s 1.33.4
linux·ubuntu·kubernetes
CheungChunChiu1 天前
嵌入式 Linux 启动机制全解析:从 Boot 到 Rootfs
linux·运维·服务器·ubuntu·uboot·boot·extboot