import os
from launch_ros.actions import Node
from launch import LaunchDescription
from launch.actions import (
ExecuteProcess,
)
PKG = "cable_sim"
WORLD_NAME = "empty.world"
def generate_launch_description():
model_env = os.environ.get("GAZEBO_MODEL_PATH", "")
model_path = "/workspace/models"
model_path = model_path if model_env == "" else model_path + ":" + model_env
plugin_env = os.environ.get("GAZEBO_RESOURCE_PATH", "")
resource_path = "/workspace/worlds"
resource_path = (
resource_path if plugin_env == "" else resource_path + ":" + plugin_env
)
plugin_env = os.environ.get("GAZEBO_PLUGIN_PATH", "")
plugin_path = "/workspace/plugins"
plugin_path = plugin_path if plugin_env == "" else plugin_path + ":" + plugin_env
gazebo = ExecuteProcess(
cmd=[
"gazebo",
"--verbose",
"-s",
"libgazebo_ros_init.so",
"-s",
"libgazebo_ros_factory.so",
"empty.world",
],
output="screen",
additional_env={
"GAZEBO_MODEL_PATH": model_path,
"GAZEBO_RESOURCE_PATH": resource_path,
"GAZEBO_PLUGIN_PATH": plugin_path,
},
)
spawn_robot = Node(
package="gazebo_ros",
executable="spawn_entity.py",
output="screen",
arguments=[
"-file",
"/workspace/models/simple_box/model.sdf",
"-entity",
"robot",
# optional pose:
"-x",
"0.0",
"-y",
"0.0",
"-z",
"0.2",
"-R",
"0.0",
"-P",
"0.0",
"-Y",
"0.0",
],
)
return LaunchDescription([gazebo, spawn_robot])