How to override /opt/ros/melodic/include/move_base/move_base.h?
I cloned the move_base
package to my catkin
workspace and built it using catkin_build
. I made some changes to the move_base
class constructor.
I changed it from MoveBase(tf2_ros::Buffer& tf);
to
MoveBase(tf2_ros::Buffer& tf, costmap_2d::Costmap2DROS* &planner_costmap_ros_, costmap_2d::Costmap2DROS* &controller_costmap_ros_ );
I am using this modified move_base
class in my package (named my_explore_lite
). I am getting the following error when I try to build the package using catkin build my_explore_lite
-
Errors << my_explore_lite:make /home/skpro19/catkin_ws/logs/my_explore_lite/build.make.007.log
/home/skpro19/catkin_ws/src/my_explore_lite/src/main.cpp: In function ‘int main(int, char**)’:
/home/skpro19/catkin_ws/src/my_explore_lite/src/main.cpp:476:75: error: no matching function for call to ‘move_base::MoveBase::MoveBase(tf2_ros::Buffer&, costmap_2d::Costmap2DROS*&, costmap_2d::Costmap2DROS*&)’
move_base::MoveBase my_move_base(buffer, global_costmap, local_costmap);
^
In file included from /home/skpro19/catkin_ws/src/my_explore_lite/src/main.cpp:15:0:
/opt/ros/melodic/include/move_base/move_base.h:90:7: note: candidate: move_base::MoveBase::MoveBase(tf2_ros::Buffer&)
MoveBase(tf2_ros::Buffer& tf);
^~~~~~~~
/opt/ros/melodic/include/move_base/move_base.h:90:7: note: candidate expects 1 argument, 3 provided
make[2]: *** [CMakeFiles/main_node.dir/src/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/main_node.dir/all] Error 2
make: *** [all] Error 2
It seems that the error is arising because the header file at the location /opt/ros/melodic/move_base/move_base.h
is being used. How do I override this header file with the one that is inside my catkin workspace's move_base
package?
This is my CMakelist.txt file.
Asked by skpro19 on 2021-05-05 06:24:51 UTC
Answers
When referring to the include_directories, the include of the my_explore_lite package seems to have the highest priority.
If you put the modified header file in my_explore_lite/include/move_base.h and include it with #include "move_base.h"
, the modified header file will be loaded first.
The only thing you have to worry about is whether you are including move_base/move_base.h
or another package is including move_base/move_base.h
. I think it's safer to rename move_base.h
, although it's more work.
Asked by miura on 2021-05-05 08:29:27 UTC
Comments
I didn't understand the last paragraph.
Asked by skpro19 on 2021-05-05 20:15:26 UTC
If you put the modified header file in my_explore_lite/include/move_base.h and include it with #include "move_base.h", the modified header file will be loaded first.
This gives the following errors -
CMakeFiles/main_node.dir/src/main.cpp.o: In function `main':
main.cpp:(.text+0x294f): undefined reference to `move_base::MoveBase::MoveBase(tf2_ros::Buffer&, costmap_2d::Costmap2DROS*&, costmap_2d::Costmap2DROS*&)'
main.cpp:(.text+0x296d): undefined reference to `move_base::MoveBase::~MoveBase()'
main.cpp:(.text+0x2b8a): undefined reference to `move_base::MoveBase::~MoveBase()'
Asked by skpro19 on 2021-05-06 00:31:28 UTC
This indicates that my_explore_lite / include / move_base.h has been successfully included. Either the constructor and deconstructor have not been created, or the linkage has failed to be set.
Asked by miura on 2021-05-06 08:54:04 UTC
move_base.h
file in the move_base
package (the one inside my catkin
workspace) has constructors and destructors defined.
How can I check for the linkage issue?
Asked by skpro19 on 2021-05-06 08:59:03 UTC
Do you mean that you have an implementation as well?
My guess is that you also need to bring move_base.cpp
into your package and update it. In the original move_base.cpp, the implementation of the deconstructor is here. ( https://github.com/ros-planning/navigation/blob/noetic-devel/move_base/src/move_base.cpp#L447 )
In addition, the CMakeLists.txt needs to be changed.
add_executable(main_node src/main.cpp src/move_base.cpp)
Asked by miura on 2021-05-06 09:18:10 UTC
I am currently working on a package named my_explore_lite
. This package is present at ~/catkin_ws/src/my_explore_lite
. I also have move_base
package inside my catkin_ws
at ~/catkin_ws/src/navigation/move_base
.
I have a cpp
file named main.cpp
inside the src
folder of my_explore_lite
package (~/catkin_ws/src/my_explore_lite/src/main.cpp
).
I have the following line of code inisde the main.cpp
file -
move_base::MoveBase my_move_base(buffer, global_costmap, local_costmap);
As mentioned in the original post, I have modified the original constructor for the MoveBase
class.
Asked by skpro19 on 2021-05-06 10:02:10 UTC
MoveBase(tf2_ros::Buffer& tf, costmap_2d::Costmap2DROS* &planner_costmap_ros_, costmap_2d::Costmap2DROS* &controller_costmap_ros_ );
is not the only part that actually works.
Please try adding the following to main.cpp. I think it will solve the link issue for now. (But it does not work.).
namespace move_base {
MoveBase::MoveBase(tf2_ros::Buffer& tf, costmap_2d::Costmap2DROS* &planner_costmap_ros_, costmap_2d::Costmap2DROS* &controller_costmap_ros_ )
{
}
MoveBase::~MoveBase()
{
}
} // namespace
Asked by miura on 2021-05-06 10:12:19 UTC
@miura Even when I am using the original move_base
constructor, I am getting the following erorr -
Errors << my_explore_lite:make /home/skpro19/catkin_ws/logs/my_explore_lite/build.make.052.log
CMakeFiles/main_node.dir/src/main.cpp.o: In function `main':
main.cpp:(.text+0x28b1): undefined reference to `move_base::MoveBase::MoveBase(tf2_ros::Buffer&)'
main.cpp:(.text+0x28c0): undefined reference to `move_base::MoveBase::~MoveBase()'
collect2: error: ld returned 1 exit status
make[2]: *** [/home/skpro19/catkin_ws/devel/.private/my_explore_lite/lib/my_explore_lite/main_node] Error 1
make[1]: *** [CMakeFiles/main_node.dir/all] Error 2
make: *** [all] Error 2
(I have removed the modified move_base.h
file from my_explore_lite
package's include
folder. In the main.cpp
, I am using move_base::MoveBase my_move_base(buffer);
)
Asked by skpro19 on 2021-05-07 05:51:06 UTC
Also, what do you mean by linking error? What could be the possible causes?
Asked by skpro19 on 2021-05-07 05:52:22 UTC
There is an error because move_base
is not a link target.
It should be resolved by adding move_base
to find_package
and catking_package
, since target_link_libraries(main_node ${catkin_LIBRARIES})
and catkin_LIBRARIES are targeted for linking.
find_package(catkin REQUIRED COMPONENTS
geometry_msgs
...
move_base # added
)
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES my_explore_lite
CATKIN_DEPENDS nav_msgs roscpp std_msgs message_runtime move_base # added
# DEPENDS system_lib
)
As for the linking error, it is not a ROS topic, so please look it up by other means.
Asked by miura on 2021-05-07 09:13:01 UTC
I did try making that change. I am still getting the same error.
Asked by skpro19 on 2021-05-08 03:12:23 UTC
I thought it would be sufficient to use
target_link_libraries(main_node ${catkin_LIBRARIES})
It may be necessary to use
target_link_libraries(main_node ${catkin_LIBRARIES} move_base)
Asked by miura on 2021-05-08 04:01:49 UTC
Comments