1
$\begingroup$

I am developing a package for the ROS, in fact, it is a package of resources/models for the Gazebo, and I need with the presence of this package in the Workspace of Catkin to automatically set the variable GAZEBO_MODEL_PATH for this package.

I could intervene in the file ~/catkin_mygazebo_ws/devel/setup.sh, adding the path to a variable, but first I would like to know if there is any way to do it by another more specialized route to Catkin.

$\endgroup$
  • $\begingroup$ Adding a 'thanks' section to a question is not required, we all tend to be thankful for the people helping us, and expect other people to be thankful too, so saying it just adds noise to the question and distracts people from the problem posed. It may seem counter intuitive, but excessive politeness can itself be impolite, as giving people extra text to read, even if they ignore it, is disrespectful of their time. $\endgroup$ – Mark Booth Sep 13 '19 at 10:50
2
$\begingroup$

I wanted to do a similar thing to point to a custom Python logging ROS configuration file.

From the way I read the documentation you only need to create a .sh script and it should be run by all of the fancier shell environments (e.g. bash with setup.bash).

So I added the following line to CMakeLists.txt for my package:

catkin_add_env_hooks(logging_env SHELLS sh DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/env-hooks)

In the folder env-hooks in my package I added the following file called logging_env.sh:

#!/usr/bin/env sh

export ROS_PYTHON_LOG_CONFIG_FILE="${CATKIN_ENV_HOOK_WORKSPACE}/share/my_custom_logging_package/config/python_logging.conf"

In this particular instance I also had to make sure the file pointed to by the environment variable was available in the installed share directory by also adding the following to CMakeLists.txt. This command copies the whole config directory into the packages share directory:

install(DIRECTORY config
  DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)
$\endgroup$
0
$\begingroup$

After some tests and following suggestions in the reference links at the end of this answer, I came up with the following solution:

Let's assume you need to add the path to new gazebo templates when developing your packages, so create a directory called env_hooks in your template package folder.

Enter the directory and create a configuration file with the extension specified for each shell (.bash, .zsh, tcsh). This file can have any name, in the case I will use models_env. , change <shell_string> to the extension representing the shell, each file must be the required variables configuration according to the shell.

Now edit the CMakeLists.txt file and add the following directive to the end:

catkin_add_env_hooks (models_env SHELLS bash tcsh zsh DIRECTORY $ {CMAKE_CURRENT_SOURCE_DIR} / env-hooks)

For example, for the Bash shell, I edited my models_env.bash file and put:

#! /bin/bash
echo "*******"
echo "Preparing specific variables for the gazebo_model package"
echo "*******"

_CATKIN_ENV_HOOKS_PATH = $ (catkin locate arr_gazebo_models)
export GAZEBO_MODEL_PATH = "$ {_ CATKIN_ENV_HOOKS_PATH} / models: $ {GAZEBO_MODEL_PATH}"

References:

https://docs.ros.org/api/catkin/html/user_guide/environment.html https://docs.ros.org/api/catkin/html/dev_guide/generated_cmake_api.html#catkin_add_env_hooks

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.