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

Can roslaunch get colon-separated environment variables?

asked 2023-06-30 04:53:49 -0600

vipetrone gravatar image

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.

edit retag flag offensive close merge delete

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?

Mike Scheutzow gravatar image Mike Scheutzow  ( 2023-06-30 09:32:15 -0600 )edit

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.

vipetrone gravatar image vipetrone  ( 2023-06-30 09:37:42 -0600 )edit

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.

gvdhoorn gravatar image gvdhoorn  ( 2023-06-30 09:40:36 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-06-30 08:58:06 -0600

Mike Scheutzow gravatar image

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.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2023-06-30 04:53:49 -0600

Seen: 103 times

Last updated: Jun 30 '23