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

Add an environment variable in ExecuteProcess

asked 2019-03-12 21:52:58 -0500

clyde gravatar image

I'm trying to add an environment variable to an ExecuteProcess action in ROS2 launch file, like so:

import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import ExecuteProcess

def generate_launch_description():
    share_dir = get_package_share_directory('tello_gazebo')
    world_path = os.path.join(share_dir, 'worlds', 'tello.world')
    model_path = os.path.join(share_dir, 'models')

    cmd = ['gazebo', '--verbose', world_path]
    env = {'GAZEBO_MODEL_PATH': model_path}

    return LaunchDescription([
        ExecuteProcess(cmd=cmd, env=env, output='screen'),
])

When I run this I get a bunch of errors -- perhaps because the environment is scrubbed of everything _except_ the environment variable I passed in, or perhaps I'm just Doing It Wrong.

$ ros2 launch tello_gazebo sim_launch.py
[INFO] [launch]: process[gazebo-1]: started with pid [22508]
[Err] [ClientConfig.cc:222] Error copying default configuration file from [/usr/share/ignition/fuel_tools//config.yaml] to [/.ignition/fuel/config.yaml]
[Err] [ClientConfig.cc:222] Error copying default configuration file from [/usr/share/ignition/fuel_tools//config.yaml] to [/.ignition/fuel/config.yaml]
Gazebo multi-robot simulator, version 9.0.0
Copyright (C) 2012 Open Source Robotics Foundation.
Released under the Apache 2 License.
http://gazebosim.org

[Err] [Console.cc:160] Missing HOME environment variable.No log file will be generated.[Err] [ClientConfig.cc:222] Error copying default configuration file from [/usr/share/ignition/fuel_tools//config.yaml] to [/.ignition/fuel/config.yaml]
Gazebo multi-robot simulator, version 9.0.0
Copyright (C) 2012 Open Source Robotics Foundation.
Released under the Apache 2 License.
http://gazebosim.org

[Err] [Console.cc:160] Missing HOME environment variable.No log file will be generated.[Msg] Waiting for master.
[Msg] Connected to gazebo master @ http://127.0.0.1:11345
[Msg] Publicized address: 192.168.86.105
[Err] [RenderEngine.cc:725] Can't open display: 
[Wrn] [RenderEngine.cc:93] Unable to create X window. Rendering will be disabled
[Wrn] [RenderEngine.cc:293] Cannot initialize render engine since render path type is NONE. Ignore this warning ifrendering has been turned off on purpose.
[Wrn] [ModelDatabase.cc:340] Getting models from[http://gazebosim.org/models/]. This may take a few seconds.
[Msg] Waiting for master.
[Msg] Connected to gazebo master @ http://127.0.0.1:11345
[Msg] Publicized address: 192.168.86.105
[Err] [GuiIface.cc:499] Unable to save INI file[""]
[Wrn] [GuiIface.cc:297] Couldn't locate specified .ini. Creating file at ""
[Err] [GuiIface.cc:308] Unable to read configuration file ""
[Err] [RenderEngine.cc:725] Can't open display: 
[Wrn] [RenderEngine.cc:93] Unable to create X window. Rendering will be disabled
[Wrn] [RenderEngine.cc:293] Cannot initialize render engine since render path type is NONE. Ignore this warning ifrendering has been turned off on purpose.
[Wrn] [GuiIface.cc:120] QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-clyde'
[Wrn] [GuiIface.cc:120] QXcbConnection: Could not connect to display 
[Err] [GuiIface.cc:124] Could not connect to any X display.
[ERROR] [launch]: process[gazebo-1] process has died [pid 22508, exit code 255, cmd 'gazebo --verbose /home/clyde/ros2/flock2_ws/install/tello_gazebo/share/tello_gazebo/worlds/tello.world'].

Is there a ... (more)

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2019-03-15 11:51:22 -0500

William gravatar image

That argument replaces the entire environment that is used for the subprocess, you'll have to extend the environment (rather than overriding it).

There was a proposal to add a new action that would change an environment variable:

https://github.com/ros2/launch/issues...

But that hasn't been implemented.

edit flag offensive delete link more
2

answered 2019-06-19 07:03:50 -0500

shiveshkhaitan gravatar image

Instead of setting env, additional_env can be used.

ExecuteProcess(cmd=cmd, additional_env=env, output='screen')

Instead of replacing the environment variables, it would append to it.

edit flag offensive delete link more

Comments

Fantastic, looks like this was added recently. Thx.

clyde gravatar image clyde  ( 2019-06-28 18:55:52 -0500 )edit

Question Tools

3 followers

Stats

Asked: 2019-03-12 21:52:58 -0500

Seen: 2,741 times

Last updated: Jun 19 '19