0

Rosanswers logo

Hi

I have created a custom planner following this tutorial:

http://wiki.ros.org/navigation/Tutorials/Writing%20A%20Global%20Path%20Planner%20As%20Plugin%20in%20ROS

I created the files:

GA_global_planner.cpp and GA_global_planner.h

Also, I needed other utility classes:

Path.cpp, Path.h, Map.cpp, Map.h, GenericPathPlanner.cpp, GenericPathPlanner.h , OccupancyGridMap.cpp, OccupancyGridMap.h , all are necessary for the planning.

This is part of GA_global_planner.h,

#include "GenericPathPlanner.h"
#include "OccupancyGridMap.h"
#include "Map.h"
#include "Path.h"
class GAGlobalPlannerROS : public nav_core::BaseGlobalPlanner, public GenericPathPlanner 

NOTE: that the class GAGlobalPlannerROS inherits both BaseGlobalPlanner and GenericPathPlanner

NOTE: that the class OccupancyGridMap inherits public from class Map

I can successfully compile and build the package of this planner.

However, when I try to use the planner with move_base got error:

[FATAL] [1623866783.746869597, 0.412000000]: Failed to create the GA_planner/GAGlobalPlannerROS planner, are you sure it is properly registered and that the containing library is built? Exception: Failed to load library /home/evadro/Desktop/Eman/ros_workspace/devel/lib//libGA_planner_lib.so. Make sure that you are calling the PLUGINLIB_EXPORT_CLASS macro in the library code, and that names are consistent between this macro and your XML. Error string: Could not load library (Poco exception = /home/evadro/Desktop/Eman/ros_workspace/devel/lib//libGA_planner_lib.so: undefined symbol: _ZN18GenericPathPlanner8findPathEP16OccupancyGridMapP4Path)
[move_base-12] process has died [pid 17199, exit code 1, cmd /opt/ros/kinetic/lib/move_base/move_base __name:=move_base __log:=/home/evadro/.ros/log/8a34ae68-cecd-11eb-b87b-9e3f7c65cb79/move_base-12.log].
log file: /home/evadro/.ros/log/8a34ae68-cecd-11eb-b87b-9e3f7c65cb79/move_base-12*.log

When I rewrite the implementation without Path.cpp, Path.h, Map.cpp, Map.h, GenericPathPlanner.cpp, GenericPathPlanner.h , OccupancyGridMap.cpp, OccupancyGridMap.h, every thing works fine and I can use my planner in ROS.

However, I need to implement another custom planner, but I have to use Path.cpp, Path.h, Map.cpp, Map.h, GenericPathPlanner.cpp, GenericPathPlanner.h , OccupancyGridMap.cpp, OccupancyGridMap.h because the implementation will be very complicated without them.

How can I solve this problem ( using multiple cpp files with the custom planner)?

Many thanks

UPDATE:

at the beginning of the source GA_global_planner.cpp

PLUGINLIB_EXPORT_CLASS(GA_planner::GAGlobalPlannerROS, nav_core::BaseGlobalPlanner)

at the beginning of GenericPathPlanner.cpp

PLUGINLIB_EXPORT_CLASS(GenericPathPlanner, nav_core::BaseGlobalPlanner)

at the beginning of OccupancyGridMap.cpp

PLUGINLIB_EXPORT_CLASS(OccupancyGridMap, nav_core::BaseGlobalPlanner)

at the beginning of Map.cpp

PLUGINLIB_EXPORT_CLASS(Map, nav_core::BaseGlobalPlanner)

at the beginning of Path.cpp

PLUGINLIB_EXPORT_CLASS(Path, nav_core::BaseGlobalPlanner)

** The launch file **

<launch>
    <arg name="use_rosbot" default="false"/>
    <arg name="use_gazebo" default="true"/>
    <param if="$(arg use_gazebo)" name="use_sim_time" value="true"/>
<!-- Bring the ROSbot model and show it in Gazebo and in Rviz  -->
    <include file="$(find rosbot_description)/launch/rosbot_rviz.launch"/>
<!-- Map server -->
    <arg name="map_file" default="$(find rosbot_navigation)/maps/willowgarage-refined.yaml"/>
    <node name="map_server" pkg="map_server" type="map_server" args="$(arg map_file)" />
<!--- tf -->
    <node unless="$(arg use_rosbot)" pkg="tf" type="static_transform_publisher" name="map_odom_tf" args="0 0 0 0 0 0 map odom 100" />  
    <node if="$(arg use_rosbot)" pkg="tf" type="static_transform_publisher" name="base_link_to_laser" args="0 0 0 3.14 0 0 base_link laser 100" />
&lt;node pkg=&quot;joint_state_publisher&quot; type=&quot;joint_state_publisher&quot; name=&quot;joint_state_publisher&quot;&gt;
&lt;param name=&quot;publish_frequency&quot; type=&quot;double&quot; value=&quot;30.0&quot; /&gt;
&lt;/node&gt;

<!--- Localization: Run AMCL --> <node pkg="amcl" type="amcl" name="amcl" output="screen"> <remap from="scan" to="/scan"/> <rosparam file="$(find rosbot_navigation)/config/amcl.yaml" command="load" />

&lt;/node&gt;

