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

编译成功即可运行示例

相关推荐
fruge2 小时前
ubuntu 22.04 编译安装nignx 报错 openssl 问题
数据库·ubuntu·postgresql
黑风风11 小时前
Ubuntu 22.04 上安装 PostgreSQL(使用官方 APT 源)
linux·ubuntu·postgresql
行星00812 小时前
Ubuntu 中安装 PostgreSQL 及常规操作指南
linux·ubuntu·postgresql
奋斗者1号12 小时前
提升WSL中Ubuntu编译速度的完整指南
linux·运维·ubuntu
郭老二12 小时前
【经验】Ubuntu中设置terminator的滚动行数、从Virtualbox复制到Windows时每行后多一空行
ubuntu
玄德公笔记12 小时前
ubuntu 22.04安装k8s高可用集群
linux·ubuntu·kubernetes·k8s·containerd·高可用集群·ubuntu 22.04
ZHOU_WUYI12 小时前
在 Ubuntu 上安装 NVM (Node Version Manager) 的步骤
linux·运维·ubuntu
简诚12 小时前
ubuntu 安装上传的 ffmpeg_7.1.1.orig.tar.xz并使用
linux·ubuntu·ffmpeg
EtherWanderer16 小时前
Ubuntu 24.04 LTS Chrome 中文输入法(搜狗等)失效?一行命令解决
linux·chrome·ubuntu
冰橙子id20 小时前
基于ubuntu安装hadoop
大数据·hadoop·ubuntu