Robotics StackExchange | Archived questions

Can roslaunch get colon-separated environment variables?

In a launch file, I have the following line

<arg name="venv" value="$(env CMAKE_PREFIX_PATH)/../src/environment_identification/venv/bin/python3" />

The problem is that CMAKE_PREFIX_PATH evaluates to /home/vpetrone/catkin_ws/devel:/opt/ros/noetic, where two paths are separated by a colon. I want to find from the launch file the path to my workspace, namely /home/vpetrone/catkin_ws/devel, which is the first element in CMAKE_PREFIX_PATH.

Is there a way to use the env tag to get only the first element of this colon-separated environment variable? Is there perhaps another way to get the workspace path in a launch file?

I am using ROS Noetic.

Asked by vipetrone on 2023-06-30 04:53:49 UTC

Comments

There is no single "workspace path" in ros. Perhaps if you tell us what information you are looking for, we could suggest a cleaner way to get it?

Asked by Mike Scheutzow on 2023-06-30 09:32:15 UTC

My goal is to find an automatic way to get the path under which my packages are built, which in my case is /home/vpetrone/catkin_ws/devel. To do this, I was thinking of using the tag $(env CMAKE_PREFIX_PATH), but it evaluates to multiple paths separated by colons, so I was also asking if there for was a way to separate the paths by using other tags or commands.

Asked by vipetrone on 2023-06-30 09:37:42 UTC

catkin locate can do something which the OP seems to be asking for, but I agree with @Mike Scheutzow that it would be good to know why that would be something you'd want to do in a .launch file.

Using $(dirname) (docs) might be a more portable / less brittle approach, but without knowing the motivation, it's hard to suggest anything.

@vipetrone wrote:

My goal is to find an automatic way to get the path under which my packages are built

yes, but why do you want to do that.

I have a feeling it has something to do with the Python venv reference in the path there.

Asked by gvdhoorn on 2023-06-30 09:40:36 UTC

Answers

The standard way to get a runtime path inside a launch file is to use the find syntax along with a ros package name:

$(find my_ros_package_name)/launch/myfile.launch

Note that a properly constructed ROS host may not have a catkin_ws/devel/ directory, and it's poor design for your launch file to assume that this directory exists.

Asked by Mike Scheutzow on 2023-06-30 08:58:06 UTC

Comments