安装 ROS 2 和 Colcon
如果您在接下来的几个步骤中遇到错误,一个好的开始是返回并确保您已正确安装 ROS 2。用户通常忘记的一个是获取 ROS 2 安装本身。
安装rosdep以安装系统依赖项: sudo apt install python3-rosdep 安装 ROS 2 后,请确保您拥有最新的软件包:
sudo rosdep init
rosdep update
sudo apt update
sudo apt dist-upgrade
这里如果出错,把rosdep换成rosdepc
sudo apt-get install python3-pip
sudo pip3 install rosdepc
使用mixin安装Colcon ROS 2 构建系统:
sudo apt install python3-colcon-common-extensions
sudo apt install python3-colcon-mixin
colcon mixin add default https://raw.githubusercontent.com/colcon/colcon-mixin-repository/master/index.yaml
colcon mixin update default
安装vcstool:
sudo apt install python3-vcstool
创建 Colcon 工作区并下载教程
对于教程,您需要有一个colcon工作区设置。
mkdir -p ~/ws_moveit2/src
进入您的 Colcon 工作区并拉取 MoveIt 教程源:
cd ~/ws_moveit2/src
sudo apt install git
git clone https://github.com/ros-planning/moveit2_tutorials -b humble --depth 1
接下来我们将下载 MoveIt 其余部分的源代码:
vcs import < moveit2_tutorials/moveit2_tutorials.repos
这里如果出错是网络问题,github DDS受到污染。
打开/home/**/ws_moveit2/src/moveit2_tutorials.repos
repositories:
launch_param_builder:
type: git
url: https://github.com/PickNikRobotics/launch_param_builder
version: main
moveit2:
type: git
url: https://github.com/ros-planning/moveit2
version: humble
moveit_resources:
type: git
url: https://github.com/ros-planning/moveit_resources
version: ros2
moveit_task_constructor:
type: git
url: https://github.com/ros-planning/moveit_task_constructor.git
version: ros2
moveit_visual_tools:
type: git
url: https://github.com/ros-planning/moveit_visual_tools
version: ros2
rosparam_shortcuts:
type: git
url: https://github.com/PickNikRobotics/rosparam_shortcuts
version: ros2
srdfdom:
type: git
url: https://github.com/ros-planning/srdfdom.git
version: ros2
在src目录下分别用git clone ***下载到7个文件夹内。可以尝试在网址前面加上:https://ghproxy.com/ ,后面加 -ros2/-humble。
(实践发现:如果有-humble分支最好用这个,没有的话用ros2)
git clone https://ghproxy.com/https://github.com/PickNikRobotics/launch_param_builder -b main
git clone https://ghproxy.com/https://github.com/ros-planning/moveit2 -b humble
git clone https://ghproxy.com/https://github.com/ros-planning/moveit_resources -b humble
git clone https://ghproxy.com/https://github.com/ros-planning/moveit_task_constructor.git -b humble
git clone https://ghproxy.com/https://github.com/ros-planning/moveit_visual_tools -b ros2
git clone https://ghproxy.com/https://github.com/PickNikRobotics/rosparam_shortcuts -b ros2
git clone https://ghproxy.com/https://github.com/ros-planning/srdfdom.git -b ros2
sudo apt autoremove ubuntu-desktop
sudo apt install ubuntu-desktop
设置Colcon 工作区
来源 Colcon 工作区:
source ~/ws_moveit2/install/setup.bash
可选:将上一个命令添加到您的.bashrc:
echo 'source ~/ws_moveit2/install/setup.bash' >> ~/.bashrc
运行样例程序
ros2 launch moveit2_tutorials demo.launch.py rviz_tutorial:=true
添加MotionPlanning后可看到机械臂。