通过c++接口调用Moveit进行编程

整理一下现在的资料:

使用Moveit的接口首先要注意一下你的ros版本(即Moveit 版本)

以下是move group c++ interface的官方说明:

ROS Melodic:

https://ros-planning.github.io/moveit_tutorials/doc/move_group_interface/move_group_interface_tutorial.html

ROS Kinetic:

http://docs.ros.org/kinetic/api/moveit_tutorials/html/doc/move_group_interface/move_group_interface_tutorial.html

ROS Indigo:

http://docs.ros.org/indigo/api/moveit_tutorials/html/doc/pr2_tutorials/planning/src/doc/move_group_interface_tutorial.html

 

然后具体使用可以参考古月大神的博客:

http://www.guyuehome.com/455

 

更高级的用法参考官方的github范例:

indigo:

https://github.com/ros-planning/moveit_tutorials/blob/indigo-devel/doc/pr2_tutorials/planning/src/motion_planning_api_tutorial.cpp

kinectic及以上:

https://github.com/ros-planning/moveit_tutorials/blob/kinetic-devel/doc/move_group_interface/src/move_group_interface_tutorial.cpp

在ROS Indigo 下的简单示例:

下面提供下自己的配置文件和程序吧,参考了各位大佬的东西,过程中踩了很多坑,如果有提示什么找不到的错误,那很可能是你的配置不对,注意一下,因为这个包还有其他文件,所以配置里包含的比最少需要的多,要注意筛选。

package.xml



moveit_demo
1.0.0
lets moveit 
wxw
BSD
catkin
roslaunch
roscpp
rospy
rostime
std_msgs
sensor_msgs
geometry_msgs
nav_msgs
move_base_msgs
actionlib
control_msgs
trajectory_msgs
tf
Eigen
moveit_core
moveit_ros_perception
moveit_ros_planning_interface
pluginlib
interactive_markers
moveit_msgs
interactive_markers
actionlib_msgs


interactive_markers
actionlib_msgs
Eigen
moveit_core
moveit_ros_perception
moveit_ros_planning_interface
pluginlib
interactive_markers
roscpp
rospy
rostime
std_msgs
sensor_msgs
geometry_msgs
nav_msgs
move_base_msgs
actionlib
control_msgs
trajectory_msgs
tf
moveit_commander
moveit_core
moveit_planners
moveit_plugins
moveit_ros
moveit_setup_assistant
 

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 
#include 

#include  
#include  
#include  
#include  

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;
}

 

你可能感兴趣的:(ROS的那些坑)