0
$\begingroup$

Rosanswers logo

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.
...

Originally posted by djiglesias on ROS Answers with karma: 31 on 2017-09-15

Post score: 3

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Try this solution https://answers.ros.org/question/200995/rosserial_arduino-generate-dependent-packages-before-make_libraries/?answer=209434#post-id-209434.

I found it by Googling "rosserial_generate_ros_lib site:answers.ros.org"


Originally posted by jayess with karma: 6155 on 2017-09-15

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by djiglesias on 2017-09-15:
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?

Comment by kmhallen on 2017-09-16:
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.

Comment by djiglesias on 2017-09-18:
@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.

$\endgroup$

Your Answer

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