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

编译成功即可运行示例

相关推荐
Linux运维技术栈3 小时前
多系统 Node.js 环境自动化部署脚本:从 Ubuntu 到 CentOS,再到版本自由定制
linux·ubuntu·centos·node.js·自动化
bianshaopeng5 小时前
ubuntu go 环境变量配置
开发语言·ubuntu·golang
Fireworkitte17 小时前
Ubuntu、CentOS、AlmaLinux 9.5的 rc.local实现 开机启动
linux·ubuntu·centos
sword devil90018 小时前
ubuntu常见问题汇总
linux·ubuntu
我是哈哈hh2 天前
【MySQL】在UBuntu环境安装以及免密码登录入门
linux·数据库·mysql·ubuntu
clever1013 天前
在ubuntu系统上离线安装jenkins的做法
ubuntu·servlet·jenkins
Nie_Xun3 天前
ubuntu网络共享
linux·运维·ubuntu
wuicer4 天前
ubuntu 20.04 安装anaconda以及安装spyder
linux·运维·ubuntu
shuangrenlong4 天前
ubuntu更新chrome版本
linux·chrome·ubuntu
基于python的毕设4 天前
C语言栈的实现
linux·c语言·ubuntu