Files
ROS2_WS/simulation_ws/trolley/launch/display.launch.py
2026-02-24 22:09:19 +08:00

45 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
import launch
import launch_ros
from launch_ros.actions import Node
from launch import LaunchDescription
from ament_index_python.packages import get_package_share_directory
import xacro
def generate_launch_description():
# 获取默认的urdf文件路径
pkg_trolley = get_package_share_directory('trolley')
xacro_path = os.path.join(pkg_trolley, 'urdf', 'miniBox.urdf.xacro')
# 处理xacro文件生成robot_description参数
robot_description_config = xacro.process_file(xacro_path).toxml()
# 创建Node节点发布robot_description参数
rsp = Node(
package='robot_state_publisher',
executable='robot_state_publisher',
output='screen',
parameters=[{'robot_description': robot_description_config}]
)
# 给可动关节提供 joint_states 发布器
jsp=Node(
package='joint_state_publisher',
executable='joint_state_publisher',
output='screen',
parameters=[]
)
# rviz_config=os.path.join(pkg_trolley, 'rviz', 'miniBox.rviz')
rviz = Node(
package='rviz2',
executable='rviz2',
output='screen',
arguments=[]
)
return launch.LaunchDescription([
rsp,
jsp,
rviz
])