How to replace the default ROS Planner

Official documents refer to: http: //wiki.ros.org/pluginlib

Sometimes, you may need to replace the default planner ROS replaced by another planner or our own planner. This involves setting up and configuring a new planner package.

The establishment of a new planner, roughly divided into the following steps:

1. To achieve nav_core package base_global_planner base_local_planner or interfaces, to create a new planner package.

2. Add the planner source code: PLUGINLIB_EXPORT_CLASS macro for registering planner, some of the ROS will not know what your class is a planner.

3. Add your_planner_plugin.xml in your project, for declaring your planner.

4. Add package.xml in the export. Of particular note here that, if you export looks like this:

    <export>
        <nav_core plugin="${prefix}/planner_plugin.xml" />
    </export>

So, be sure to remember to add in the package.xml:

  <build_depend>nav_core</build_depend>
  <exec_depend>nav_core</exec_depend>

Otherwise, you will find that compile all right, but I could not find move_base start your planner. It will come out similar to the following error:

Failed to create the your_planner/YourPlannerROS planner, are you sure it is properly registered and that the containing library is built? 
Exception: According to the loaded plugin descriptions the class your_planner/YourPlannerROS with base class type nav_core::BaseGlobalPlanner does not exist. 
Declared types are carrot_planner/CarrotPlanner global_planner/GlobalPlanner navfn/NavfnROS.

No matter how you debug the system could not find your planner.

5. The last step is to write CMakefileLists.txt. You must pay attention to install the lib files and plugin.xml file. Do not install, then sometimes failed to find these files failed:

install(TARGETS your_planner
       ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
       LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
       )

install(FILES your_planner_plugin.xml
    DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)

When using your own planner testing is recommended catkin_make_isolated --install compile and source install_isolated / setup.bash. Use devel_isolated / setup.bash sometimes you can not find the planner.

PS: If you find the time to debug or wrong, want to check the specific cause of the error, you can modify the following move_base this:

    //initialize the global planner
    try {
      planner_ = bgp_loader_.createInstance(global_planner);
      planner_->initialize(bgp_loader_.getName(global_planner), planner_costmap_ros_);
    } catch (const pluginlib::PluginlibException& ex) {
      ROS_FATAL("Failed to create the %s planner, are you sure it is properly registered and that the containing library is built? Exception: %s", global_planner.c_str(), ex.what());
      exit(1);
    }

Change it to:

    //initialize the global planner
    try {
      planner_ = bgp_loader_.createInstance(global_planner);
      planner_->initialize(bgp_loader_.getName(global_planner), planner_costmap_ros_);
    }
    catch (const pluginlib::LibraryLoadException& ex) {
        ROS_FATAL("pluginlib::LibraryLoadException");
        exit(1);
    }
    catch (const pluginlib::ClassLoaderException& ex) {
        ROS_FATAL("pluginlib::ClassLoaderException");
        exit(1);
    }
    catch (const pluginlib::LibraryUnloadException& ex) {
        ROS_FATAL("pluginlib::LibraryUnloadException");
        exit(1);
    }
    catch (const pluginlib::CreateClassException& ex) {
        ROS_FATAL("pluginlib::CreateClassException");
        exit(1);
    }
    catch (const pluginlib::PluginlibException& ex) {
      ROS_FATAL("Failed to create the %s planner, are you sure it is properly registered and that the containing library is built? Exception: %s", global_planner.c_str(), ex.what());
      exit(1);
    }

You can see the specific cause of the error, local planner and a global planner similar method.

Guess you like

Origin www.cnblogs.com/qyit/p/11390373.html