Ask Your Question
2

Set build order in catkin: generate custom messages before generating ros_lib

asked 2017-09-15 12:23:32 -0500

updated 2017-09-15 13:54:47 -0500

Quesiton: When using catkin to build a project, how do you set one package to finish compiling before another executes?


Background: I am making a robot with custom messages/services on an Arduino using catkin. The project layout is rather similar to the Clearpath Robotics Husky where the project is separated into packages: msgs, hardware, description, ... etc. Everything works and the Arduino even compiles and uploads though catkin_make commands as outlined by this rosserial_arduino tutorial. The current project layout is as follows:

  • catkin_ws/
    • src/
      • robot_msgs: description of custom ros messages/services (Status.msg & Command.srv)
      • robot_hardware: source code for Arduino (runs rosserial_client & rosserial_arduino)
      • robot_description: robot description files (urdf/xacro)
      • robot_viz: opens RVIZ with robot model

Problem: When building from a fresh install (no build/devel folders in the main catkin workspace), the issue arises when executing catkin_make for the first time. It seems that the robot_hardware package builds and compiles a new ros_lib before robot_msgs can add Status.msg or Command.srv to the project directory (robot_msgs folder is absent in the final ros_lib folder). However, if robot_hardware is temporarily removed while catkin_make is run, then afterwards replaced and catkin_make is run again, everything compiles and robot_msgs now exists in ros_lib. Is there anyway to add a dependency to the CMakeLists.txt file in robot_hardware to force it to go last so that the project compiles using catkin_make without tinkering with the project folders in a such a way?


Supplementary:

robot_hardware/CMakeLists.txt

cmake_minimum_required(VERSION 2.8.3)
project(robot_hardware)

find_package(catkin REQUIRED COMPONENTS
  rosserial_arduino
  rosserial_client
  robot_msgs
)

catkin_package()

rosserial_generate_ros_lib(
  PACKAGE rosserial_arduino
  SCRIPT make_libraries.py
)

# Added as a suggestion from @jayess (Sept 15 '17)
add_dependencies(robot_hardware_ros_lib 
    robot_msgs_generate_messages
    robot_msgs_generate_messages_cpp
    robot_msgs_generate_messages_eus
    robot_msgs_generate_messages_lisp
    robot_msgs_generate_messages_nodejs
    robot_msgs_generate_messages_py
)

rosserial_configure_client(
  DIRECTORY firmware
  TOOLCHAIN_FILE ${ROSSERIAL_ARDUINO_TOOLCHAIN}
)

rosserial_add_client_target(firmware robot_base ALL)
rosserial_add_client_target(firmware robot_base-upload)

robot_msgs/CMakeLists.txt

cmake_minimum_required(VERSION 2.8.3)
project(robot_msgs)

find_package(catkin REQUIRED COMPONENTS
  message_generation
  std_msgs
)

add_message_files(FILES
  Status.msg
)

add_service_files(FILES
  Command.srv
)

generate_messages(DEPENDENCIES
  std_msgs
)

catkin_package(CATKIN_DEPENDS std_msgs message_runtime)

runtime error on fresh build

...
[86%] Building CXX object CMakeFiles/robot_base.dir/robot_hardware.cpp.obj
/home/user/catkin_ws/src/robot_hardware/firmware/robot_hardware.cpp:52:34: fatal error: robot_msgs/Command.h: No such file or directory
#include <robot_msgs/Command.h>
                               ^
compilation terminated.
...
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2017-09-15 13:04:44 -0500

jayess gravatar image
edit flag offensive delete link more

Comments

Great find, slightly embarrassed that I didn't find that sooner. Unfortunately, the solution did not work. I found the targets and added them as dependencies to the robot_hardware/CMakeLists.txt. I deleted the build and devel folders to start fresh but the behaviour is still the same.

Any ideas?

djiglesias gravatar imagedjiglesias ( 2017-09-15 13:51:17 -0500 )edit

Try robot_msgs_gencpp instead of robot_msgs_generate_messages_cpp and others. Also, catkin_make_isolated will build one package at a time in dependency order.

kmhallen gravatar imagekmhallen ( 2017-09-16 10:01:55 -0500 )edit

@kmhallen

catkin_make_isolated compiles fine with the robot_msgs building to ros_lib as desired, but removes the ability to upload code to the Arduino via command line. Also, substituting robot_msgs_gencpp in place of the other dependencies had no effect on the build behaviour yet again.

djiglesias gravatar imagedjiglesias ( 2017-09-18 12:57:26 -0500 )edit
0

answered 2018-05-01 04:42:10 -0500

I found out a quick way to achieve this building on @djiglesias

If you have a situation like

  • my_pkg
  • my_pkg_msgs

you can make it work doing:

1) Remove my_pkg from the package to build

mv catkin_ws/src/my_pkg/package.xml catkin_ws/src/my_pkg/package.xml.tmp

Generated the messages (Note, the my_pkg_msgs package must be in the catkin workspace)

catkin_make

Bring back my_pkg

mv catkin_ws/src/my_pkg/package.xml.tmp catkin_ws/src/my_pkg/package.xml

Build everything

catkin_make

If the messages do not change, you can build as normal (catkin_make) in the next iteration. If you are changing the messages definition you need to do the same as before

It seems this problem is known ( https://github.com/ros-drivers/rosser... ), however no solution has been released yet.

The add_dependencies and generate_msgs did not work for me.

edit flag offensive delete link more

Comments

Or just run catkin_make --pkg my_pkg_msgs first

stridera gravatar imagestridera ( 2019-06-26 16:08:43 -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

2 followers

Stats

Asked: 2017-09-15 12:23:32 -0500

Seen: 1,338 times

Last updated: Sep 15 '17