整理一下现在的资料:
使用Moveit的接口首先要注意一下你的ros版本(即Moveit 版本)
以下是move group c++ interface的官方说明:
ROS Melodic:
ROS Kinetic:
ROS Indigo:
然后具体使用可以参考古月大神的博客:
更高级的用法参考官方的github范例:
indigo:
kinectic及以上:
在ROS Indigo 下的简单示例:
下面提供下自己的配置文件和程序吧,参考了各位大佬的东西,过程中踩了很多坑,如果有提示什么找不到的错误,那很可能是你的配置不对,注意一下,因为这个包还有其他文件,所以配置里包含的比最少需要的多,要注意筛选。
package.xml
<?xml version="1.0"?>
<package>
<name>moveit_demo</name>
<version>1.0.0</version>
<description>lets moveit </description>
<maintainer email="565346370@qq.com">wxw</maintainer>
<license>BSD</license>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>roslaunch</build_depend>
<build_depend>roscpp</build_depend>
<build_depend>rospy</build_depend>
<build_depend>rostime</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>sensor_msgs</build_depend>
<build_depend>geometry_msgs</build_depend>
<build_depend>nav_msgs</build_depend>
<build_depend>move_base_msgs</build_depend>
<build_depend>actionlib</build_depend>
<build_depend>control_msgs</build_depend>
<build_depend>trajectory_msgs</build_depend>
<build_depend>tf</build_depend>
<build_depend>Eigen</build_depend>
<build_depend>moveit_core</build_depend>
<build_depend>moveit_ros_perception</build_depend>
<build_depend>moveit_ros_planning_interface</build_depend>
<build_depend>pluginlib</build_depend>
<build_depend>interactive_markers</build_depend>
<build_depend>moveit_msgs</build_depend>
<build_depend>interactive_markers</build_depend>
<build_depend>actionlib_msgs</build_depend>
<run_depend>interactive_markers</run_depend>
<run_depend>actionlib_msgs</run_depend>
<run_depend>Eigen</run_depend>
<run_depend>moveit_core</run_depend>
<run_depend>moveit_ros_perception</run_depend>
<run_depend>moveit_ros_planning_interface</run_depend>
<run_depend>pluginlib</run_depend>
<run_depend>interactive_markers</run_depend>
<run_depend>roscpp</run_depend>
<run_depend>rospy</run_depend>
<run_depend>rostime</run_depend>
<run_depend>std_msgs</run_depend>
<run_depend>sensor_msgs</run_depend>
<run_depend>geometry_msgs</run_depend>
<run_depend>nav_msgs</run_depend>
<run_depend>move_base_msgs</run_depend>
<run_depend>actionlib</run_depend>
<run_depend>control_msgs</run_depend>
<run_depend>trajectory_msgs</run_depend>
<run_depend>tf</run_depend>
<run_depend>moveit_commander</run_depend>
<run_depend>moveit_core</run_depend>
<run_depend>moveit_planners</run_depend>
<run_depend>moveit_plugins</run_depend>
<run_depend>moveit_ros</run_depend>
<run_depend>moveit_setup_assistant</run_depend>
<export> </export>
</package>
CMakeLists.txt
cmake_minimum_required(VERSION 2.8.3)
project(moveit_demo)
find_package(catkin REQUIRED COMPONENTS
roscpp
std_msgs
sensor_msgs
actionlib
actionlib_msgs
control_msgs
move_base_msgs
trajectory_msgs
cmake_modules
moveit_core
moveit_msgs
moveit_ros_planning_interface
)
catkin_package(
INCLUDE_DIRS
CATKIN_DEPENDS roscpp std_msgs sensor_msgs geometry_msgs nav_msgs actionlib move_base_msgs control_msgs trajectory_msgs interactive_markers moveit_core moveit_ros_perception moveit_ros_planning_interface pluginlib actionlib_msgs
)
include_directories(
${catkin_INCLUDE_DIRS}
)
link_directories(
${catkin_LIB_DIRS}
)
#lets moveit
add_executable(letsmoveit src/letsmoveit.cpp)
target_link_libraries(letsmoveit
${catkin_LIBRARIES}
)
letsmoveit.cpp
//letsmoveit.cpp
#include <moveit/move_group_interface/move_group.h>
#include <moveit/planning_scene_interface/planning_scene_interface.h>
#include <moveit_msgs/DisplayRobotState.h>
#include <moveit_msgs/DisplayTrajectory.h>
#include <moveit_msgs/AttachedCollisionObject.h>
#include <moveit_msgs/CollisionObject.h>
int main(int argc, char **argv)
{
ros::init(argc, argv, "movo_moveit");
ros::NodeHandle node_handle;
ros::AsyncSpinner spinner(1);
spinner.start();
moveit::planning_interface::MoveGroup group("right_arm");//right_arm对应moveit中选择的规划部分
// 设置发送的数据,对应于moveit中的拖拽
geometry_msgs::Pose target_pose1;
target_pose1.orientation.x= 0.424;
target_pose1.orientation.y = -0.637;
target_pose1.orientation.z = -0.325;
target_pose1.orientation.w = 0.554;
target_pose1.position.x = 0.805;
target_pose1.position.y = -0.348;
target_pose1.position.z = 1.213;
group.setPoseTarget(target_pose1);
// 进行运动规划,计算机器人移动到目标的运动轨迹,对应moveit中的plan按钮
moveit::planning_interface::MoveGroup::Plan my_plan;
bool success = group.plan(my_plan);
ROS_INFO("Visualizing plan 1 (pose goal) %s",success?"":"FAILED");
//让机械臂按照规划的轨迹开始运动,对应moveit中的execute。
if(success)
group.execute(my_plan);
ros::shutdown();
return 0;
}