• ROS入门(八) make_plan的Server连接


    在move_base里面,将起始点和终点规划路径并且离散化。

    主要是一个叫做make_plan的Service。

    #include <ros/ros.h>
    #include <nav_msgs/GetPlan.h>
    #include <move_base_msgs/MoveBaseActionGoal.h>
    #include <geometry_msgs/PoseStamped.h>
    #include <geometry_msgs/PointStamped.h>
    #include <boost/foreach.hpp>
    #define forEach BOOST_FOREACH
    
    nav_msgs::GetPlan srv;
    ros::Publisher goal_pub;
    ros::ServiceClient plan_client;
    
    void callPlanningService(ros::ServiceClient plan_client, nav_msgs::GetPlan &srv)
    {
      if(plan_client.call(srv)){
        if(!srv.response.plan.poses.empty())
        {
          forEach(const geometry_msgs::PoseStamped &p, srv.response.plan.poses)
          {
            ROS_INFO("x = %f, y =%f",p.pose.position.x, p.pose.position.y);
          }
        }
        else
        {
          ROS_INFO("EMPTY PLAN.");
        }
      }
      else
      {
        ROS_ERROR("Failed to call service.");
      }
    }
    
    
    void clicked_point(const geometry_msgs::PointStamped& msg)
    {
      //ROS_INFO("Got clicked point:[%f,%f,%f]", msg.pose.x, msg.pose.y, msg.pose.z);
    
      nav_msgs::GetPlan srv;
      move_base_msgs::MoveBaseActionGoal goal;
    
      geometry_msgs::PoseStamped goalPos;
      goalPos.header.frame_id = "map";
      goalPos.header.stamp = ros::Time::now();
      goalPos.pose.position.x = 1.63;
      goalPos.pose.position.y = 2.9;
      goalPos.pose.position.z = 0;
      goalPos.pose.orientation.x = 0;
      goalPos.pose.orientation.y = 0;
      goalPos.pose.orientation.z = 0.115;
      goalPos.pose.orientation.w = 0.99;
    
      srv.request.start.header.stamp = ros::Time::now();
      srv.request.start.header.frame_id = "map";
      srv.request.start.pose.position.x  = msg.point.x;
      srv.request.start.pose.position.y  = msg.point.y;
      srv.request.start.pose.position.z  = 0;
      srv.request.start.pose.orientation.x  = 0;
      srv.request.start.pose.orientation.y  = 0;
      srv.request.start.pose.orientation.z  = 0;
      srv.request.start.pose.orientation.w  = 1;
      //srv.request.goal.header.frame_id = "map";
      srv.request.goal = goalPos;
      srv.request.tolerance = 0.5;
    
      goal.goal.target_pose = goalPos;
      goal_pub.publish(goal);
      callPlanningService(plan_client, srv);
    }
    
    
    
    int main(int argc, char** argv)
    {
      ros::init(argc, argv, "send_goal");
      ros::NodeHandle n;
      goal_pub=n.advertise<move_base_msgs::MoveBaseActionGoal>("/goal",10);
      plan_client=n.serviceClient<nav_msgs::GetPlan>("/move_base/make_plan");
      ros::Subscriber clickedpoint=n.subscribe("/clicked_point", 100, clicked_point);
    
      ros::spin();
      return 0;
    }

    参考资料:  

    Nav_msgs docs:

    http://docs.ros.org/api/nav_msgs/html/srv/GetPlan.html

    csdn的make_plan资料:

    http://blog.csdn.net/yiranhaiziqi/article/details/52891312

  • 相关阅读:
    关于智能本质的思考
    Effective C++ 条款39
    【视频教程】JEECG 入门视频教程大全+历史版本号代码下载
    HDU 4859(Bestcoder #1 1003)海岸线(网络流之最小割)
    最简单的基于FFMPEG的音频编码器(PCM编码为AAC)
    android经常使用的电话操作
    Vmware中为Mac Os安装vmtools
    win10.10 激活
    VM11安装Mac OS X 10.10
    win7系统升家庭版级为旗舰版的方法
  • 原文地址:https://www.cnblogs.com/TIANHUAHUA/p/8516431.html
Copyright © 2020-2023  润新知