Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
28 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,34 @@ | ||
from ament_index_python.packages import get_package_share_path | ||
|
||
from launch import LaunchDescription | ||
from launch.actions import DeclareLaunchArgument | ||
from launch.conditions import IfCondition, UnlessCondition | ||
from launch.substitutions import Command, LaunchConfiguration | ||
|
||
from launch_ros.actions import Node | ||
from launch_ros.parameter_descriptions import ParameterValue | ||
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription | ||
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution | ||
from launch_ros.substitutions import FindPackageShare | ||
|
||
def generate_launch_description(): | ||
urdf_tutorial_path = get_package_share_path('urdf_tutorial') | ||
default_model_path = urdf_tutorial_path / 'urdf/01-myfirst.urdf' | ||
default_rviz_config_path = urdf_tutorial_path / 'rviz/urdf.rviz' | ||
ld = LaunchDescription() | ||
|
||
urdf_tutorial_path = FindPackageShare('urdf_tutorial') | ||
default_model_path = PathJoinSubstitution(['urdf', '01-myfirst.urdf']) | ||
default_rviz_config_path = PathJoinSubstitution([urdf_tutorial_path, 'rviz', 'urdf.rviz']) | ||
|
||
# These parameters are maintained for backwards compatibility | ||
gui_arg = DeclareLaunchArgument(name='gui', default_value='true', choices=['true', 'false'], | ||
description='Flag to enable joint_state_publisher_gui') | ||
model_arg = DeclareLaunchArgument(name='model', default_value=str(default_model_path), | ||
description='Absolute path to robot urdf file') | ||
rviz_arg = DeclareLaunchArgument(name='rvizconfig', default_value=str(default_rviz_config_path), | ||
ld.add_action(gui_arg) | ||
rviz_arg = DeclareLaunchArgument(name='rvizconfig', default_value=default_rviz_config_path, | ||
description='Absolute path to rviz config file') | ||
|
||
robot_description = ParameterValue(Command(['xacro ', LaunchConfiguration('model')]), | ||
value_type=str) | ||
|
||
robot_state_publisher_node = Node( | ||
package='robot_state_publisher', | ||
executable='robot_state_publisher', | ||
parameters=[{'robot_description': robot_description}] | ||
) | ||
|
||
# Depending on gui parameter, either launch joint_state_publisher or joint_state_publisher_gui | ||
joint_state_publisher_node = Node( | ||
package='joint_state_publisher', | ||
executable='joint_state_publisher', | ||
condition=UnlessCondition(LaunchConfiguration('gui')) | ||
) | ||
|
||
joint_state_publisher_gui_node = Node( | ||
package='joint_state_publisher_gui', | ||
executable='joint_state_publisher_gui', | ||
condition=IfCondition(LaunchConfiguration('gui')) | ||
) | ||
|
||
rviz_node = Node( | ||
package='rviz2', | ||
executable='rviz2', | ||
name='rviz2', | ||
output='screen', | ||
arguments=['-d', LaunchConfiguration('rvizconfig')], | ||
) | ||
|
||
return LaunchDescription([ | ||
gui_arg, | ||
model_arg, | ||
rviz_arg, | ||
joint_state_publisher_node, | ||
joint_state_publisher_gui_node, | ||
robot_state_publisher_node, | ||
rviz_node | ||
]) | ||
ld.add_action(rviz_arg) | ||
|
||
# This parameter has changed its meaning slightly from previous versions | ||
ld.add_action(DeclareLaunchArgument(name='model', default_value=str(default_model_path), | ||
description='Path to robot urdf file relative to urdf_tutorial package')) | ||
|
||
ld.add_action(IncludeLaunchDescription( | ||
PathJoinSubstitution([FindPackageShare('urdf_launch'), 'launch', 'display.launch.py']), | ||
launch_arguments={ | ||
'urdf_package': 'urdf_tutorial', | ||
'urdf_package_path': LaunchConfiguration('model'), | ||
'rviz_config': LaunchConfiguration('rvizconfig'), | ||
'jsp_gui': LaunchConfiguration('gui')}.items() | ||
)) | ||
|
||
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