Ask Your Question

# Call substitute for package inside launch file

Hi,

I am currently editing a launch file that I moved from one package to another. I would like to store the package name inside an argument or parameter so that I can easily substitute the name by editing the substitute. I tried something like: <arg name="" "config_pkg"="" default="pkg1"/>

Now if I want to call it inside another argument it would look like this: <arg name="rvizconfig" default="$(find 'config_pkg')/launch/panda.rviz"/> This throws an error, is there an easy way to fix this or do I have to change all the pkg names everytime they will change? edit retag close merge delete ## 1 Answer Sort by » oldest newest most voted Hi To answer your question lets look at the following example, I hgave the following launch file: <?xml version="1.0"?> <launch> <arg name="config_pkg" default="my_pkg"/> <node name="rviz" pkg="rviz" type="rviz" args="-d$(find $(arg config_pkg))/launch/my_config.rviz"/> </launch>  This launch file will throw you an RLException since dollar signs '$' cannot be inside of substitution args like $(find ...) You can use this to change dynamically the node package like <?xml version="1.0"?> <launch> <arg name="config_pkg" default="rviz"/> <node name="rviz" pkg="$(arg config_pkg)" type="rviz"/>
</launch>


However bear in mind that what you can do is using enviromental variables:

In a terminal:

export my_path="/path/to/your/config/"


An in the launch file:

<?xml version="1.0"?>

<launch>
<arg name="config_pkg" default="rviz"/>
<node name="rviz" pkg="rviz" type="rviz" args="-d \$(optenv my_path default/path/to/config)/my_config.rviz"/>
</launch>


For more information about this you can check the following wiki page.

Hope that can help you with this problem.

Regards.

more

## Comments

Thanks a lot!

( 2020-08-01 12:33:47 -0500 )edit

## Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

## Stats

Asked: 2020-07-31 04:55:19 -0500

Seen: 52 times

Last updated: Aug 01 '20