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

custom global planner with multiple cpp and h files

asked 2021-06-16 13:44:15 -0600

Eman.m gravatar image

updated 2021-06-18 12:12:11 -0600

Hi

I have created a custom planner following this tutorial:

http://wiki.ros.org/navigation/Tutori...

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" /> ...
(more)
edit retag flag offensive close merge delete

Comments

Did you add PLUGINLIB_EXPORT_CLASS to your source code?

skpro19 gravatar image skpro19  ( 2021-06-16 14:25:58 -0600 )edit

Did you update your CMakeLists.txt with add_library(global_planner_lib src/path_planner/global_planner/global_planner.cpp) ?

skpro19 gravatar image skpro19  ( 2021-06-16 14:26:53 -0600 )edit

Did you create the global_planner_plugin.xml file in your package?

skpro19 gravatar image skpro19  ( 2021-06-16 14:27:52 -0600 )edit

Did you update your package.xml file?

skpro19 gravatar image skpro19  ( 2021-06-16 14:28:33 -0600 )edit

Please upate the post with the launch file you are using.

skpro19 gravatar image skpro19  ( 2021-06-16 14:29:10 -0600 )edit

Thank you. I have edited my question above and added more details

Eman.m gravatar image Eman.m  ( 2021-06-16 18:20:55 -0600 )edit
1

What happens when you try to query the package system (rospack plugins --attrib=plugin nav_core)?

tryan gravatar image tryan  ( 2021-06-17 09:59:46 -0600 )edit

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
Eman.m gravatar image Eman.m  ( 2021-06-18 12:17:58 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-06-18 18:09:21 -0600

Eman.m gravatar image

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

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2021-06-16 13:44:15 -0600

Seen: 180 times

Last updated: Jun 18 '21