ROS从入门到放弃——安装Moveit及其使用

本文详细介绍了如何在ROS Melodic中安装Moveit,并通过实例展示了Move Group Python Interface的使用,包括关节目标规划、位姿目标规划、笛卡尔路径规划等操作,同时涵盖了附加和移除物体的场景模拟。
摘要由CSDN通过智能技术生成

参考

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
  • 1
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值