-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make simulation use specific world file and have skybox
the sdf file isn't hand-crafted. I ran the launch file, then saved it from gazebo, then modified the scene tag to add a sky tag, then pasted that over my file, then removed the added robot model.
- Loading branch information
1 parent
2edb9b7
commit ac01ddd
Showing
4 changed files
with
258 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Author: Addison Sears-Collins | ||
# Date: September 19, 2021 | ||
# Description: Load a world file into Gazebo. | ||
# https://automaticaddison.com | ||
# https://automaticaddison.com/how-to-load-a-world-file-into-gazebo-ros-2/ | ||
|
||
import os | ||
from launch import LaunchDescription | ||
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription | ||
from launch.conditions import IfCondition, UnlessCondition | ||
from launch.launch_description_sources import PythonLaunchDescriptionSource | ||
from launch.substitutions import Command, LaunchConfiguration, PythonExpression | ||
from launch_ros.actions import Node | ||
from launch_ros.substitutions import FindPackageShare | ||
|
||
def generate_launch_description(): | ||
|
||
# Set the path to the Gazebo ROS package | ||
pkg_gazebo_ros = FindPackageShare(package='gazebo_ros').find('gazebo_ros') | ||
|
||
# Set the path to this package. | ||
pkg_share = FindPackageShare(package='two_wheeled_robot').find('two_wheeled_robot') | ||
|
||
# Set the path to the world file | ||
world_file_name = 'cafe.world' | ||
world_path = os.path.join(pkg_share, 'worlds', world_file_name) | ||
|
||
# Set the path to the SDF model files. | ||
gazebo_models_path = os.path.join(pkg_share, 'models') | ||
os.environ["GAZEBO_MODEL_PATH"] = gazebo_models_path | ||
|
||
########### YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE ############## | ||
# Launch configuration variables specific to simulation | ||
headless = LaunchConfiguration('headless') | ||
use_sim_time = LaunchConfiguration('use_sim_time') | ||
use_simulator = LaunchConfiguration('use_simulator') | ||
world = LaunchConfiguration('world') | ||
|
||
declare_simulator_cmd = DeclareLaunchArgument( | ||
name='headless', | ||
default_value='False', | ||
description='Whether to execute gzclient') | ||
|
||
declare_use_sim_time_cmd = DeclareLaunchArgument( | ||
name='use_sim_time', | ||
default_value='true', | ||
description='Use simulation (Gazebo) clock if true') | ||
|
||
declare_use_simulator_cmd = DeclareLaunchArgument( | ||
name='use_simulator', | ||
default_value='True', | ||
description='Whether to start the simulator') | ||
|
||
declare_world_cmd = DeclareLaunchArgument( | ||
name='world', | ||
default_value=world_path, | ||
description='Full path to the world model file to load') | ||
|
||
# Specify the actions | ||
|
||
# Start Gazebo server | ||
start_gazebo_server_cmd = IncludeLaunchDescription( | ||
PythonLaunchDescriptionSource(os.path.join(pkg_gazebo_ros, 'launch', 'gzserver.launch.py')), | ||
condition=IfCondition(use_simulator), | ||
launch_arguments={'world': world}.items()) | ||
|
||
# Start Gazebo client | ||
start_gazebo_client_cmd = IncludeLaunchDescription( | ||
PythonLaunchDescriptionSource(os.path.join(pkg_gazebo_ros, 'launch', 'gzclient.launch.py')), | ||
condition=IfCondition(PythonExpression([use_simulator, ' and not ', headless]))) | ||
|
||
# Create the launch description and populate | ||
ld = LaunchDescription() | ||
|
||
# Declare the launch options | ||
ld.add_action(declare_simulator_cmd) | ||
ld.add_action(declare_use_sim_time_cmd) | ||
ld.add_action(declare_use_simulator_cmd) | ||
ld.add_action(declare_world_cmd) | ||
|
||
# Add any actions | ||
ld.add_action(start_gazebo_server_cmd) | ||
ld.add_action(start_gazebo_client_cmd) | ||
|
||
return ld |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.