ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question
0

Edit environmental variable with ROS2 python launch file

asked 2021-12-01 04:14:31 -0500

fnax8902 gravatar image

Hello, I want to edit a environmental variable using my ros2 python launch file. I launch mutiple nodes so setting it once is not an option, as the variable will have to change for each node. Is it possible to set in in the Node description?

test = Node(
        package="test",
        executable="test",
        namespace=namespace,
        name="test_node",
        output="screen",
        emulate_tty=True,
        parameters=[params],
    )

return LaunchDescription([
    test
])
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-12-01 04:27:50 -0500

fnax8902 gravatar image

Okay, I found the solution:

from launch.actions import SetEnvironmentVariable

return LaunchDescription([
    SetEnvironmentVariable(name='TEST', value='whatever'),
    Node(
        package="test",
        executable="test",
        namespace=namespace,
        name="test_node",
        output="screen",
        emulate_tty=True,
    )
])
edit flag offensive delete link more

Comments

Nevermind, It doesn't set the environmental variable for the specific node. All nodes will have the value of the last launch description called

fnax8902 gravatar image fnax8902  ( 2021-12-01 05:08:43 -0500 )edit

Seems like a correct solution to me, I tried it out. Run print(os.environ.get("TEST")) in your test_node, it prints 'whatever', remove the SetEnvironmentVariable, run again and it should print None. What's your issue?

tnajjar gravatar image tnajjar  ( 2022-01-10 16:27:10 -0500 )edit

Your Answer

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

Add Answer

Question Tools

2 followers

Stats

Asked: 2021-12-01 04:14:31 -0500

Seen: 107 times

Last updated: Dec 01 '21