Importing ROS package into existing CMake Project

asked 2021-02-04 09:32:31 -0500

theuema gravatar image

updated 2022-05-28 16:53:48 -0500

lucasw gravatar image

Hello, I was thrown right into an existing CMake project, that now needs to include ROS. I did some beginners guides and actually was able to make a Publisher/Subscriber service with a simple package.xml and a CMakeLists.txt using std_msgs. The rather easy file structure looked like this:

ROS/
    CMakeLists.txt
    package.xml
    setup_ros_environment.sh
    Publisher.cpp
    Subscriber.cpp
    msg/
        TestMessage.msg
    build/

Now i need to include Catkin into an existing CMake Project that looks something like this:

PROJECT/
     CMakeLists.txt
     Applications/
     CMakeModules/
     Configurations/
     Libraries/
              CMakeLists.txt
              DataForwarderSomething/
              SensorSomethingDevice/
              TriggerDevice/
              ROSPackageNedded/
                       CMakeLists.txt
                       package.xml
                       someCppThatUsesROS.cpp
                       header.hpp

I now tried to change the CMakeLists.txt in ROSPackageNeeded/ to invoke catkin_package(), find_package(), add_message_files() and include_directories(${catkin_INCLUDE_DIRS}), like I did with the previous example.

So the 'Toplevel' CMake file is not provided by Catkin, obviously.

2 things happened:

  • catkin_pkg was not found, since with using this CMakeLists.txt Toplevel file Pyhton3.6 instead of Python2.7 is found. I temporarly resolved this one with: pip3 install catkin_pkg I have no idea if this is sufficient for our needs.

Is there a way to force Catkin to use Python2? Somehow declare it in the CMakeLists.txt in ROSPackageNeeded/ ?

  • package.xml is now being searched Toplevel! I was not able to resolve this one yet, but since it is possible to use various ROS_Packages in a ROS_Workingspace with several different package.xml files, I thought it has to be possible in an existing CMake project as well...

Is it possible to tell Catkin to use the package.xml provided in ROSPackageNedded/ ?

Generally: What is the intended way to import ROS packages to an existing CMake Project? I am pretty unsure about how to include ROS to an exisiting CMake Project.

I am working on:

  • Linux aarch64 aarch64 aarch64 GNU/Linux
  • Distributor ID: Ubuntu
  • Description: Ubuntu 18.04.5 LTS
  • Release: 18.04
  • Codename: bionic
  • Catkin: Melodic

Thanks in advance for any help :)

-- Using CATKIN_TEST_RESULTS_DIR: /usr/build/MITA_test/test_results
-- Found gtest sources under '/usr/src/googletest': gtests will be built
-- Found gmock sources under '/usr/src/googletest': gmock will be built
-- Found PythonInterp: /usr/bin/python3 (found version "3.6.9")
-- Using Python nosetests: /usr/bin/nosetests
-- catkin 0.7.29
-- BUILD_SHARED_LIBS is on
-- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy
-- RosGpsImu: 2 messages, 0 services
CMake Error: File /usr/src/PROJECT/package.xml does not exist.
CMake Error at /opt/ros/melodic/share/catkin/cmake/stamp.cmake:10 (configure_file):
configure_file Problem configuring file
Call Stack (most recent call first):
/opt/ros/melodic/share/catkin/cmake/catkin_package_xml.cmake:72 (stamp)
/opt/ros/melodic/share/catkin/cmake/catkin_package_xml.cmake:50 (_catkin_package_xml)
/opt/ros/melodic/share/catkin/cmake/catkin_package.cmake:99 (catkin_package_xml)
Libraries/ROSPackageNedded/CMakeLists.txt:39 (catkin_package)
edit retag flag offensive close merge delete