ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How to use message from another package

asked 2018-10-13 21:23:30 -0600

renanmb gravatar image

updated 2022-01-22 16:16:23 -0600

Evgeny gravatar image

So I am trying to use a custom msg (Drive.msg) that I created in the boat_controller project inside the same workspace. This message is necessary for connecting boat_hw with boat_controller.

Github: in the same workspace I have the following projects:

boat_hw : https://github.com/renanmb/boat_hw

boat_controller : https://github.com/renanmb/boat_pid_c...

VESC : https://github.com/renanmb/VESC

So how do I do it on the CMakefile.txt , It really got me confused. Message is in boat_controller and I wanna build it in boat_hw.

This is the error shown by the Terminal:

[ 96%] Building CXX object boat_hw/CMakeFiles/robot.dir/src/boat_hw.cpp.o
[ 96%] Building CXX object boat_hw/CMakeFiles/robot.dir/src/robot.cpp.o
In file included from /home/renan/rostest_ws/src/boat_hw/src/boat_hw.cpp:1:0:
/home/renan/rostest_ws/src/boat_hw/src/boat_hw.h:5:37: fatal error: boat_controller/Drive.msg: No such file or directory
compilation terminated.
boat_hw/CMakeFiles/robot.dir/build.make:86: recipe for target 'boat_hw/CMakeFiles/robot.dir/src/boat_hw.cpp.o' failed
make[2]: *** [boat_hw/CMakeFiles/robot.dir/src/boat_hw.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
In file included from /home/renan/rostest_ws/src/boat_hw/src/robot.cpp:1:0:
/home/renan/rostest_ws/src/boat_hw/src/boat_hw.h:5:37: fatal error: boat_controller/Drive.msg: No such file or directory
compilation terminated.
boat_hw/CMakeFiles/robot.dir/build.make:62: recipe for target 'boat_hw/CMakeFiles/robot.dir/src/robot.cpp.o' failed
make[2]: *** [boat_hw/CMakeFiles/robot.dir/src/robot.cpp.o] Error 1
CMakeFiles/Makefile2:4519: recipe for target 'boat_hw/CMakeFiles/robot.dir/all' failed
make[1]: *** [boat_hw/CMakeFiles/robot.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j6 -l6" failed

This is my CMakelist.txt

cmake_minimum_required(VERSION 2.8.3)
project(boat_hw)


find_package(catkin REQUIRED COMPONENTS vesc_driver vesc_msgs controller_manager)

## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
  CATKIN_DEPENDS vesc_driver vesc_msgs boat_controller

)

include_directories(
  include
  ${Boost_INCLUDE_DIRS}
  ${catkin_INCLUDE_DIRS}
)


add_executable(robot
                        src/robot.cpp
                        src/boat_hw.cpp
                        src/boat_driver.cpp
              )

add_dependencies(robot ${catkin_EXPORTED_TARGETS})
target_link_libraries(robot
  ${catkin_LIBRARIES}
  vesc_driver_nodelet
  ${boat_controller}
#  add_library(${PROJECT_NAME}
  src/${boat_controller}/Drive.msg
  #controller_manager
)
edit retag flag offensive close merge delete

Comments

Please remove all the comments from your CMakeLists.txt. They are not needed and make your post unnecessarily long.

gvdhoorn gravatar image gvdhoorn  ( 2018-10-14 01:38:24 -0600 )edit

I've changed the title of your question, as you are explicitly asking how to use messages from other packages and make compilation work.

gvdhoorn gravatar image gvdhoorn  ( 2018-10-14 01:48:15 -0600 )edit

and I am pretty confused, I know I could just create a message folder. I want to use messages from other packages without the need of creating the folder again. I saw in some other projects people creating a package just with messages.

renanmb gravatar image renanmb  ( 2018-10-14 05:44:01 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-10-14 01:43:47 -0600

gvdhoorn gravatar image

There are quite a few questions about this, so can you please try the following search in Google and see whether the results help you: custom message in other package site:answers.ros.org?

In summary: messages are headers, not libraries. So you can't link them.

See the Catkin documentation, specifically the C++ message or service dependencies section for how to configure everything correctly.

edit flag offensive delete link more

Comments

so do I have to create a new mg folder in every single package every time I want to use a new custom message?

I thought there would be a way around it.

renanmb gravatar image renanmb  ( 2018-10-14 05:32:40 -0600 )edit

No, that is not needed.

You create your msgs (and srvs and actions) in one package and then express a dependency on the pkg providing those msgs/srvs/actions.

You just have to make sure to add the correct statements to your CMakeLists.txt. Refer to the Catkin docs I linked.

gvdhoorn gravatar image gvdhoorn  ( 2018-10-14 05:39:48 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-10-13 21:23:30 -0600

Seen: 3,772 times

Last updated: Oct 14 '18