Import a custom message outside of a catkin workspace (c++)

asked 2021-01-27 21:06:24 -0600

sava-f gravatar image

Hi folks, I am trying to import a custom action file in my c++ application but with no success.

My application currently uses ROS but it is not build in a catkin_ws. What I need to do is to define action file and import that in my application. Ideally I would like to import my actionFile in two different programs, separately built, acting as client and server.

It is clear to me how to build in catkin my action file but I am really struggling on importing it in my application.

There is someone here who could suggest me any solution or point me any tutorial?

PS. I am working with ROS melodic over ubuntu 18. Thanks a lot to all.

sava-f

edit retag flag offensive close merge delete

Comments

Maybe you could explain your setup a bit more, as well as the rationale for why you want to include an action outside of a ROS workspace?

note that the action definitions get "compiled" during a catkin build into header files that you can then include (rather, there is code auto-generated from the action/msg/srv definitions during the catkin build step). That being said, there is no way to directly include the action definition (I guess that i what you mean by "action file") in your program. You need to include the generated header...

mgruhler gravatar image mgruhler  ( 2021-01-29 01:20:36 -0600 )edit

Hi thanks for your reply. The setting is the following: I have a legacy application written in C++. It is not compiled using catkin. It uses ROS for some communication. Now I need to implement a communication between this application and other modules (implemented in C++ and Python). These modules and the legacy application will communicate using actionLib. So my idea would be to implement the action messages and include them in both: the modules and my legacy application (eventually as a submodule). Do you think it is a good way to proceed?

I tried to include the generated headers (I put them in the include folder). Do I need to modify my cmake as well?

sava-f gravatar image sava-f  ( 2021-01-30 06:43:05 -0600 )edit

How is your legacy application compiled, then, if it uses ROS but not catkin? Is this still rosbuild? Or plain CMake? Please be very specific, best, either with a link to the repo or a stripped down version of the build files...

mgruhler gravatar image mgruhler  ( 2021-02-01 08:00:15 -0600 )edit

I am sorry but cannot share my application for copyright reason. By the way it is plain CMake. The CMake itself it is a bit messy at the moment since I am moving to a modern CMake implementation. The point in which I import ROS appears like this:

set(ROS_LIBRARIES /opt/ros/melodic/lib)

find_package(catkin REQUIRED COMPONENTS roscpp geometry_msgs std_msgs sensor_msgs )

Up to know I only use ros to publish some ros messages like string or joint_msgs.

Does it make sense to you or you need more information?

sava-f gravatar image sava-f  ( 2021-02-02 21:24:32 -0600 )edit

Well, custom action defintions etc are compiled into the devel space of your workspace. So you would need to point your CMake file to that space as well, to pick up any libraries and include directories (I assume you also have an appropriate include_directories entry) therein.

You can actually also use catkin_make_install -DCMAKE_INSTALL_PREFIX=<PATH> to put the output of your packages to a proper location, like e.g. /opt/ros/custom or something (you need to set the appropriate permissions for that directory, by default, it puts it into your workspace under install). I also highly recommend to not mix it with the default ROS location...

mgruhler gravatar image mgruhler  ( 2021-02-04 01:59:55 -0600 )edit