ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

What you need is to implement a global planner plugin that has service client built-in. Then, in a different node you implement a service server which is responsible for calculating the path each time it gets a service request.

ROS Services are explained Here

This is how to add a service client to the code shown by the Writing A Global Path Planner As Plugin in ROS tutorial:

Class Header

 //  SOME OTHER INCLUDE STATEMENTS
 #include "***YOUR MESSAGE TYPE HERE***"

 namespace global_planner {

 class GlobalPlanner : public nav_core::BaseGlobalPlanner {
      public:
        //  SOME CODE TO DECLARE PUBLIC MEMBERS

      private :
        //  SOME CODE TO DECLARE PRIVATE MEMBERS

        // service client declaration
        ros::ServiceClient service_;
  };
};

Class Implementation

 void GlobalPlanner::initialize(std::string name, costmap_2d::Costmap2DROS* costmap_ros){
   //  OTHER INITIALIZATION CODE

   // create a client for the path planning service
  service_ = private_nh.serviceClient<***YOUR MESSAGE TYPE HERE***>("plan");

  // wait for the service to be advertised and available
  service_.waitForExistence();
 }

then send a service request from inside of the body of the function GlobalPlanner::makePlan(), like so:

   bool GlobalPlanner::makePlan(const geometry_msgs::PoseStamped& start, const geometry_msgs::PoseStamped& goal,  std::vector<geometry_msgs::PoseStamped>& plan ){

  // initialize a message of your custom message type
  **YOUR MESSAGE TYPE** message_name;

   // CODE TO FILL IN YOUR CUSTOM MESSAGE

  // call the path planning service
  service_.call(message_name);

 // you must also process the service response (not shown here)
}

Don't forget to process the service response and store it to the variable name plan which is one of the parameters of the function GlobalPlanner::makePlan().

You will also have to modify your CMakeLists.txt file to include your custom message type. All about how to create a custom service message is explained here: Creating a ROS msg and srv tutorial

Note that this is not a cut-and-paste ready-to-go example. You will have to additionally:
- define a custom message
- create a service server
- fill in the service request, and
- process the service response

Hopefully this information is enough to get you started and that it also answers your question.