ROS, MoveIt, and OMPL
注意注意:本文基于的版本是ROS melodic(Melodic是基于python2)
第一步:环境setup,全部follow此tutorial的步骤
- 创建catkin的workspace, 以及安装moveit(从源代码安装)
# Install catkin the ROS build system
rosdep update
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install ros-melodic-catkin python-catkin-tools
# Install MoveIt is from pre-built binaries
sudo apt install ros-melodic-moveit
# Create A Catkin Workspace
mkdir -p ~/ws_moveit/src
- 我们要下载两个ROS packages,剩下的tutorial全是通过启动这两个包来进行的(注意一个ROS package下面可以有多个ROS node,需要指明启动ROS的哪个package里面的哪个node)
- 第一个ROS包:ROBOT_moveit_config,用来定义robot的;默认的机器人是Panda arm from Franka Emika,所以默认的定义的机器人ROS包是panda_moveit_config, panda代替了ROBOT。
- 第二个ROS包:下载ROS包moveit_tutorials。
cd ~/ws_moveit/src
git clone https://github.com/ros-planning/panda_moveit_config.git -b melodic-devel
git clone https://github.com/ros-planning/moveit_tutorials.git -b melodic-devel
- build一下ws_moveit(你的workspace)
cd ~/ws_moveit/src
rosdep install -y --from-paths . --ignore-src --rosdistro melodic
cd ~/ws_moveit
catkin config --extend /opt/ros/melodic --cmake-args -DCMAKE_BUILD_TYPE=Release
catkin build
source ~/ws_moveit/devel/setup.bash
echo 'source ~/ws_moveit/devel/setup.bash' >> ~/.bashrc
第二步:创建自己的机器人config package(有自己的机器人的必要步骤)
即自己的 robot_moveit_config package, 参考the MoveIt Setup Assistant tutorial.
第三步:Visualize a robot with the interactive motion planning plugin for RViz(非必要的步骤)
可视化机器人,并在rviz上有可交互的页面。Rviz是ROS最重要的可视化工具,MoveIt通过他支持的rviz插件,可以实现交互式选取start state与goal state, 测试motion planning等等。
- 运行roslaunch panda_moveit_config demo.launch rviz_tutorial:=true用于启动panda_moveit_config的ROS包,里面会启动planning_context.launch(用于加载描述robot的信息),启动move_group.launch(moveit的可运行程序),启动moveit_rviz.launch(启动rviz),
- 如果是第一次启动panda_moveit_config的ROS包,那么你会打开rviz,并有一个空的enviroment,没有机器人。我们需要添加motion planning的插件. 加完该motion planning插件,panda机器臂就出现在环境中。同时我们要对motion planning这个插件做一些关于robot的configuration。另外关于可视化,我们可以设置哪些项目是可见的,有四个东西可以显示。
- 机器人周围的环境(包括障碍物什么的,scene robot)
- 规划的路径(planned path)
- 绿色的起始状态(start state)
- 橙色的目标状态(goal state)
- 我们可以设置在motion planning插件中设置Use Collision-Aware IK,这样planned path可以不会与自己碰撞(碰撞的机械臂部分会变红)
- 所有都设置好以后,我们可以选取起始和目标状态,然后点 plan,rviz就会显示planned path。
Move Group Python Interface
该接口(以MoveGroup的ROS包的形式呈现)可以用来设置起始状态和目标状态,建立motion plan,在环境中添加障碍物等等。
- 启动moveit和机器人,即启动panda_moveit_config的ROS包。
- 启动moveit_tutorials的ROS包里面的node之一move_group_python_interface
roslaunch panda_moveit_config demo.launch
rosrun moveit_tutorials move_group_python_interface_tutorial.py
Motion planning API
在moveit里面,motion planner是通过插件的形式来加载的,因此还是在runtime加入。所以分为两步:
- 启动moveit机器人(panda_moveit_config包)
- 启动motion_planning_api node(moveit_tutorials包)。我们分为两步:
roslaunch panda_moveit_config demo.launch
roslaunch moveit_tutorials motion_planning_api_tutorial.launch
具体代码就是我们需要创建三个类对象,一个是RobotModel(通过RobotModelLoader来实现),一个是PlanningScene,还有planner_plugin_loader(通过ROS pluginlib library)。
加入OMPL Planner
如果要加入OMPL的planner, 启动moveit机器人的panda_moveit_config。关于motion planner的主要设置是在该panda_moveit_config下的config文件夹中的ompl_planning.yaml。Depending on the planning problem, MoveIt chooses between joint space and cartesian space for problem representation. 可以设置的主要参数有:
- longest_valid_segment_fraction(in ompl_planning.yaml):the discretization of robot motions used for collision checking and greatly affects the performance and reliability of OMPL-based solutions.
- A
motion
in this context can be thought of as an edge between two nodes in a graph, where nodes are waypoints along a trajectory. - The default motion collision checker in OMPL simply discretizes the edge into a number of sub-states to collision check.
- No continuous collision checking is currently available in OMPL/MoveIt!, though this is an area of the current discussion.
- For example, if longest_valid_segment_fraction = 0.01, then we assume that if an edge between two nodes is less than 1/100th of the state space, then we don’t need to explicitly check any sub-states along that edge, just the two nodes it connects.
- A
- maximum_waypoint_distance( found in the dynamic reconfigure file.): defines the same discretization of robot motions for collision checking, but it does so at an absolute level instead of using fractions of the state space.\
- For example, if
maximum_waypoint_distance = 0.1
, then if an edge is shorter than 0.1 in state space distance then we don’t explicitly check any sub-states along that edge. - If both longest_valid_segment_fraction and maximum_waypoint_distance are set, then the variable that produces the most conservative discretization (the one that would generate the most states to collision check on a given edge) is chosen.
- Set longest_valid_segment_fraction (or maximum_waypoint_distance) too low, and collision checking / motion planning will be very slow. Set too high and collisions will be missed around small or narrow objects.
- In addition, a high collision checking resolution will cause the path smoothers to output incomprehensible motions because they are able to “catch” the invalid path and then attempt to repair them by sampling around it, but imperfectly.
- For example, if
- projection_evaluator: take in a list of joints or links to approximate the coverage of configuration space. This settings is used by planners such as KPIECE, BKPIECE, LBKPIECE, and PDST. For more information read the corresponding publications.
enforce_joint_model_state_space
: enforces the use ofjoint space
for all plans.- By default, planning requests with orientation path constraints are sampled in cartesian space so that invoking IK serves as a generative sampler.
- By enforcing joint space, the planning process will use rejection sampling to find valid requests. Please note that this might increase the planning time considerably.
- Other Settings: Depending on the planner you are using, other settings are available for tuning/parameter sweeping. The default values for these settings are auto-generated in the MoveIt! Setup Assistant and are listed in the ompl_planning.yaml file – you are encouraged to tweak them.