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

Call substitute for package inside launch file

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

carlosg gravatar image

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-08-01 06:42:04 -0500

Weasfas gravatar image

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.

edit flag offensive delete link more

Comments

Thanks a lot!

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

Question Tools

1 follower

Stats

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

Seen: 228 times

Last updated: Aug 01 '20