<!-- Move base --> <node pkg="move_base" type="move_base" name="move_base" output="screen"> <!-- <param name="base_global_planner" value="navfn/NavfnROS"/> --> <param name="base_global_planner" value="GA_planner/GAGlobalPlannerROS"/> <param name="base_local_planner" value="teb_local_planner/TebLocalPlannerROS" /> <param name="controller_frequency" value="30.0"/> <!-- default is 20.0 --> <rosparam file="$(find rosbot_navigation)/config/costmap_common_params.yaml" command="load" ns="global_costmap" /> <rosparam file="$(find rosbot_navigation)/config/costmap_common_params.yaml" command="load" ns="local_costmap" /> <rosparam file="$(find rosbot_navigation)/config/local_costmap_params.yaml" command="load" /> <rosparam file="$(find rosbot_navigation)/config/global_costmap_params.yaml" command="load" /> <rosparam file="$(find rosbot_navigation)/config/teb_local_planner_params.yaml" command="load" /> </node> </launch>

CMakeLists.txt

cmake_minimum_required(VERSION 2.8.3)
project(GA_planner)

find_package(catkin REQUIRED COMPONENTS nav_core roscpp rospy std_msgs )

catkin_package(

INCLUDE_DIRS include

LIBRARIES GA_planner

CATKIN_DEPENDS nav_core roscpp rospy std_msgs

DEPENDS system_lib

)

include_directories( include ${catkin_INCLUDE_DIRS} )

add_library(GA_planner_lib src/GA_global_planner.cpp)

package.xml

<?xml version="1.0"?>
<package format="2">
  <name>GA_planner</name>
  <version>0.0.0</version>
  <description>The GA_planner package</description>

<maintainer email="eman@todo.todo">eman</maintainer>

<license>TODO</license>

<buildtool_depend>catkin</buildtool_depend>

<build_depend>roscpp</build_depend> <build_depend>nav_core</build_depend> <build_depend>nav_msgs</build_depend> <build_depend>rospy</build_depend> <build_depend>std_msgs</build_depend> <build_depend>costmap_2d</build_depend> <build_depend>geometry_msgs</build_depend> <build_depend>pluginlib</build_depend> <build_depend>tf</build_depend>

<exec_depend>roscpp</exec_depend> <exec_depend>nav_core</exec_depend> <exec_depend>rospy</exec_depend> <exec_depend>std_msgs</exec_depend> <exec_depend>costmap_2d</exec_depend> <exec_depend>geometry_msgs</exec_depend> <exec_depend>pluginlib</exec_depend> <exec_depend>tf</exec_depend>

<!-- The export tag contains other, unspecified, tags --> <export> <!-- Other tools can request additional information be placed here --> <nav_core plugin="${prefix}/GA_planner_plugin.xml"/> </export> </package>

GA_planner_plugin.xml

 <library path="lib/libmetabolic_pathways_planner_lib">
  <class name="GA_planner/GAGlobalPlannerROS" 
    type="GA_planner::GAGlobalPlannerROS" 
    base_class_type="nav_core::BaseGlobalPlanner">
  <class type="GenericPathPlanner">
  <class type="OccupancyGridMap">
  <class type="Map">
  <class type="Path">
    <description>This is GA global planner plugin.</description>
  </class>
</library>

Originally posted by Eman.m on ROS Answers with karma: 65 on 2021-06-16

Post score: 1


Original comments

Comment by skpro19 on 2021-06-16:
Did you add PLUGINLIB_EXPORT_CLASS to your source code?

Comment by skpro19 on 2021-06-16:
Did you update your CMakeLists.txt with add_library(global_planner_lib src/path_planner/global_planner/global_planner.cpp) ?

Comment by skpro19 on 2021-06-16:
Did you create the global_planner_plugin.xml file in your package?

Comment by skpro19 on 2021-06-16:
Did you update your package.xml file?

Comment by skpro19 on 2021-06-16:
Please upate the post with the launch file you are using.

Comment by Eman.m on 2021-06-16:
Thank you. I have edited my question above and added more details

Comment by tryan on 2021-06-17:
What happens when you try to query the package system (rospack plugins --attrib=plugin nav_core)?

Comment by Eman.m on 2021-06-18:
I added PLUGINLIB_EXPORT_CLASS at the beginning of each class composes the library, as I edit above.

Also I edit the plugin.xml and add all cpp files composes the library (edit above).

After .lanuch, i got different error:

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

this the output of rospack:

clear_costmap_recovery /opt/ros/kinetic/share/clear_costmap_recovery/ccr_plugin.xml
teb_local_planner /opt/ros/kinetic/share/teb_local_planner/teb_local_planner_plugin.xml
navfn /opt/ros/kinetic/share/navfn/bgp_plugin.xml
rotate_recovery /opt/ros/kinetic/share/rotate_recovery/rotate_plugin.xml
base_local_planner /opt/ros/kinetic/share/base_local_planner/blp_plugin.xml

Comment by skpro19 on 2021-06-18:
Are you able to build your package? If yes, did you run source ~/catkin_ws/devel/setup.bash after the build step.

1 Answers1

0

Rosanswers logo

I have solve it:

  1. no need for PLUGINLIB_EXPORT_CLASS in each .cpp, add it only in the planner's .cpp

  2. in cMakeLists.txt

    add_library(GA_planner_lib src/GA_global_planner_ros.cpp src/GenericPathPlanner.cpp src/Map.cpp src/OccupancyGridMap.cpp src/Path.cpp)

That is, add all .cpp needed by your planner


Originally posted by Eman.m with karma: 65 on 2021-06-18

This answer was ACCEPTED on the original site

Post score: 1