文章目录
- 前言
- 一、MoveIt Setup Assistant 是什么?
- 二、搭建步骤
- 拉取相关repo
- 创建项目文档
- 编辑moveit_description文件夹
- 编辑moveit_config文件夹
- MoveIt Setup Assistant 配置
- Launch moveit_setup_assistant
- 配置干涉关系
- 配置planning groups
- 配置ros2 controller
- 配置moveit controller
- 配置用户
- 配置生成路径
- 运行仿真
- 修改 moveit config 文件夹
- 总结
前言
之前写了一篇文章《从零开始搭建一个moveit2简单机械臂模型》如何通过urdf文件搭建一个简单机械臂模型并调用rviz做显示。本文将通过MoveIt Setup Assistant
来搭建一个机械臂,这台机械臂将包含urdf同时配置好srdf,动力学模型,init pose,ompl参数等文件。
一、MoveIt Setup Assistant 是什么?
MoveIt Setup Assistant 是 MoveIt 软件包的一部分,它是一个用于配置机器人和 MoveIt 的可视化工具。通过 MoveIt Setup Assistant,用户可以添加机器人的 URDF 模型以及定义其运动学参数和限制。还可以使用该工具创建运动规划场景,包括环境、终端姿态、插值器和碰撞检测等。MoveIt Setup Assistant 使用户可以快速轻松地设置 MoveIt,以便进行运动规划和控制。
二、搭建步骤
本文采用yaskawa motoman 搭建机械臂模型,选用型号为gp110
模型gitlab repo https://github.com/ros-industrial/motoman
拉取相关repo
命令如下:
mkdir moveit_robot_resources
cd moveit_robot_resources
git clone git@gitlab.com:ros-industrial/motoman.git
创建项目文档
命令如下:
cd moveit_robot_resources
ros2 pkg create --build-type ament_cmake gp110_moveit_config
ros2 pkg create --build-type ament_cmake gp110_moveit_description
编辑moveit_description文件夹
文件夹结构如下:
gp110_moveit_description
├── CMakeLists.txt
├── meshes
│ ├── collision
│ │ ├── base_link.stl
│ │ ├── link_1_s.stl
│ │ ├── link_2_l.stl
│ │ ├── link_3_u.stl
│ │ ├── link_4_r.stl
│ │ ├── link_5_b.stl
│ │ └── link_6_t.stl
│ └── visual
│ ├── base_link.stl
│ ├── link_1_s.stl
│ ├── link_2_l.stl
│ ├── link_3_u.stl
│ ├── link_4_r.stl
│ ├── link_5_b.stl
│ └── link_6_t.stl
├── package.xml
└── urdf
拷贝motoman/motoman_gp110_support/meshes/gp110
中的collinsion
与visual
文件夹到gp110_moveit_description/meshes
修改CMakeLists.txt
:
cmake_minimum_required(VERSION 3.8)
# 修改名字按照如下格式,moveit_resources_*_moveit_config前后缀要保留
project(moveit_resources_gp110_moveit_config)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
# find dependencies
find_package(ament_cmake REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)
ament_package()
# 关键增加下边一行
install(DIRECTORY meshes urdf DESTINATION share/${PROJECT_NAME})
修改package.xml
:
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>moveit_resources_gp110_moveit_config</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="example@example.com">dev</maintainer>
<license>TODO: License declaration</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>
拷贝motoman/motoman_resources/urdf
中的common_colors.xacro
与common_materials.xacro
到config目录
拷贝motoman/motoman_gp110_support/urdf/gp110_macro.xacro
到config目录
编辑moveit_config文件夹
文件结构如下:
gp110_moveit_config
├── CMakeLists.txt
├── config
│ ├── common_colors.xacro
│ ├── common_materials.xacro
│ ├── gp110_macro.xacro
│ └── gp110.urdf.xacro
| └── robot.urdf.xacro
├── launch
└── package.xml
└── .setup_assistant
修改CMakeLists.txt
:
cmake_minimum_required(VERSION 3.8)
project(moveit_resources_gp110_moveit_config)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
# find dependencies
find_package(ament_cmake REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)
ament_package()
install(DIRECTORY config launch DESTINATION share/${PROJECT_NAME})
修改package.xml
:
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>moveit_resources_gp110_moveit_config</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="example@example.com">dev</maintainer>
<license>TODO: License declaration</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<exec_depend>moveit_resources_gp110_moveit_description</exec_depend>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>
创建gp110.urdf.xacro
文件,其内容为:
<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="gp110">
<!-- Import robot arm -->
<xacro:include filename="gp110_macro.xacro" />
<!-- Set emviroment parameter. -->
<xacro:motoman_gp110 prefix="" mesh_path_prefix="package://moveit_resources_gp110_moveit_description"/>
</robot>
修改gp110_macro.xacro
为:
如下内容改了几句,后续均按照此规则修改。
<?xml version="1.0" ?>
<robot xmlns:xacro="http://ros.org/wiki/xacro">
<!-- <xacro:macro name="motoman_gp110" params="prefix"> -->
<xacro:macro name="motoman_gp110" params="prefix mesh_path_prefix">
<!-- <xacro:include filename="$(find motoman_resources)/urdf/common_materials.xacro"/> -->
<xacro:include filename="common_materials.xacro"/>
<!-- link list -->
<link name="${prefix}base_link">
<visual>
<geometry>
<!-- <mesh filename="package://motoman_gp110_support/meshes/gp110/visual/base_link.stl"/> -->
<mesh filename="${mesh_path_prefix}/meshes/visual/base_link.stl"/>
</geometry>
<xacro:material_yaskawa_blue/>
</visual>
<collision>
<geometry>
<mesh filename="${mesh_path_prefix}/meshes/collision/base_link.stl"/>
</geometry>
</collision>
</link>
<link name="${prefix}link_1_s">
<visual>
<geometry>
<mesh filename="${mesh_path_prefix}/meshes/visual/link_1_s.stl"/>
</geometry>
<xacro:material_yaskawa_blue/>
</visual>
<collision>
<geometry>
<mesh filename="${mesh_path_prefix}/meshes/collision/link_1_s.stl"/>
</geometry>
</collision>
</link>
...
创建robot.urdf.xacro
文件,其内容为:
<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="robot">
<!-- Import robot urdf file -->
<xacro:include filename="$(find moveit_resources_gp110_moveit_description)/urdf/gp110.urdf" />
</robot>
xacro
生成urdf文件:
cd moveit_robot_resources
xacro gp110_moveit_config/config/gp110.urdf.xacro -o gp110_moveit_description/urdf/gp110.urdf
check_urdf gp110_moveit_description/urdf/gp110.urdf
robot name is: gp110
---------- Successfully Parsed XML ---------------
root Link: base_link has 2 child(ren)
child(1): base
child(2): link_1_s
child(1): link_2_l
child(1): link_3_u
child(1): link_4_r
child(1): link_5_b
child(1): link_6_t
child(1): flange
child(1): tool0
修改.setup_assistant
:
moveit_setup_assistant_config:
urdf:
package: moveit_resources_gp110_moveit_config
relative_path: config/robot.urdf.xacro
srdf:
relative_path: config/robot.srdf
package_settings:
author_name: binglee
author_email: lilinxin75@gmail.com
generated_timestamp: 1686213224
control_xacro:
command:
- position
state:
- position
- velocity
modified_urdf:
xacros:
- control_xacro
control_xacro:
command:
- position
state:
- position
- velocity
编译项目:
$ colcon build --packages-up-to --cmake-args -DCMAKE_BUILD_TYPE=Release
Starting >>> moveit_resources_gp110_moveit_description
Finished <<< moveit_resources_gp110_moveit_description [0.14s]
Starting >>> moveit_resources_gp110_moveit_config
Finished <<< moveit_resources_gp110_moveit_config [0.07s]
Summary: 2 packages finished [0.28s]
$ . install/setup.bash
MoveIt Setup Assistant 配置
Launch moveit_setup_assistant
ros2 launch moveit_setup_assistant setup_assistant.launch.py
配置干涉关系
这里直接用默认关系
配置planning groups
点击Add Kin. Chain如下所示
配置ros2 controller
配置moveit controller
配置用户
配置生成路径
生成项目文件
现在退出即可
运行仿真
修改 moveit config 文件夹
修改robot.urdf.xacro
文件
<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="robot">
<xacro:arg name="initial_positions_file" default="initial_positions.yaml" />
<!-- Import robot urdf file -->
<!-- 修改此行如下 <xacro:include filename="$(find moveit_resources_gp110_moveit_config)/config/robot.urdf.xacro" /> -->
<xacro:include filename="$(find moveit_resources_gp110_moveit_description)/urdf/gp110.urdf" />
<!-- Import control_xacro -->
<xacro:include filename="robot.ros2_control.xacro" />
<xacro:robot_ros2_control name="FakeSystem" initial_positions_file="$(arg initial_positions_file)"/>
</robot>
修改CMakeLists.txt
文件
cmake_minimum_required(VERSION 3.22)
# project(gp110_moveit_config)
project(moveit_resources_gp110_moveit_config)
find_package(ament_cmake REQUIRED)
ament_package()
install(DIRECTORY launch DESTINATION share/${PROJECT_NAME}
PATTERN "setup_assistant.launch" EXCLUDE)
install(DIRECTORY config DESTINATION share/${PROJECT_NAME})
install(FILES .setup_assistant DESTINATION share/${PROJECT_NAME})
修改package.xml
文件
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<!-- <name>gp110_moveit_config</name> -->
<name>moveit_resources_gp110_moveit_config</name>
<version>0.3.0</version>
<description>
An automatically generated package with all the configuration and launch files for using the robot with the MoveIt Motion Planning Framework
</description>
<maintainer email="lilinxin75@gmail.com">binglee</maintainer>
<license>BSD</license>
<url type="website">http://moveit.ros.org/</url>
<url type="bugtracker">https://github.com/ros-planning/moveit2/issues</url>
<url type="repository">https://github.com/ros-planning/moveit2</url>
<author email="lilinxin75@gmail.com">binglee</author>
<buildtool_depend>ament_cmake</buildtool_depend>
<exec_depend>moveit_ros_move_group</exec_depend>
<exec_depend>moveit_kinematics</exec_depend>
<exec_depend>moveit_planners</exec_depend>
<exec_depend>moveit_simple_controller_manager</exec_depend>
<exec_depend>joint_state_publisher</exec_depend>
<exec_depend>joint_state_publisher_gui</exec_depend>
<exec_depend>tf2_ros</exec_depend>
<exec_depend>xacro</exec_depend>
<!-- The next 2 packages are required for the gazebo simulation.
We don't include them by default to prevent installing gazebo and all its dependencies. -->
<!-- <exec_depend>joint_trajectory_controller</exec_depend> -->
<!-- <exec_depend>gazebo_ros_control</exec_depend> -->
<exec_depend>controller_manager</exec_depend>
<exec_depend>moveit_configs_utils</exec_depend>
<exec_depend>moveit_resources_gp110_moveit_description</exec_depend>
<exec_depend>moveit_ros_move_group</exec_depend>
<exec_depend>moveit_ros_visualization</exec_depend>
<exec_depend>moveit_ros_warehouse</exec_depend>
<exec_depend>moveit_setup_assistant</exec_depend>
<exec_depend>robot_state_publisher</exec_depend>
<exec_depend>rviz2</exec_depend>
<exec_depend>rviz_common</exec_depend>
<exec_depend>rviz_default_plugins</exec_depend>
<exec_depend>tf2_ros</exec_depend>
<exec_depend>warehouse_ros_mongo</exec_depend>
<exec_depend>xacro</exec_depend>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>
修改launch 文件,每个launch均修改如下,为避免这一步最好在前期是packages使用moveit_resources_gp110_moveit_config创建
编译:
$ colcon build --packages-up-to --cmake-args -DCMAKE_BUILD_TYPE=Release
Starting >>> moveit_resources_gp110_moveit_description
Finished <<< moveit_resources_gp110_moveit_description [0.10s]
Starting >>> moveit_resources_gp110_moveit_config
Finished <<< moveit_resources_gp110_moveit_config [0.13s]
Summary: 2 packages finished [0.30s]
$ . install/setup.bash
运行:
$ ros2 launch moveit_resources_gp110_moveit_config demo.launch.py
插入一个简单的轨迹规划如下:
总结
以上就是今天要讲的内容,本文记录了全套使用MoveIt Setup Assistant
搭建机械臂的过程,中间也遇到一些问题,在本文中都有说说明。