ROS从入门到放弃——安装Moveit及其使用
1. 安装流程
rosdep update
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install ros-melodic-catkin python-catkin-tools
sudo apt install ros-melodic-moveit
2.小测试前的准备
mkdir -p ~/ws_moveit/src
git clone https://github.com/ros-planning/moveit_tutorials.git -b melodic-devel
git clone https://github.com/ros-planning/panda_moveit_config.git -b melodic-devel
⚠️ For now we will use a pre-generated
panda_moveit_config
package but later we will learn how to make our own in the MoveIt Setup Assistant tutorial.
cd ~/ws_moveit/src
rosdep install -y --from-paths . --ignore-src --rosdistro melodic
cd ~/ws_moveit
catkin_make
source ~/ws_moveit/devel/setup.bash
3. 小测试
roslaunch panda_moveit_config demo.launch rviz_tutorial:=true
Collision-aware IK:会一直尝试寻找是否有没有Collision的做法。
4. Move Group Python Interface
在3的基础上继续,先看效果:
rosrun moveit_tutorials move_group_python_interface_tutorial.py
具体解释:
import sys
import copy
import rospy
# 提供了MoveGroupCommander,PlanningSceneInterface,RobotCommander这3个类
import moveit_commander
import moveit_msgs.msg
import geometry_msgs.msg
from math import pi
from std_msgs.msg import String
from moveit_commander.conversions import pose_to_list
之后代码主要部分为class MoveGroupPythonIntefaceTutorial(object):
我们一个一个看它其中的函数
4.0 辅助函数 all_close(goal,actual,tolerance)
对比两个列表中的数字之差是否大于Tolerance
def all_close(goal, actual, tolerance):
"""
Convenience method for testing if a list of values are within a tolerance of their counterparts in another list
@param: goal A list of floats, a Pose or a PoseStamped
@param: actual A list of floats, a Pose or a PoseStamped
@param: tolerance A float
@returns: bool
"""
all_equal = True
if type(goal) is list:
for index in range(len(goal)):
if abs(actual[index] - goal[index]) > tolerance:
return False
elif type(goal) is geometry_msgs.msg.PoseStamped:
return all_close(goal.pose, actual.pose, tolerance)
elif type(goal) is geometry_msgs.msg.Pose:
return all_close(pose_to_list(goal), pose_to_list(actual), tolerance)
return True
4.1 Init
def __init__(self):
super(MoveGroupPythonIntefaceTutorial, self).__init__()
## 首先初始化 `moveit_commander`_ 和一个名为move_group_python_interface_tutorial的`rospy`_ node:
moveit_commander.roscpp_initialize(sys.argv)
rospy.init_node('move_group_python_interface_tutorial', anonymous=True)
# 初始化一个RobotCommander的对象,它会提供机器人运动学和当前joint state的信息。
# Rappel: RobotCommander是moveit_commander中的一个类
robot = moveit_commander.RobotCommander()
# 创建一个PlanningSceneInterface对象,用于改变机器人内部对于周围世界的理解。
# Rappel: PlanningSceneInterface是moveit_commander中的一个类
scene = moveit_commander.PlanningSceneInterface()
# 这里我们Planning的Group是panda_arm,这个名字可以在RViz的Planning Group下拉框中看到
# 也可以用robot.get_group_names得到
# 用于Plan和Excute不同的动作:
# Rappel: MoveGroupCommander是moveit_commander中的一个类
group_name = "panda_arm"
move_group = moveit_commander.MoveGroupCommander(group