Ask Your Question
0

Using the same data structure in multiple nodes

asked 2015-11-16 03:57:13 -0500

anoman gravatar image

updated 2015-11-16 03:58:17 -0500

I am designing a system which consists of multiple nodes. Among others there is a "gui" node for visualization and a "controls" node for controlling the whole application. During runtime I need to keep and update the information about a so called camera_unit for which I created a class CameraUnit (.h + .cpp files). The thing is I need to use this class both in "gui" and "controls" node, as the gui uses the info for visualization and the controls for other computations, but I do not want to duplicate the code. What are my options? I have thought of these:

1. Duplicate the code (Probably the worst option as I would have to always copy .h and .cpp file between nodes when editing them)

2. Make the static library out of the CameraUnit class which would be linked to both "controls" and "gui" node (That seems possible but I still feel there is a more elegant option)

3. Merge "gui" and "controls" nodes to one node and make the gui run in a separate thread (I would like to prevent this option as it would change my architecture)

Thank you for any advice!

edit retag flag offensive close merge delete

Comments

Why don't you just include your CameraUnit.h in both nodes? #include <your_package cameraunit.h="">

Mehdi. gravatar image Mehdi.  ( 2015-11-16 04:13:52 -0500 )edit

That would work but it would mean referencing the code from the different package and I thought this would not be really clean either. Or do you consider such an approach alright?

anoman gravatar image anoman  ( 2015-11-16 13:19:34 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-11-16 04:27:22 -0500

dornhege gravatar image

Use a variant of number 2. Make the CameraUnit a class in a shared library. Basically with catkin, don't think about it and just use add_library. This change should just be 2-3 lines in your cmake file and it should work.

edit flag offensive delete link more

Comments

It works, I just had to make a few more adjustments. You have to add lines

INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src LIBRARIES name_of_your_lib

in catkin_packege() in the node which builds the library to make it work. Is there any specific reason why to use SHARED and not STATIC library?

anoman gravatar image anoman  ( 2015-11-16 05:22:31 -0500 )edit

static libraries would be linked into every dependent package. It probably doesn't matter for smaller projects. But you don't need to worry about it. catkin should do everything correctly here.

dornhege gravatar image dornhege  ( 2015-11-16 07:19:59 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-11-16 03:57:13 -0500

Seen: 114 times

Last updated: Nov 16 '15