ROS1 to ROS2 CMakeLists.txt Conversion Issues

asked 2021-06-30 16:13:27 -0600

buzzport93 gravatar image

Hello. I am working on Ubuntu 20.04 on Intel NUC device (amd64). Most of my projects were based on ROS1 until earlier this year. But to work with Nav2 package, I have decided to slowly start converting existing packages to ROS2 version.

Here is the look of the directories within the src folder:

  • unitree_legged_control
    • include
      • joint_controller.h
      • unitree_joint_control_tool.h
    • lib
      • libunitree_joint_control_tool.so
    • src
      • joint_controller.cpp
    • CMakeLists.txt
    • package.xml
    • unitree_controller_plugins.xml

My main issues with the package is converting the CMakeLists.txt file. I have taken a look at migration guide (https://docs.ros.org/en/foxy/Contribu...) to get the most of it done, but the issues still seem to persist.

First, the original CMakeLists.txt from ROS1:

cmake_minimum_required(VERSION 2.8.3)
project(unitree_legged_control)

find_package(catkin REQUIRED COMPONENTS
    controller_interface
    hardware_interface
    pluginlib
    roscpp
    realtime_tools
    unitree_legged_msgs
)

catkin_package(
    CATKIN_DEPENDS
        unitree_legged_msgs
        controller_interface
        hardware_interface
        pluginlib
        roscpp
        INCLUDE_DIRS include
        LIBRARIES ${PROJECT_NAME}
    )

include_directories(include ${catkin_INCLUDE_DIRS} ${Boost_INCLUDE_DIR})
link_directories($(catkin_LIB_DIRS) lib)

add_library( unitree_legged_control 
    src/joint_controller.cpp
)
add_dependencies(${PROJECT_NAME} unitree_legged_msgs_gencpp)
target_link_libraries(unitree_legged_control ${catkin_LIBRARIES} unitree_joint_control_tool)

And here is my attempted conversion of CMakeLists.txt:

cmake_minimum_required(VERSION 3.5)
project(unitree_legged_control)

# Default to C99
if(NOT CMAKE_C_STANDARD)
  set(CMAKE_C_STANDARD 99)

endif()

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(controller_interface REQUIRED)
find_package(hardware_interface REQUIRED)
find_package(pluginlib REQUIRED)
find_package(rclcpp REQUIRED)
find_package(realtime_tools REQUIRED)
find_package(unitree_legged_msgs REQUIRED)


include_directories(include ${Boost_INCLUDE_DIR})

target_include_directories(my_target
  PUBLIC
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
    $<INSTALL_INTERFACE:include>)

add_library(unitree_legged_control 
        src/joint_controller.cpp ) ament_target_dependencies(${PROJECT_NAME} unitree_legged_msgs_gencpp)
    target_link_libraries(unitree_legged_control
    unitree_joint_control_tool)


if(BUILD_TESTING)  
find_package(ament_lint_auto
REQUIRED)  
ament_lint_auto_find_test_dependencies()
endif()

ament_package()

Once I try to build, I get the following error:

CMake Error at /opt/ros/foxy/share/ament_cmake_target_dependencies/cmake/ament_target_dependencies.cmake:77 (message):
  ament_target_dependencies() the passed package name
  'unitree_legged_msgs_gencpp' was not found before
Call Stack (most recent call first):
  CMakeLists.txt:38 (ament_target_dependencies)
  1. Why is it returning the error for a package name that does not exist? Is this package supposed to come from the encrypted .so files in the lib folder? I am confused.

  2. Also, when and how is ament_package() supposed to be used to replace the catkin_package?

  3. How am I supposed to replace link_directories($(catkin_LIB_DIRS) lib) ?

  4. How am I supposed to replace add_library(~~~)?

Thank you for the support. Also, Please note that I have already checked out the CMakeLists & package.xml converter developed by amazonrobotics. I want to point out that the converter does not even build properly and is not my option.

edit retag flag offensive close merge delete

Comments

I haven't checked the rest, but unitree_legged_msgs_gencpp is clearly a ROS 1 target and doesn't exist in ROS 2 CMakeLists.txts.

gvdhoorn gravatar image gvdhoorn  ( 2021-07-01 02:40:27 -0600 )edit