Robotics StackExchange | Archived questions

error when calling xacro command from python launch file

Currently Running ROS2 Humble & fortress ignition gazebo on 22.04 Ubuntu.

When I run xacro from a python launch file It returns an error. when I run the exact same command from the command line from the folder, it runs as expected, with no error. The goal of this is to use xacro to piece together sdf files for ignition gazebo. I've put a couple hours into this and am stumped. sorry if I haven't posted any crucial information, as I am new to ros in general

xacro_world_file = ExecuteProcess(
    cmd=[[' xacro ', world_name, ' -o sdf/',world_name,' -v']],
    cwd=urdf_path, # the location to do the command from
    shell=True,
)

[INFO] [launch]: Default logging verbosity is set to INFO

[INFO] [monke_gz.sdf-1]: process started with pid [60435]

[INFO] [monke_sim.world -v-2]: process started with pid [60437]

[INFO] [monke_sim.world-3]: process started with pid [60439]

[monke_sim.world -v-2] XML parsing error: no element found: line 1, column 0

[monkesim.world -v-2] when processing file: /home/sperospace/Git/RoboticArm/01Prototypes/03Gecko

/04simulation/monkegazebo/install/monkegazeboload/share/monkegazeboload/urdf/sdf/monke_gz.sdf

[monkesim.world -v-2] included from: monkesim.world

[monke_sim.world -v-2]

[monke_sim.world -v-2] Check that:

[monke_sim.world -v-2] - Your XML is well-formed

[monke_sim.world -v-2] - You have the xacro xmlns declaration: xmlns:xacro="http://www.ros.org/wiki/xacro"

[ERROR] [monkesim.world -v-2]: process has died [pid 60437, exit code 2, cmd ' xacro monkesim.world -o sdf/monke_sim.world -v'].

[INFO] [monke_gz.sdf-1]: process has finished cleanly [pid 60435]

[monkesim.world-3] Warning: Ignoring XDGSESSIONTYPE=wayland on Gnome. Use QTQPA_PLATFORM=wayland to run on Wayland anyway.

Asked by Sebastian-Schroder on 2023-06-09 00:23:08 UTC

Comments

Answers

A way around this I found was to instead use the provided xacro import with the following code.

doc = xacro.process(os.path.join(urdf_path,world_name),)

with open(os.path.join(urdf_path,'sdf',world_name),"w+") as f:
    f.write(doc);

Asked by Sebastian-Schroder on 2023-06-09 02:25:58 UTC

Comments

if you need to run a command line function from a launch file, which method is better? using python, or creating a ExecuteProcess launch description.

Asked by Sebastian-Schroder on 2023-06-09 02:31:22 UTC