0
$\begingroup$

Rosanswers logo

My file structure is as follows:

catkin_workspace/src/
                     package/
                             subpackage_1/src/subpackage_1.cpp
                             subpackage_2/src/subpackage_2.cpp
                             package (Metapackage)

I define a class in each of these .cpp files, and each one contains an instance of the same base class. Where should I save this base class to conform with the ROS C++ Style Guide? And what would I need to add to each subpackage_#'s CMakeLists.txt? Thanks.

EDIT: It's working. I didn't modify the structure of the packages at all. Here are the contents of catkin_workspace/src/package/subpackage_3/CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.3)
project(subpackage_3)
SET(CMAKE_BUILD_TYPE RELEASE)

find_package(catkin REQUIRED COMPONENTS
  roscpp)
find_package( PCL REQUIRED )

catkin_package(CATKIN_DEPENDS roscpp
           INCLUDE_DIRS include
           LIBRARIES subpackage_3
           )

include_directories(
  include 
  ${catkin_INCLUDE_DIRS}
  ${PCL_INCLUDE_DIRS}
)
set(PKG3_COM_LIB_SOURCES
    src/subpackage_3.cpp)
add_library (subpackage_3 ${PKG3_COM_LIB_SOURCES})

The only modification I needed to make to subpackage_<1, 2>/CMakeLists.txt was to add find_package(subpackage_3). I also added < depend>subpackage_3< /depend> to subpackage_<1, 2>/package.xml (without the spaces).


Originally posted by mc123 on ROS Answers with karma: 13 on 2016-05-26

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

ROS does not have a concept of "subpackage" like you seem to describe.

Perhaps the ROS equivalent would be to eliminate the src/package directory and promote each of its contained directories to that level:

 catkin_workspace/src/
                      subpackage_1/src/subpackage_1.cpp
                      subpackage_2/src/subpackage_2.cpp
                      package (Metapackage)

That gives you two ROS packages (subpackage_1 and subpackage_2) and a metapackage.

EDIT: If you like, the base class can go in its own ROS package at the same level. Then, subpackage_1 and subpackage_2 would both depend on that.

There is no way to know what CMakeLists.txt changes would be required without you editing the original question to add their current contents.

But, the ROS catkin documentation contains plenty of examples for how to do things like that:

Another alternative would be to collect everything into a single ROS package. Depending on the structure of your project that might be easier.


Originally posted by joq with karma: 25443 on 2016-05-26

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by mc123 on 2016-05-27:
Okay. If I do that, where should I include the common class, and how should I modify my CMakeList.txts to reflect the changes?

Comment by joq on 2016-06-01:
There is no way to answer that, because you have not told us what the CMakeLists.txt currently contains. Please edit your question to add that information.

Comment by joq on 2016-06-03:
That looks reasonable. Instead of find_package(subpackage_3) the recommended catkin usage is adding it to this: find_package(catkin REQUIRED COMPONENTS roscpp subpackage_3).

Comment by joq on 2016-06-03:
Also, it's a good idea to make subpackage_3 releasable, by adding the install steps: http://docs.ros.org/api/catkin/html/howto/format2/building_libraries.html#installing .

Comment by mc123 on 2016-06-03:
Awesome. Thanks, joq.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.