koide3 / glim_ext

18 stars 6 forks source link

Working with ROS2 #9

Open changh95 opened 1 month ago

changh95 commented 1 month ago

Hi again!

I'm trying to use some of the extension modules, but I am struggling to integrate it on ROS2 glim_rosbag.

Following the installation procedures on the documentation, I cloned this repo in the ros2_ws/src and did colcon build. The ament build shows that glim_ext has successfully been built.

When I run glim_rosbag, it seems like ROS2 cannot find glim_ext.

The logs are as follows. Before running it, I modified the config_ros.json file and added imu_validator and gnss_global libraries. But these are not found too.

[2024-08-05 08:23:10.711] [glim] [info] config_path: /root/ros2_ws/install/glim/share/glim/config
[2024-08-05 08:23:10.712] [glim] [info] load libodometry_estimation_gpu.so
[2024-08-05 08:23:10.776] [glim] [info] load libsub_mapping.so
[2024-08-05 08:23:10.776] [glim] [info] load libglobal_mapping.so
[2024-08-05 08:23:10.778] [glim] [warning] Extension modules are enabled!!
[2024-08-05 08:23:10.778] [glim] [warning] You must carefully check and follow the licenses of ext modules
[2024-08-05 08:23:10.778] [glim] [warning] glim_ext package path was not found!!
[2024-08-05 08:23:10.778] [glim] [info] load libmemory_monitor.so
[2024-08-05 08:23:10.778] [glim] [info] load libstandard_viewer.so
[2024-08-05 08:23:10.782] [glim] [info] load librviz_viewer.so
[2024-08-05 08:23:10.788] [glim] [info] load libimu_validator.so
[2024-08-05 08:23:10.788] [glim] [warning] failed to open libimu_validator.so
[2024-08-05 08:23:10.788] [glim] [warning] libimu_validator.so: cannot open shared object file: No such file or directory
[2024-08-05 08:23:10.788] [glim] [error] failed to load libimu_validator.so
[2024-08-05 08:23:10.788] [glim] [info] load libgnss_global.so
[2024-08-05 08:23:10.788] [glim] [warning] failed to open libgnss_global.so
[2024-08-05 08:23:10.788] [glim] [warning] libgnss_global.so: cannot open shared object file: No such file or directory
[2024-08-05 08:23:10.788] [glim] [error] failed to load libgnss_global.so
sgvandijk commented 1 month ago

I am running into the same issue. The problem seems to be that the glim_ext module libraries are installed to ros2_ws/install/glim_ext/ directly, however when sourceing the workspace, LD_LIBRARY_PATH will have ros2_ws/install/glim_ext/lib/ instead. The lib directory is the standard for libraries as part of ROS 2 packages.

To get them installed in the right place, I have removed the following line from glib_ext/CMakeLists.txt:

install(TARGETS ${glim_ext_LIBRARIES})

and instead added the install instruction in the section that checks for ROS 2 further below, as such:

if(DEFINED ENV{ROS_VERSION})
  if($ENV{ROS_VERSION} EQUAL 2)
    # ROS2
    install(DIRECTORY config DESTINATION share/glim_ext)

    ament_target_dependencies(glim_ext glim)
    ament_export_libraries(${glim_ext_LIBRARIES})

    # Ensure everything is installed in the correct place as expected by ROS 2
    install(TARGETS ${glim_ext_LIBRARIES}
      LIBRARY DESTINATION lib
      ARCHIVE DESTINATION lib
      RUNTIME DESTINATION bin
    )

    ament_package()
  elseif($ENV{ROS_VERSION} EQUAL 1)
    # ROS1
    find_package(catkin REQUIRED)
    catkin_package(
      LIBRARIES ${glim_ext_LIBRARIES}
    )
  endif()
endif()

See also the cmake_ament documentation: https://docs.ros.org/en/humble/How-To-Guides/Ament-CMake-Documentation.html#installing

To still make it work for ROS 1 and non-ROS builds, the old install statement needs to be added in the appropriate else/elseif blocks.

If this seems like the proper solution then I am happy to create a quick PR.

changh95 commented 1 month ago

@sgvandijk Thank you for sharing your solution! Unfortunately I could not get it to work.

In my case, ROS2 just cannot seem to find glim_ext package, so consequent reading configs for glim_ext just tends to skip completely. (Line 131 in glim_ros.cpp)

So I just replace the code to use absolute path. This way, reading config path works.

const std::string config_ext_path = "/root/ros2_ws/install/glim_ext/share/glim_ext/config";
//const std::string config_ext_path = ament_index_cpp::get_package_share_directory("glim_ext") + "/config";

Then I specified which extension modules to use in glim/config/config_ros.json. I added libimu_validator.so and libgnss_global.so in the extension_modules section, but these libraries cannot be found.

image

These libraries are built in ros2_ws/install/glim_ext/lib, but reading extension module libraries are done in ros2_ws/install/glim/lib. So I manually copied the libraries from glim_ext/lib to glim/lib. There was another message that glim_ext.so is also required but missing, so I copied that library as well. But then glim_ext.so must NOT be added in the list for config_ros.json, because it does not have the appropriate load function. Then finally, the extension modules could be loaded.

image

koide3 commented 1 month ago

@sgvandijk Thanks for the information. I would be happy if you could open a PR to fix it.

@changh95 Sorry for letting you get confused. I think I should add some tutorial about the setting of config files for extension modules (e.g., glim_ext.so should not be added to config_ros.json). The issue on finding library may be resolved by fixing the installation path as @sgvandijk said.

Side note: This FAQ might be helpful to resolve shared library-related issues: https://github.com/koide3/glim/wiki/FAQ#failed-to-load-modulename-module-or-modulenameso

koide3 commented 1 month ago

I fixed the installation path with https://github.com/koide3/glim_ext/pull/13 .