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

How to override /opt/ros/melodic/include/move_base/move_base.h?

asked 2021-05-05 06:24:51 -0600

updated 2021-05-05 07:33:29 -0600

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.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2021-05-05 08:29:27 -0600

miura gravatar image

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.

edit flag offensive delete link more

Comments

I didn't understand the last paragraph.

skpro19 gravatar image skpro19  ( 2021-05-05 20:15:26 -0600 )edit

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()'
skpro19 gravatar image skpro19  ( 2021-05-06 00:31:28 -0600 )edit

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.

miura gravatar image miura  ( 2021-05-06 08:54:04 -0600 )edit

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?

skpro19 gravatar image skpro19  ( 2021-05-06 08:59:03 -0600 )edit

Do you mean that you have an implementation as well?

My guess is that you also need to bring move_base.cppinto your package and update it. In the original move_base.cpp, the implementation of the deconstructor is here. ( https://github.com/ros-planning/navig... )

In addition, the CMakeLists.txt needs to be changed.

add_executable(main_node src/main.cpp src/move_base.cpp)
miura gravatar image miura  ( 2021-05-06 09:18:10 -0600 )edit

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.

skpro19 gravatar image skpro19  ( 2021-05-06 10:02:10 -0600 )edit

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
miura gravatar image miura  ( 2021-05-06 10:12:19 -0600 )edit

@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); )

skpro19 gravatar image skpro19  ( 2021-05-07 05:51:06 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2021-05-05 06:24:51 -0600

Seen: 220 times

Last updated: May 05 '21